Esp8266 DHT11 get disconnected from sever

i am new… so please bear with me if the code is not good

My project is to monitor two area with DHT11 an to see those value over the web with the Blynk app on a iOs phone

It with a ESP8266 and DHt11

the code is running but after few hour it stop… the esp8266 get disconnected from my home internet

Any help would be appreciated

// Example testing DHT11 humidity/temperature sensors
// Demonstrates multiple Temperature sensors

#include <SPI.h>
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <DHT.h>

#define DHT1TYPE DHT11   // Using Temperature Type = DHT11//
#define DHT4PIN 4        // what pin we're connected to ?//
#define DHT2PIN 2       // what pin we're connected to ?//

// Auth Token in the Blynk App.
char auth[] = "TTTT"; //Enter the Auth code which was send by Blink

// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "XXX";  //Enter your WIFI Name
char pass[] = "ZZZZ";  //Enter your WIFI Password

//Connection process
void setup() 
      //Serial.println("Connection in Process Please Wait");
      Blynk.begin(auth, ssid, pass);

// Reading temperature or humidity
void loop() 
     float h1 = dht2.readHumidity();
     float t1 = dht2.readTemperature();
     float h2 = dht4.readHumidity();
     float t2 = dht4.readTemperature();
    // check if returns are valid, if they are NaN (not a number) then something went wrong!
  if (isnan(t1) || isnan(h1))
    //Serial.println("Failed to read from DHT #1");
     //Serial.print("Temperature 1 = "); 
     //Serial.print(" C");   
     //Serial.print("   Humidity 1 = "); 
     //Serial.println(" %\t");
  if (isnan(t2) || isnan(h2)) 
     //Serial.println("Failed to read from DHT #2");
     //Serial.print("Temperature 2 = "); 
     //Serial.print(" C");
     //Serial.print("   Humidity 2 = "); 
     //Serial.println(" %\t");
// Sending Blynk values.
     Blynk.virtualWrite(V5, h1);  //V5 is for Humidity
     Blynk.virtualWrite(V6, t1);  //V6 is for Temperature
     Blynk.virtualWrite(V7, h2);  //V7 is for Humidity
     Blynk.virtualWrite(V8, t2);  //V8 is for Temperature

@PW43575 please edit your post, using the pencil icon at the bottom, and add triple backticks at the beginning and end of your code so that it displays correctly.
Triple backticks look like this:


done… sorry for that

The problem is being caused by your void loop.

You should read this:

Also, you are reading the DHT11 too frequently. These sensors are very slow, and I wouldn’t recommend reading them any more than once every 5 seconds.

So, when you restructure your code and remove the delay(2000) and replace it with a timer, set the timer to around 5000ms.


Tks so much… i will do my homework :wink: