From 8fcc840a20b7f26e60a36becc53ddc03468d5657 Mon Sep 17 00:00:00 2001 From: Ronald Schaten Date: Mon, 21 Mar 2016 09:52:50 +0100 Subject: [PATCH] check for DHT value validity --- things.ino | 7 +++++++ 1 file changed, 7 insertions(+) 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