diff --git a/things.ino b/things.ino index d7ce9e1..2bdac9f 100644 --- a/things.ino +++ b/things.ino @@ -55,6 +55,7 @@ Ticker ticker; // LED status WiFiClient wifiClient; PubSubClient mqtt_client(wifiClient); +bool dhtvalid = false; // indicate if measurement is valid float humidity, temperature; // raw values from the sensor float heatindex; // computed value from the sensor char str_humidity[10], str_temperature[10]; // rounded values as strings @@ -108,8 +109,14 @@ void read_sensor() { // check if any reads failed and exit early (to try again) if (isnan(humidity) || isnan(temperature)) { + dhtvalid = false; Serial.println("Failed to read from DHT sensor!"); + strcpy(str_humidity, "invalid"); + strcpy(str_temperature, "invalid"); + strcpy(str_heatindex, "invalid"); return; + } else { + dhtvalid = true; } // convert the floats to strings and round to 2 decimal places