From 08cfcbd2c12d1059b442ef23c32d9aeb93559bba Mon Sep 17 00:00:00 2001 From: Maxim Prokhorov Date: Sat, 9 Nov 2019 02:57:12 +0300 Subject: [PATCH] sensor/dht: wait DHT_MIN_INTERVAL after initialization --- code/espurna/sensors/DHTSensor.h | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/code/espurna/sensors/DHTSensor.h b/code/espurna/sensors/DHTSensor.h index 87720353..626907c9 100644 --- a/code/espurna/sensors/DHTSensor.h +++ b/code/espurna/sensors/DHTSensor.h @@ -20,6 +20,8 @@ #define DHT_CHIP_DHT21 21 #define DHT_CHIP_AM2301 21 +#define DHT_DUMMY_VALUE -255 + class DHTSensor : public BaseSensor { public: @@ -75,6 +77,9 @@ class DHTSensor : public BaseSensor { } _previous = _gpio; + // Set now to fail the check in _read at least once + _last_ok = millis(); + _count = 2; _ready = true; @@ -126,7 +131,11 @@ class DHTSensor : public BaseSensor { void _read() { if ((_last_ok > 0) && (millis() - _last_ok < DHT_MIN_INTERVAL)) { - _error = SENSOR_ERROR_OK; + if ((_temperature == DHT_DUMMY_VALUE) && (_humidity == DHT_DUMMY_VALUE)) { + _error = SENSOR_ERROR_WARM_UP; + } else { + _error = SENSOR_ERROR_OK; + } return; } @@ -246,8 +255,8 @@ class DHTSensor : public BaseSensor { unsigned long _last_ok = 0; unsigned char _errors = 0; - double _temperature = 0; - double _humidity = 0; + double _temperature = DHT_DUMMY_VALUE; + double _humidity = DHT_DUMMY_VALUE; };