fix(mqtt): stop tryConnect() log-flood when MQTT host is unconfigured - #2
Open
jace wants to merge 1 commit into
Open
fix(mqtt): stop tryConnect() log-flood when MQTT host is unconfigured#2jace wants to merge 1 commit into
jace wants to merge 1 commit into
Conversation
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 <noreply@anthropic.com>
Author
|
Hello! I'm building FlashBee with a DFRobot lightning sensor instead of a Seeed Studio Grove sensor as I couldn't find one. I asked Claude Code to run the tests for hardware compatibility, and in the process it spotted a small gap in the logic, when WiFi is configured but no MQTT server is configured. I'll open a few more PRs for the things I find. Hope that's okay! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
When WiFi is connected but no MQTT host is configured,
tryConnect()spins on everyloop()iteration — re-reading NVS and emitting an error log each time.tryConnect()early-returns on an empty host without advancings_nextTryMs:loop()only callstryConnect()whenmillis() >= s_nextTryMs. Since the empty-host path leavess_nextTryMsuntouched, it fires every iteration (~60 ms). Each call re-readsmqtt_hostfrom NVS, and the ESPPreferenceslayer logsnvs_get_str len fail: mqtt_host NOT_FOUNDat error level — flooding the serial/remote log (~16 lines/sec) indefinitely for any WiFi-up-but-MQTT-unconfigured deployment (the default for anyone using WiFi/OTA without MQTT).Fix
Give the "host not configured" branch the same backoff discipline the genuine-failure path already has: set a 60 s retry window before returning. A minute-scale recheck still picks up credentials set later without spinning.
Verification
Bench-tested on a XIAO ESP32-C3, WiFi associated, no MQTT host set:
mqtt_host NOT_FOUNDlines / 14 sThe configured-MQTT path is untouched (no behavior change when a host is set), and the recheck still self-corrects if credentials are added at runtime.
🤖 Generated with Claude Code