From bdefbf23bc54f07181bf2e6d962c6d73afeb39b6 Mon Sep 17 00:00:00 2001 From: Nicu Hodos Date: Tue, 2 Jan 2024 22:02:46 +0100 Subject: [PATCH] publish any change in temperature, but display only if difference is more than 0.2 --- src/esp_clock.cpp | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/esp_clock.cpp b/src/esp_clock.cpp index fe7fe4f..f95dd8e 100644 --- a/src/esp_clock.cpp +++ b/src/esp_clock.cpp @@ -29,12 +29,15 @@ Task tLed(TASK_IMMEDIATE, TASK_ONCE, []() { }, &ts); Task tReadBmp(TASK_MINUTE, TASK_FOREVER, []() { static float lastTemp = 0; + float temp = Bmp::data.temp; Bmp::data.readAll(); - if (abs(lastTemp - Bmp::data.temp) <= 0.2) return; - lastTemp = Bmp::data.temp; - Display::displayTemp(Bmp::data.temp); + if (temp == Bmp::data.temp) return; Mqtt::publishBmp280(); -}, &ts, true); + if (abs(lastTemp - Bmp::data.temp) > 0.2) { + lastTemp = Bmp::data.temp; + Display::displayTemp(Bmp::data.temp); + } +}, &ts); void setup() { @@ -55,6 +58,8 @@ void setup() { pinMode(BUTTON, INPUT_PULLUP); attachInterrupt(digitalPinToInterrupt(BUTTON), onButtonPressed, FALLING); attachInterrupt(digitalPinToInterrupt(LED_BUILTIN), onLed, CHANGE); + + tReadBmp.enable(); } void loop() {