From f9cbd507deb127cd3078785f55b761a34b3db908 Mon Sep 17 00:00:00 2001 From: Maxim Prokhorov Date: Fri, 26 Feb 2021 17:40:58 +0300 Subject: [PATCH] mqtt: cancel heartbeat when disconnected --- code/espurna/mqtt.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/code/espurna/mqtt.cpp b/code/espurna/mqtt.cpp index 57b7ec32..d2d73fcd 100644 --- a/code/espurna/mqtt.cpp +++ b/code/espurna/mqtt.cpp @@ -574,19 +574,20 @@ void _mqttCallback(unsigned int type, const char * topic, const char * payload) } bool _mqttHeartbeat(heartbeat::Mask mask) { + // No point retrying, since we will be re-scheduled on connection + if (!mqttConnected()) { + return true; + } + +#if NTP_SUPPORT // Backported from the older utils implementation. // Wait until the time is synced to avoid sending partial report *and* // as a result, wait until the next interval to actually send the datetime string. -#if NTP_SUPPORT if ((mask & heartbeat::Report::Datetime) && !ntpSynced()) { return false; } #endif - if (!mqttConnected()) { - return false; - } - // TODO: rework old HEARTBEAT_REPEAT_STATUS? // for example: send full report once, send only the dynamic data after that // (interval, hostname, description, ssid, bssid, ip, mac, rssi, uptime, datetime, heap, loadavg, vcc)