DHT22+temperature&humidity-widget problem random crashes

Hi Everyone,
I have a problem with my selfmade weatherstation.
I use the dht22 humidity&temperature sensor and the wemos d1 mini to get temperature and humidity data to my blynk-app,
But There is a problem when i Turn on the whole station, the Widgets for humidity and temperature randomly Crash.
I don’t know bis to fix it. I also got a lux-sensor which is connectet by an I2C Bus ans it’s working fine.
I Hope you Guys can help me.
Thanks in advance
Janjy

Can’t help without code to debug.

#define BLYNK_PRINT Serial    // Comment this out to disable prints and save space
#include <ESP8266WiFi.h>
#include <SPI.h>
#include <Ethernet.h>
#include <BlynkSimpleEsp8266.h>
#include <SimpleTimer.h>
#include <TimeLib.h>
#include <Wire.h>
#include <Makerblog_TSL45315.h>
#include <DHT.h>
#include <RCSwitch.h>
#include <WidgetRTC.h>

#define DHTPIN 12 //pin gpio 12 in sensor
#define DHTTYPE DHT22   // DHT 22 Change this if you have a DHT11
#define TRANSMITTER_PIN    13





DHT dht(DHTPIN, DHTTYPE);

RCSwitch mySwitch = RCSwitch();

Makerblog_TSL45315 luxsensor = Makerblog_TSL45315(TSL45315_TIME_M4);

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "1c6af0a64246421690ce62168b1b00db";  // Put your Auth Token here. (see Step 3 above)

SimpleTimer timer;


WidgetRTC rtc;

void clockDisplay()
{
  // You can call hour(), minute(), ... at any time
  // Please see Time library examples for details

  String currentTime = String(hour()) + ":" + minute() + ":" + second();
  String currentDate = String(day()) + " " + month() + " " + year();
  Serial.print("Current time: ");
  Serial.print(currentTime);
  Serial.print(" ");
  Serial.print(currentDate);
  Serial.println();

  // Send time to the App
  Blynk.virtualWrite(V7, currentTime);
  // Send date to the App
  Blynk.virtualWrite(V6, currentDate);
}

void setup()
{
  Serial.begin(9600); // See the connection status in Serial Monitor
   Blynk.begin(auth, "Nix_da_ihr_WLAN-Schnorrer", "Nicht_Geheim");
    while (Blynk.connect() == false) {
    // Wait until connected
  }
  
  luxsensor.begin();
    mySwitch.enableTransmit(TRANSMITTER_PIN);
     rtc.begin();
  // Setup a function to be called every second
  timer.setInterval(2000L, sendUptime);
  timer.setInterval(10000L, clockDisplay);
  timer.setInterval(6000L, sendUptimelux);
}

BLYNK_WRITE(V0) {
  if(param.asInt() == 0) {
    mySwitch.switchOff("11011", "00011");
  } else {
    mySwitch.switchOn("11011", "00011");
  }
}

BLYNK_WRITE(V1) {
    mySwitch.switchOn("11011", "00011");
    delay(2000);
    mySwitch.switchOff("11011", "00011");
}
    
void sendUptime()
{
  // You can send any value at any time.
  // Please don't send more that 10 values per second.
   //Read the Temp and Humidity from DHT
  float h = dht.readHumidity();
  float t = dht.readTemperature();
  
  
  Blynk.virtualWrite(10, t); // virtual pin 
  Blynk.virtualWrite(12, t); // virtual pin
  Blynk.virtualWrite(11, h); // virtual pin 
  Blynk.virtualWrite(13, h); // virtual pin
 
  
}

void sendUptimelux()
{
 uint32_t lux = luxsensor.readLux(); 

  Blynk.virtualWrite(14, lux); // virtual pin
  Blynk.virtualWrite(15, lux); // virtual pin
}

void loop()
{
  if (hour() == 13 && minute() == 43 && second() == 00)
{
    mySwitch.switchOn("11011", "00011");
    delay(2000);
    mySwitch.switchOff("11011", "00011"); 
    }

  Blynk.run();
  timer.run();
}

Is you widget set to PUSH ?

No i use the gauge Widget and the labled value Display where i can’t Set push

You can set the reading rate on both on PUSH

Ah ok i see should i set it to push ?

yes try that

I’ve tried it but same result…
what else can i so ?

What does it do when it crashes, does your device disconnect ?

No only the temperature and humidity Widget Shows me “nan°C” randomly

have you tried to reboot your device ?

Yeah multiple times, but still the same

That’s correct. DHT sensor may fail. In that case it will return NAN. You need to guard your code with :

float t = dht.readTemperature();
  if (isnan(t)) {
    return;
  }
1 Like

You should also get rid of all delay() calls, and move the lines above Blynk.run() and timer.run() into a function. Then using timers to run a function every xxxx milliseconds achieves the purpose of the delays, but using millis().