Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void loop() {
- // Listenning for new clients
- WiFiClient client = server.available();
- if (client) {
- Serial.println("New client");
- // bolean to locate when the http request ends
- boolean blank_line = true;
- while (client.connected()) {
- if (client.available()) {
- char c = client.read();
- if (c == 'n' && blank_line) {
- getWeather();
- client.println("HTTP/1.1 200 OK");
- client.println("Content-Type: text/html");
- client.println("Connection: close");
- client.println();
- // your actual web page that displays temperature
- client.println("<!DOCTYPE HTML>");
- client.println("<html>");
- //client.println("<head><META HTTP-EQUIV="refresh" CONTENT="15"></head>");
- client.println("<body><h1>ESP8266 Weather Web Server</h1>");
- client.println("<table border="2" width="456" cellpadding="10"><tbody><tr><td>");
- client.println();
- client.println(client.remoteIP());
- client.println();
- client.println("<h3>Temperature = ");
- client.println(temperatureFString);
- client.println("°F</h3><h3>Humidity = ");
- client.println(humidityString);
- client.println("%</h3><h3>Approx. Dew Point = ");
- client.println(dpString);
- client.println("°F</h3><h3>Pressure = ");
- client.println(pressureString);
- client.println("hPa (");
- client.println(pressureInchString);
- client.println("Inch)</h3></td></tr></tbody></table></body></html>");
- int x;
- for(x = 1;x < 2; x++)
- {
- Serial.println(client.remoteIP());
- }
- break;
- }
- if (c == 'n') {
- // when starts reading a new line
- blank_line = true;
- }
- else if (c != 'r') {
- // when finds a character on the current line
- blank_line = false;
- }
- }
- }
- // closing the client connection
- delay(1);
- client.stop();
- Serial.println("Client disconnected.");
- }
- client.remoteIP().toString().c_str()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement