Ahtx0 detections (#695)

* Detect when sensor isn't available or read fails

* Matching code guidelines

Co-authored-by: Jonathan Michael Wells <jonathan-wells@oist.jp>
This commit is contained in:
JonandJonathan Michael Wells authored and GitHub committed 2020-07-09 12:35:10 -05:00
1 parent 6aa2a3c1c3
commit 486fd63813
1 file changed
+10 -6
+10 -6
View File
@@ -56,9 +56,13 @@ void setupZsensorAHTx0() {
# if defined(ESP32) # if defined(ESP32)
Wire.begin(AHT_I2C_SDA, AHT_I2C_SCL); Wire.begin(AHT_I2C_SDA, AHT_I2C_SCL);
ahtSensor.begin(&Wire); if (!ahtSensor.begin(&Wire)) {
Log.error(F("Failed to initialize AHTx0 sensor!" CR));
}
# else # else
ahtSensor.begin(); if (!ahtSensor.begin()) {
Log.error(F("Failed to initialize AHTx0 sensor!" CR));
}
# endif # endif
} }
@@ -71,9 +75,8 @@ void MeasureAHTTempHum() {
static float persisted_aht_hum; static float persisted_aht_hum;
sensors_event_t ahtTempC, ahtHum; sensors_event_t ahtTempC, ahtHum;
ahtSensor.getEvent(&ahtHum, &ahtTempC); // get sensor data if (!ahtSensor.getEvent(&ahtHum, &ahtTempC)) // get sensor data
{
if (ahtTempC.temperature >= 998 || ahtHum.relative_humidity >= 998) {
Log.error(F("Failed to read from sensor AHTx0!" CR)); Log.error(F("Failed to read from sensor AHTx0!" CR));
return; return;
} }
@@ -101,9 +104,10 @@ void MeasureAHTTempHum() {
Log.notice(F("Same Humidity. Don't send it" CR)); Log.notice(F("Same Humidity. Don't send it" CR));
} }
if (AHTx0data.size() > 0) if (AHTx0data.size() > 0) {
pub(AHTTOPIC, AHTx0data); pub(AHTTOPIC, AHTx0data);
} }
}
persisted_aht_tempc = ahtTempC.temperature; persisted_aht_tempc = ahtTempC.temperature;
persisted_aht_hum = ahtHum.relative_humidity; persisted_aht_hum = ahtHum.relative_humidity;
} }