check for DHT value validity
This commit is contained in:
parent
602077a726
commit
8fcc840a20
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user