Fix DS18B20 not working properly (#1121)

* Fix Switch Celcius and Fahrenheit

* Fix overflow issue
This commit is contained in:
Benoit Courty authored and GitHub committed 2022-01-02 18:15:43 -06:00
1 parent 5c3eccbb18
commit 892cbc35f5
2 files changed
+6 -6

No files matched your search

+4 -4
View File
@@ -128,11 +128,11 @@ void MeasureDS1820Temp() {
// trigger temperature conversion some time before actually
// calling getTempC() to make reading temperatures non-blocking
if (!triggeredConversion && (millis() > (timeDS1820 + (DS1820_INTERVAL_SEC * 1000) - DS1820_CONV_TIME))) {
if (!triggeredConversion && ((millis() - timeDS1820) > (DS1820_INTERVAL_SEC * 1000UL - DS1820_CONV_TIME))) {
Log.trace(F("DS1820: Trigger temperature conversion..." CR));
ds1820.requestTemperatures();
triggeredConversion = true;
} else if (triggeredConversion && (millis() > (timeDS1820 + (DS1820_INTERVAL_SEC * 1000)))) {
} else if (triggeredConversion && ((millis() - timeDS1820) > DS1820_INTERVAL_SEC * 1000UL)) {
timeDS1820 = millis();
triggeredConversion = false;
@@ -148,8 +148,8 @@ void MeasureDS1820Temp() {
if (current_temp[i] == -127) {
Log.error(F("DS1820: Device %s currently disconnected!" CR), (char*)ds1820_addr[i].c_str());
} else if (DS1820_ALWAYS || current_temp[i] != persisted_temp[i]) {
DS1820data["tempc"] = (float)DallasTemperature::toFahrenheit(current_temp[i]);
DS1820data["tempf"] = (float)current_temp[i];
DS1820data["tempf"] = (float)DallasTemperature::toFahrenheit(current_temp[i]);
DS1820data["tempc"] = (float)current_temp[i];
if (DS1820_DETAILS) {
DS1820data["type"] = ds1820_type[i];
+2 -2
View File
@@ -34,10 +34,10 @@ extern void pubOneWire_HADiscovery();
#define OW_TOPIC "/OneWiretoMQTT/ds1820"
#define OW_MAX_SENSORS 8 // query max. sensors on 1-wire bus
#define DS1820_ALWAYS true // if false only published current temperature if has changed from previous reading
#define DS1820_INTERVAL_SEC 60 // time between DS1820 readings (seconds)
#define DS1820_INTERVAL_SEC 60UL // time between DS1820 readings (seconds)
#define DS1820_RESOLUTION 10 // conversion times: 9 bit (93.75 ms), 10 bit (187.5 ms), 11 bit (375 ms), 12 bit (750 ms)
#define DS1820_DETAILS true // publish extented info for each sensor (resolution, address, type)
#define DS1820_CONV_TIME 2000 // trigger conversion before requesting temperature readings (ms)
#define DS1820_CONV_TIME 2000UL // trigger conversion before requesting temperature readings (ms)
/*-------------------PIN DEFINITIONS----------------------*/
#ifndef DS1820_OWBUS_GPIO