Advertisement
Guest User

Untitled

a guest
Nov 20th, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.17 KB | None | 0 0
  1. void loop() {
  2. // Listenning for new clients
  3. WiFiClient client = server.available();
  4.  
  5. if (client) {
  6.  
  7. Serial.println("New client");
  8. // bolean to locate when the http request ends
  9. boolean blank_line = true;
  10. while (client.connected()) {
  11.  
  12.  
  13. if (client.available()) {
  14. char c = client.read();
  15.  
  16. if (c == 'n' && blank_line) {
  17. getWeather();
  18. client.println("HTTP/1.1 200 OK");
  19. client.println("Content-Type: text/html");
  20. client.println("Connection: close");
  21. client.println();
  22. // your actual web page that displays temperature
  23. client.println("<!DOCTYPE HTML>");
  24. client.println("<html>");
  25. //client.println("<head><META HTTP-EQUIV="refresh" CONTENT="15"></head>");
  26. client.println("<body><h1>ESP8266 Weather Web Server</h1>");
  27. client.println("<table border="2" width="456" cellpadding="10"><tbody><tr><td>");
  28. client.println();
  29. client.println(client.remoteIP());
  30. client.println();
  31. client.println("<h3>Temperature = ");
  32. client.println(temperatureFString);
  33. client.println("&deg;F</h3><h3>Humidity = ");
  34. client.println(humidityString);
  35. client.println("%</h3><h3>Approx. Dew Point = ");
  36. client.println(dpString);
  37. client.println("&deg;F</h3><h3>Pressure = ");
  38. client.println(pressureString);
  39. client.println("hPa (");
  40. client.println(pressureInchString);
  41. client.println("Inch)</h3></td></tr></tbody></table></body></html>");
  42.  
  43.  
  44. int x;
  45. for(x = 1;x < 2; x++)
  46. {
  47. Serial.println(client.remoteIP());
  48. }
  49. break;
  50. }
  51. if (c == 'n') {
  52. // when starts reading a new line
  53. blank_line = true;
  54. }
  55. else if (c != 'r') {
  56. // when finds a character on the current line
  57. blank_line = false;
  58. }
  59. }
  60. }
  61. // closing the client connection
  62. delay(1);
  63. client.stop();
  64. Serial.println("Client disconnected.");
  65. }
  66.  
  67. client.remoteIP().toString().c_str()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement