From 341c99b4faa99b2ed5968d86db09366a230ac891 Mon Sep 17 00:00:00 2001 From: Otto Winter Date: Mon, 1 Jul 2019 11:10:03 +0200 Subject: [PATCH] Better DHT error reporting --- esphome/components/dht/dht.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/esphome/components/dht/dht.cpp b/esphome/components/dht/dht.cpp index 797137c08c..936f87e3fa 100644 --- a/esphome/components/dht/dht.cpp +++ b/esphome/components/dht/dht.cpp @@ -153,13 +153,15 @@ bool HOT DHT::read_sensor_(float *temperature, float *humidity, bool report_erro if (checksum_a != data[4] && checksum_b != data[4]) { if (report_errors) { - ESP_LOGE(TAG, "Checksum invalid: %u!=%u", checksum_a, data[4]); + ESP_LOGW(TAG, "Checksum invalid: %u!=%u", checksum_a, data[4]); } return false; } if (this->model_ == DHT_MODEL_DHT11) { *humidity = data[0]; + if (*humidity > 100) + *humidity = NAN; *temperature = data[2]; } else { uint16_t raw_humidity = (uint16_t(data[0] & 0xFF) << 8) | (data[1] & 0xFF); @@ -170,18 +172,20 @@ bool HOT DHT::read_sensor_(float *temperature, float *humidity, bool report_erro if (raw_temperature == 1 && raw_humidity == 10) { if (report_errors) { - ESP_LOGE(TAG, "Invalid temperature+humidity! Sensor reported 1°C and 1%% Hum"); + ESP_LOGW(TAG, "Invalid temperature+humidity! Sensor reported 1°C and 1%% Hum"); } return false; } *humidity = raw_humidity * 0.1f; + if (*humidity > 100) + *humidity = NAN; *temperature = int16_t(raw_temperature) * 0.1f; } if (*temperature == 0.0f && (*humidity == 1.0f || *humidity == 2.0f)) { if (report_errors) { - ESP_LOGE(TAG, "DHT reports invalid data. Is the update interval too high or the sensor damaged?"); + ESP_LOGW(TAG, "DHT reports invalid data. Is the update interval too high or the sensor damaged?"); } return false; }