mirror of
https://github.com/esphome/esphome.git
synced 2024-12-20 16:18:49 +01:00
DHT22 ignore invalid values (#614)
Fixes https://github.com/esphome/issues/issues/397
This commit is contained in:
parent
0d36e66125
commit
73eea154d5
@ -164,11 +164,18 @@ bool HOT DHT::read_sensor_(float *temperature, float *humidity, bool report_erro
|
|||||||
} else {
|
} else {
|
||||||
uint16_t raw_humidity = (uint16_t(data[0] & 0xFF) << 8) | (data[1] & 0xFF);
|
uint16_t raw_humidity = (uint16_t(data[0] & 0xFF) << 8) | (data[1] & 0xFF);
|
||||||
uint16_t raw_temperature = (uint16_t(data[2] & 0xFF) << 8) | (data[3] & 0xFF);
|
uint16_t raw_temperature = (uint16_t(data[2] & 0xFF) << 8) | (data[3] & 0xFF);
|
||||||
*humidity = raw_humidity * 0.1f;
|
|
||||||
|
|
||||||
if ((raw_temperature & 0x8000) != 0)
|
if ((raw_temperature & 0x8000) != 0)
|
||||||
raw_temperature = ~(raw_temperature & 0x7FFF);
|
raw_temperature = ~(raw_temperature & 0x7FFF);
|
||||||
|
|
||||||
|
if (raw_temperature == 1 && raw_humidity == 10) {
|
||||||
|
if (report_errors) {
|
||||||
|
ESP_LOGE(TAG, "Invalid temperature+humidity! Sensor reported 1°C and 1%% Hum");
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
*humidity = raw_humidity * 0.1f;
|
||||||
*temperature = int16_t(raw_temperature) * 0.1f;
|
*temperature = int16_t(raw_temperature) * 0.1f;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user