From 170c30c4b730393e578461d329229d45f32829d4 Mon Sep 17 00:00:00 2001 From: Kiran Jonnalagadda Date: Sun, 19 Jul 2026 15:35:13 +0530 Subject: [PATCH] fix(mqtt): back off when MQTT host is unconfigured tryConnect() early-returned on empty host without advancing s_nextTryMs, so loop() re-invoked it every iteration once WiFi was up -- re-reading NVS and logging 'mqtt_host NOT_FOUND' ~16x/sec. Set a 60s backoff in that branch. Verified 250->1 log lines / 14s. Co-Authored-By: Claude Opus 4.8 --- src/net/mqtt.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/net/mqtt.cpp b/src/net/mqtt.cpp index 73e152b..0f29cc9 100644 --- a/src/net/mqtt.cpp +++ b/src/net/mqtt.cpp @@ -89,7 +89,15 @@ static void onMessage(char* topicC, byte* payload, unsigned len) { static void tryConnect() { if (netwifi::state() != netwifi::State::Connected) return; String host = settings::getMqttHost(); - if (host.length() == 0) return; + if (host.length() == 0) { + // MQTT host not configured. Back off instead of returning straight + // to loop(), which (with s_nextTryMs unchanged) re-invokes us every + // iteration — re-reading NVS and logging "mqtt_host NOT_FOUND" ~16x + // a second. A minute-scale recheck still picks up creds set later + // without flooding the log or spinning the CPU. + s_nextTryMs = millis() + 60000; + return; + } uint16_t port = settings::getMqttPort(); String user = settings::getMqttUser(); String pw = settings::getMqttPw();