mirror of
https://github.com/esphome/esphome.git
synced 2024-11-02 08:40:55 +01:00
Better DHT error reporting
This commit is contained in:
parent
83095e8989
commit
341c99b4fa
@ -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 (checksum_a != data[4] && checksum_b != data[4]) {
|
||||||
if (report_errors) {
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this->model_ == DHT_MODEL_DHT11) {
|
if (this->model_ == DHT_MODEL_DHT11) {
|
||||||
*humidity = data[0];
|
*humidity = data[0];
|
||||||
|
if (*humidity > 100)
|
||||||
|
*humidity = NAN;
|
||||||
*temperature = data[2];
|
*temperature = data[2];
|
||||||
} 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);
|
||||||
@ -170,18 +172,20 @@ bool HOT DHT::read_sensor_(float *temperature, float *humidity, bool report_erro
|
|||||||
|
|
||||||
if (raw_temperature == 1 && raw_humidity == 10) {
|
if (raw_temperature == 1 && raw_humidity == 10) {
|
||||||
if (report_errors) {
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
*humidity = raw_humidity * 0.1f;
|
*humidity = raw_humidity * 0.1f;
|
||||||
|
if (*humidity > 100)
|
||||||
|
*humidity = NAN;
|
||||||
*temperature = int16_t(raw_temperature) * 0.1f;
|
*temperature = int16_t(raw_temperature) * 0.1f;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (*temperature == 0.0f && (*humidity == 1.0f || *humidity == 2.0f)) {
|
if (*temperature == 0.0f && (*humidity == 1.0f || *humidity == 2.0f)) {
|
||||||
if (report_errors) {
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user