From 988d096452d6ab3f6ad6e478080c4cdc663f14ae Mon Sep 17 00:00:00 2001 From: irekzielinski Date: Mon, 13 Jul 2020 17:37:45 +0100 Subject: [PATCH] fixed minor issue with MQTT updates beign sent too frequently --- PylontechMonitoring.ino | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/PylontechMonitoring.ino b/PylontechMonitoring.ino index 8e607de..2e26c4f 100644 --- a/PylontechMonitoring.ino +++ b/PylontechMonitoring.ino @@ -740,13 +740,15 @@ void mqttLoop() sendCommandAndReadSerialResponse("pwr") == true) { static batteryStack lastSentData; //this is the last state we sent to MQTT, used to prevent sending the same data over and over again + static unsigned int callCnt = 0; parsePwrResponse(g_szRecvBuff); prepareJsonOutput(g_szRecvBuff, sizeof(g_szRecvBuff)); - bool forceUpdate = (g_lastDataSent == 0) || (millis() % 20 == 0); //push all the data every 20th call + bool forceUpdate = (callCnt % 20 == 0); //push all the data every 20th call pushBatteryDataToMqtt(lastSentData, forceUpdate); + callCnt++; g_lastDataSent = os_getCurrentTimeSec(); memcpy(&lastSentData, &g_stack, sizeof(batteryStack)); }