Arduino MQTT lots of bugs

It’s because you are not checking the DHT results for errors. Use something like this:

do {
  WhileLoops++;
  //We can't go too long without calling Cayenne.loop() so exit this loop after 2 seconds and set an error flag
  if (WhileLoops >= 4){
    Serial.println("Sensor Read Error");
    ReadError = true;
    break;
  }
  //Read temperature as Fahrenheit
  t = dht.readTemperature(true);
  //Read humidity (percent)
  h = dht.readHumidity();
  //Read temperature as Fahrenheit
  t = dht.readTemperature(true);
  //Calculate Heat Index as Fahrenheit
  hif = dht.computeHeatIndex(t, h);

  delay(500);
} while  (isnan(t) || isnan(h));

Code from Battery Powered ESP8266 Temperature/Humidity Monitor with DHT11

1 Like