Skip to content

Commit

Permalink
checkval
Browse files Browse the repository at this point in the history
  • Loading branch information
markirb committed Jun 2, 2024
1 parent dccbd65 commit e8aaab1
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/DHT/shelly_dht_sensor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,18 @@ 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 result == std::nan or result_humidity == std::nan) {
//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 e8aaab1

Please sign in to comment.