Repository navigation
WiFi observability: stop failing silently (4/7) - #45
Merged
Merged
Conversation
…ode scan diagnostic The firmware swallowed every WiFi outcome: begin() was fired and nothing was ever reported — a failing link just looked idle, and even successful reconnects never printed the acquired IP. Debugging meant guessing between password, signal, router, and firmware. (This is how a marginal-RF AUTH_EXPIRE failure burned an evening being mistaken for a config bug.) - WiFi.onEvent handler: STA start / association / got-IP (with RSSI, printed on EVERY acquire) / lost-IP / disconnect with the IDF reason code translated to text (AUTH_EXPIRE, NO_AP_FOUND, 4WAY_HANDSHAKE_TIMEOUT, ...), plus setup-AP client join/leave. Pure logging on the event task; connect edges are still handled by the handleWifiMaintenance() poll (P0.1 untouched). - The silent skip is now spoken: when a reconnect is due but held off because a client is parked on the setup AP (the deliberate #40 guard), a rate-limited line says so instead of nothing. lastWifiAttempt is not reset by the log, so the retry still fires the moment the client leaves. - Diagnostic scan while disconnected (every ~95 s, same AP-client guard): async scan logging every BSSID broadcasting the target SSID with channel, RSSI and auth mode — distinguishes not-visible / too-weak / wrong-auth / mesh-node-that-won't-answer from the device's own radio. Field-proven on hardware: the new logs pinned tonight's failure in minutes (reason 2 AUTH_EXPIRE + scan showing the SSID at -87 dBm on ch 11 = marginal RF at the auth handshake; connection recovered and verified end-to-end). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
The scan only logged networks matching the configured SSID, so a scan result of "0 broadcasting Untz" could not distinguish two very different failures: the AP is gone/renamed, versus this radio is deaf (e.g. the XIAO's u.FL antenna knocked loose — it detaches easily during handling). When the target isn't found, log every visible network (SSID, channel, RSSI), capped at 8 so a dense 2.4 GHz band can't spam the log. One line now separates "sees 7 networks, none are ours" from "sees 1 network". Prompted by a live NO_AP_FOUND on hardware where the device could see a single network while a laptop beside it saw seven.
Found in review of the scan diagnostic. A WiFi.begin() issued while the async diagnostic scan runs aborts the scan (the IDF returns ESP_ERR_WIFI_STATE), and the Arduino core's scan-done handler posts the truncated count without checking its status — so scanComplete() returned 0 or a partial result as if the scan had finished. Logged, that reads as "0 networks visible" or one weak `heard:` entry: exactly the "deaf radio / antenna knocked off" signature the listing exists to detect. With the scan every 95 s and the reconnect every 30 s, about one scan in six collided (~every 10 minutes), and the collision also cost that reconnect attempt. - The scan and the reconnect are gated against each other. The automatic reconnect holds off while a scan is pending (lastWifiAttempt is not reset, so it fires as soon as the scan finishes; the wait is bounded at 15 s so a lost event can never wedge reconnects), and a scan never starts within 10 s of a connect attempt. - A user-initiated connect (credentials just saved) outranks the diagnostic: it stops the scan (esp_wifi_scan_stop) and drops the partial result. - The IDF's own scan-done status is captured in the event handler; a result from a scan that didn't complete is discarded and logged as interrupted rather than reported as a reading. - Hidden networks log as "(hidden)" instead of an empty quoted string. - The old comment claiming a collision "just aborts the scan — retried next cycle" was wrong and is gone. Verified: firmware builds; 82/82 native tests. The IDF event path has no native coverage — it is hardware-only. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This was referenced Sep 12, 2026
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.
What
WiFi stops failing silently. This is mostly logging. The one behavior change: the automatic reconnect now waits for a running diagnostic scan to finish (a few seconds, bounded at 15 s), because the two used to collide.
Event logging: association, got-IP on every acquire (with RSSI), lost-IP, disconnects with the IDF reason code translated to text (
AUTH_EXPIRE,NO_AP_FOUND, …), and setup-AP client join/leave.The deliberate "reconnect paused while a client is on the setup AP" rule now says so, instead of staying silent.
Diagnostic scan while disconnected: every BSSID broadcasting your SSID (channel, RSSI, auth mode). If the SSID isn't found, it lists what the radio can hear, which separates "the router is gone" from "this radio is deaf" (e.g. a loose u.FL antenna).
Review follow-up: a reconnect issued mid-scan aborted the scan, and the truncated result was logged as a real reading. That faked the "deaf radio" signature the listing exists to detect, about one scan in six. The scan and reconnect are now gated against each other. A user-initiated connect cancels a running scan. Results from a scan the WiFi stack reports as incomplete are discarded. Hidden networks log as "(hidden)".
Review notes
A single file (
src/network/wifi.cpp).Verification
Built and tested on this branch alone. This stacked state is new, so it was verified independently rather than assumed: 81/81 native tests pass, the firmware builds for
seeed_xiao_esp32c3(91.3% of the app partition), and the web UI JS passesnode --check.Field-proven: these logs diagnosed a marginal-RF
AUTH_EXPIRE(−87 dBm) and aNO_AP_FOUNDon real hardware.🤖 Generated with Claude Code
The stack (merge top to bottom):