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:
1 parent
6aa2a3c1c3
commit
486fd63813
1 file changed
+10
-6
+10
-6
@@ -56,9 +56,13 @@ void setupZsensorAHTx0() {
|
||||
|
||||
# if defined(ESP32)
|
||||
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
|
||||
ahtSensor.begin();
|
||||
if (!ahtSensor.begin()) {
|
||||
Log.error(F("Failed to initialize AHTx0 sensor!" CR));
|
||||
}
|
||||
# endif
|
||||
}
|
||||
|
||||
@@ -71,9 +75,8 @@ void MeasureAHTTempHum() {
|
||||
static float persisted_aht_hum;
|
||||
|
||||
sensors_event_t ahtTempC, ahtHum;
|
||||
ahtSensor.getEvent(&ahtHum, &ahtTempC); // get sensor data
|
||||
|
||||
if (ahtTempC.temperature >= 998 || ahtHum.relative_humidity >= 998) {
|
||||
if (!ahtSensor.getEvent(&ahtHum, &ahtTempC)) // get sensor data
|
||||
{
|
||||
Log.error(F("Failed to read from sensor AHTx0!" CR));
|
||||
return;
|
||||
}
|
||||
@@ -101,8 +104,9 @@ void MeasureAHTTempHum() {
|
||||
Log.notice(F("Same Humidity. Don't send it" CR));
|
||||
}
|
||||
|
||||
if (AHTx0data.size() > 0)
|
||||
if (AHTx0data.size() > 0) {
|
||||
pub(AHTTOPIC, AHTx0data);
|
||||
}
|
||||
}
|
||||
persisted_aht_tempc = ahtTempC.temperature;
|
||||
persisted_aht_hum = ahtHum.relative_humidity;
|
||||
|
||||
Reference in new issue
Block a user