Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void loop()
- {
- // listen for incoming clients
- WiFiClient client = server.available();
- if (client) {
- //Serial.println("Client connected");
- // an http request ends with a blank line
- boolean currentLineIsBlank = true;
- while (client.connected()) {
- while(client.available()) {
- char c = client.read();
- // if you've gotten to the end of the line (received a newline
- // character) and the line is blank, the http request has ended,
- // so you can send a reply
- if (c == 'n' && currentLineIsBlank) {
- // Here is where the POST data is.
- Serial.println("Post data: ");
- int ctr = 0;
- while(client.available())
- {
- Serial.write(client.read());
- buffer[ctr] = client.read();
- ctr++;
- }
- Serial.println("Buffer: ");
- Serial.write(buffer);
- Serial.println();
- //Serial.println("Sending response");
- // send a standard http response header
- client.println("HTTP/1.0 200 OK");
- client.println("Content-Type: text/html");
- client.println("Connection: keep-alive");
- client.println();
- //form added to send data from browser and view received data in serial monitor
- client.println();
- client.println("<!DOCTYPE html>");
- client.println("<html lang="en">");
- client.println("<body>");
- client.println(" <FORM action="" method="POST">");
- client.println(" <P>");
- client.println(" <LABEL for="username">Username:</LABEL>");
- client.println(" <INPUT type="text" name="uname"><BR><BR>");
- client.println(" <LABEL for="password">Password:</LABEL>");
- client.println(" <INPUT type="text" name="pwd"><BR><BR>");
- client.println(" <INPUT type="submit" value="Submit">");
- client.println(" </P>");
- client.println(" </FORM>");
- client.println("</body>");
- client.println("</html>");
- client.println();
- client.stop();
- }
- else if (c == 'n') {
- // you're starting a new line
- currentLineIsBlank = true;
- }
- else if (c != 'r') {
- // you've gotten a character on the current line
- currentLineIsBlank = false;
- }
- }
- }
- //Serial.println("Disconnected");
- Serial.println();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement