From fa11355767c2779d1ac5fe146054ab7f3523b480 Mon Sep 17 00:00:00 2001 From: Nicu Hodos Date: Sun, 31 Dec 2023 14:57:25 +0100 Subject: [PATCH] read temp every minute and publish only if difference is more than 0.2 --- include/mqtt.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/include/mqtt.h b/include/mqtt.h index 250cae9..614475e 100644 --- a/include/mqtt.h +++ b/include/mqtt.h @@ -19,7 +19,7 @@ namespace Mqtt { void disconnect(); Task tReConnect(5 * TASK_MINUTE, TASK_FOREVER, connect, &ts); Task tPublishInit(TASK_IMMEDIATE, TASK_ONCE, publishInit, &ts); - Task tPublishBmp(5 * TASK_MINUTE, TASK_FOREVER, publishBmp280, &ts); + Task tPublishBmp(TASK_MINUTE, TASK_FOREVER, publishBmp280, &ts); Task tPublishCommand(TASK_SECOND, TASK_FOREVER, publishCommand, &ts); AsyncMqttClient client; @@ -120,7 +120,11 @@ namespace Mqtt { } void publishBmp280() { + static float lastTemp = 0; Bmp::data.readAll(); + if (abs(lastTemp - Bmp::data.temp) <= 0.2) return; + lastTemp = Bmp::data.temp; + Display::displayTemp(Bmp::data.temp); StaticJsonDocument<255> jsonDoc; jsonDoc["temperature"] = Bmp::data.temp; jsonDoc["pressure"] = Bmp::data.pressure;