diff --git a/thermo_sensor_v2.ino b/thermo_sensor_v2.ino index 809a46b..70879eb 100644 --- a/thermo_sensor_v2.ino +++ b/thermo_sensor_v2.ino @@ -21,6 +21,7 @@ IPAddress subnet(MY_NET); ModbusIP mb; DHT dht(DHTPIN, DHTTYPE); char id[64]; +bool dht_read_error = false; #define REGISTER_CURRENT_TEMP 0 #define REGISTER_CURRENT_HUM 1 @@ -35,6 +36,7 @@ unsigned long current = 0; Modbus::ResultCode OnModbusRequest(Modbus::FunctionCode fc, const Modbus::RequestData data) { last_poll = current; + if (dht_read_error) return Modbus::EX_ILLEGAL_VALUE; return Modbus::EX_SUCCESS; } @@ -81,6 +83,8 @@ void UpdateDHTData() float t = dht.readTemperature(); cur_hum = (int)(h * 100); cur_t = (int)(t * 100); + if (cur_t == 2147483647 && cur_hum == 2147483647) dht_read_error = true; + else dht_read_error = false; } unsigned long last_read = 0;