Skip to content

Commit

Permalink
Check DHT Sensor values for errors (#1392)
Browse files Browse the repository at this point in the history
* checkval

* bump to beta3

* fix and parenthesis
  • Loading branch information
markirb authored Jun 10, 2024
1 parent 8ccdc21 commit db34ed9
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
2 changes: 1 addition & 1 deletion mos.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
author: Shelly-HomeKit contributors
description: A HomeKit firmware for Shelly switches
version: 2.12.0-beta2
version: 2.12.0-beta3

libs_version: latest
modules_version: latest
Expand Down
17 changes: 14 additions & 3 deletions src/DHT/shelly_dht_sensor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,20 @@ StatusOr<float> DHTSensor::GetHumidity() {
}

void DHTSensor::UpdateTemperatureCB() {
// std::nan
result_ = mgos_dht_get_temp(dht);
result_humidity_ = mgos_dht_get_humidity(dht);
float result = mgos_dht_get_temp(dht);
float result_humidity = mgos_dht_get_humidity(dht);

// check values for validity
if (((result == 0) and (result_humidity == 0)) or isnan(result) or
isnan(result_humidity)) {
// error during readout do nothing for now
LOG(LL_INFO, ("DHT: invalid value received"));
return;
}

result_ = result;
result_humidity_ = result_humidity;

if (notifier_) {
notifier_();
}
Expand Down

0 comments on commit db34ed9

Please sign in to comment.