diff --git a/sonoff/_changelog.ino b/sonoff/_changelog.ino index 7e52e3404..f780d7a21 100644 --- a/sonoff/_changelog.ino +++ b/sonoff/_changelog.ino @@ -1,4 +1,6 @@ /* 6.1.1c + * Fix possible WDT due to long MQTT publish handling (#3313) + * Fix CCS811 temperature and humidity compensation * Add support for CCS811 sensor (#3309) * Add command Timers 0/1 to globally disable or enable armed timers (#3270) * diff --git a/sonoff/sonoff.h b/sonoff/sonoff.h index 1a2e6f8af..00c1e1c59 100644 --- a/sonoff/sonoff.h +++ b/sonoff/sonoff.h @@ -68,6 +68,7 @@ typedef unsigned long power_t; // Power (Relay) type #define HLW_IREF_PULSE 3500 // was 1666us = 600Hz = 4.545A #define MQTT_RETRY_SECS 10 // Minimum seconds to retry MQTT connection +#define GLOBAL_VALUES_VALID 300 // Max number of seconds to keep last received values #define APP_POWER 0 // Default saved power state Off #define WS2812_MAX_LEDS 512 // Max number of LEDs diff --git a/sonoff/sonoff.ino b/sonoff/sonoff.ino index af68a4879..1d4442d59 100755 --- a/sonoff/sonoff.ino +++ b/sonoff/sonoff.ino @@ -188,8 +188,9 @@ uint8_t ntp_force_sync = 0; // Force NTP sync StateBitfield global_state; RulesBitfield rules_flag; -uint8_t glob_humidity = 0; -sint16_t glob_temperature = -9999; +uint32_t global_update = 0; +float global_temperature = 0; +float global_humidity = 0; char my_version[33]; // Composed version string char my_hostname[33]; // Composed Wifi hostname @@ -1544,6 +1545,8 @@ void PerformEverySecond() } } + ResetGlobalValues(); + if (Settings.tele_period) { tele_period++; if (tele_period == Settings.tele_period -1) { diff --git a/sonoff/support.ino b/sonoff/support.ino index a5d6e9e4e..13a9d4265 100644 --- a/sonoff/support.ino +++ b/sonoff/support.ino @@ -414,6 +414,22 @@ char TempUnit() return (Settings.flag.temperature_conversion) ? 'F' : 'C'; } +void SetGlobalValues(float temperature, float humidity) +{ + global_update = uptime; + global_temperature = temperature; + global_humidity = humidity; +} + +void ResetGlobalValues() +{ + if ((uptime - global_update) > GLOBAL_VALUES_VALID) { // Reset after 5 minutes + global_update = 0; + global_temperature = 0; + global_humidity = 0; + } +} + double FastPrecisePow(double a, double b) { // https://martin.ankerl.com/2012/01/25/optimized-approximative-pow-in-c-and-cpp/ diff --git a/sonoff/xdrv_01_mqtt.ino b/sonoff/xdrv_01_mqtt.ino index 4bfff0724..8afcf672b 100644 --- a/sonoff/xdrv_01_mqtt.ino +++ b/sonoff/xdrv_01_mqtt.ino @@ -231,6 +231,8 @@ void MqttPublishDirect(const char* topic, boolean retained) if (Settings.ledstate &0x04) { blinks++; } + + yield(); // #3313 } void MqttPublish(const char* topic, boolean retained) diff --git a/sonoff/xsns_07_sht1x.ino b/sonoff/xsns_07_sht1x.ino index 510ee7be3..8771dab7f 100644 --- a/sonoff/xsns_07_sht1x.ino +++ b/sonoff/xsns_07_sht1x.ino @@ -147,6 +147,8 @@ boolean ShtRead() sht_humidity = (sht_temperature - 25) * (t1 + t2 * humRaw) + rhLinear; sht_temperature = ConvertTemp(sht_temperature); + SetGlobalValues(sht_temperature, sht_humidity); + sht_valid = SENSOR_MAX_MISS; return true; } diff --git a/sonoff/xsns_08_htu21.ino b/sonoff/xsns_08_htu21.ino index 9534cbbce..61266e106 100644 --- a/sonoff/xsns_08_htu21.ino +++ b/sonoff/xsns_08_htu21.ino @@ -185,6 +185,8 @@ boolean HtuRead() htu_humidity = (-0.15) * (25 - htu_temperature) + htu_humidity; } + SetGlobalValues(htu_temperature, htu_humidity); + htu_valid = SENSOR_MAX_MISS; return true; } diff --git a/sonoff/xsns_09_bmp.ino b/sonoff/xsns_09_bmp.ino index 8f46219c8..8a50b8ae6 100755 --- a/sonoff/xsns_09_bmp.ino +++ b/sonoff/xsns_09_bmp.ino @@ -460,8 +460,7 @@ void BmpRead() } if (bmp_temperature != 0.0) { bmp_temperature = ConvertTemp(bmp_temperature); } - glob_humidity = bmp_humidity; - glob_temperature = bmp_temperature; + SetGlobalValues(bmp_temperature, bmp_humidity); } void BmpEverySecond() diff --git a/sonoff/xsns_14_sht3x.ino b/sonoff/xsns_14_sht3x.ino index c754bbab0..c3c8b2f9c 100755 --- a/sonoff/xsns_14_sht3x.ino +++ b/sonoff/xsns_14_sht3x.ino @@ -102,10 +102,7 @@ void Sht3xShow(boolean json) for (byte i = 0; i < sht3x_count; i++) { if (Sht3xRead(t, h, sht3x_sensors[i].address)) { - if (0 == i) { - glob_humidity = h; - glob_temperature = t; - } + if (0 == i) { SetGlobalValues(t, h); } dtostrfd(t, Settings.flag2.temperature_resolution, temperature); dtostrfd(h, Settings.flag2.humidity_resolution, humidity); diff --git a/sonoff/xsns_31_ccs811.ino b/sonoff/xsns_31_ccs811.ino index 8fb43d62a..482572cdb 100644 --- a/sonoff/xsns_31_ccs811.ino +++ b/sonoff/xsns_31_ccs811.ino @@ -62,10 +62,7 @@ void CCS811Update() // Perform every n second TVOC = ccs.getTVOC(); eCO2 = ccs.geteCO2(); CCS811_ready = 1; - if ((glob_humidity != 0) && (glob_temperature != -9999)) { - double gtmp = glob_temperature * 4; - ccs.setEnvironmentalData(glob_humidity, gtmp / 4); - } + if (global_update) { ccs.setEnvironmentalData((uint8_t)global_humidity, global_temperature); } ecnt = 0; } } else {