bclose

dht11 web client


Create A Simple ESP8266 NodeMCU Web Server In Arduino IDE

 

#include <ESP8266WiFi.h>
 const char* ssid = "REDLINEB"; // SSID
 const char* password = "contrase"; // Password
 const char* host = "www.google.es"; // IP serveur - Server IP
 const int port = 80; // Port serveur - Server Port
 const int watchdog = 5000; // Fréquence du watchdog - Watchdog frequency
 unsigned long previousMillis = millis();
 // byte server[] = { 64, 233, 187, 99 };
 byte server[]= { 192,168,1,132};
 const char* xxhost = "www.example.com";
 
void setup() 
{    Serial.begin(115200);
     Serial.print("Connecting to ");
     Serial.println(ssid);

     WiFi.begin(ssid, password);
     while (WiFi.status() != WL_CONNECTED) 
        {   delay(500);
            Serial.print(".");
        }

     Serial.println("");
     Serial.println("WiFi connected");
     Serial.println("IP address: ");
     Serial.println(WiFi.localIP());
 }

void loop() 
{    unsigned long currentMillis = millis();
     if ( currentMillis - previousMillis > watchdog ) 
       {  previousMillis = currentMillis;
          WiFiClient client;
          Serial.println("Conectando...");
          if (!client.connect(server, port)) 
            {  Serial.println("connection failed");
               return;
            }
     Serial.println("Conectado");
     // This will send the request to the server
     client.print(String("GET ") +"/" + " HTTP/1.1\r\n" +
     "Host: " + host + "\r\n" + "Connection: close\r\n\r\n");
     unsigned long timeout = millis();
     while (client.available() == 0) 
       {   if (millis() - timeout > 5000) 
             { Serial.println(">>> Client Timeout !");
               client.stop();
               return; 
             }
       }

  // Read all the lines of the reply from server and print them to Serial
  while(client.available())
    {  String line = client.readStringUntil('\r');
       Serial.print(line);
    }
  }
}