Advertisement
Guest User

Untitled

a guest
Jun 12th, 2016
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.36 KB | None | 0 0
  1. void loop()
  2. {
  3. // listen for incoming clients
  4. WiFiClient client = server.available();
  5.  
  6. if (client) {
  7. //Serial.println("Client connected");
  8. // an http request ends with a blank line
  9. boolean currentLineIsBlank = true;
  10.  
  11. while (client.connected()) {
  12. while(client.available()) {
  13. char c = client.read();
  14. // if you've gotten to the end of the line (received a newline
  15. // character) and the line is blank, the http request has ended,
  16. // so you can send a reply
  17. if (c == 'n' && currentLineIsBlank) {
  18.  
  19. // Here is where the POST data is.
  20. Serial.println("Post data: ");
  21. int ctr = 0;
  22. while(client.available())
  23. {
  24. Serial.write(client.read());
  25. buffer[ctr] = client.read();
  26. ctr++;
  27. }
  28. Serial.println("Buffer: ");
  29. Serial.write(buffer);
  30. Serial.println();
  31.  
  32. //Serial.println("Sending response");
  33. // send a standard http response header
  34. client.println("HTTP/1.0 200 OK");
  35. client.println("Content-Type: text/html");
  36. client.println("Connection: keep-alive");
  37. client.println();
  38.  
  39. //form added to send data from browser and view received data in serial monitor
  40. client.println();
  41. client.println("<!DOCTYPE html>");
  42. client.println("<html lang="en">");
  43. client.println("<body>");
  44. client.println(" <FORM action="" method="POST">");
  45. client.println(" <P>");
  46. client.println(" <LABEL for="username">Username:</LABEL>");
  47. client.println(" <INPUT type="text" name="uname"><BR><BR>");
  48. client.println(" <LABEL for="password">Password:</LABEL>");
  49. client.println(" <INPUT type="text" name="pwd"><BR><BR>");
  50. client.println(" <INPUT type="submit" value="Submit">");
  51. client.println(" </P>");
  52. client.println(" </FORM>");
  53. client.println("</body>");
  54. client.println("</html>");
  55.  
  56. client.println();
  57.  
  58. client.stop();
  59. }
  60. else if (c == 'n') {
  61. // you're starting a new line
  62. currentLineIsBlank = true;
  63. }
  64. else if (c != 'r') {
  65. // you've gotten a character on the current line
  66. currentLineIsBlank = false;
  67. }
  68. }
  69. }
  70. //Serial.println("Disconnected");
  71. Serial.println();
  72. }
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement