Repository navigation
Rest the radio between failed WiFi connection attempts on ESP32 - #1308
Merged
Merged
Conversation
With auto-reconnect enabled, the ESP32 core retries back to back after every failed connection attempt, keeping the radio busy. A bus powered device with a weak signal or an unavailable AP can not sustain that. Disable the core's auto-reconnect on ESP32 and pace retries ourselves. The disconnect event now tells a lost established connection apart from a failed attempt: a lost connection still leaves the radio on for the fast same-AP retry in connect(), while a failed attempt turns WiFi off for RECONNECT_TIMEOUT before connect() tries again with a full scan. ESP8266 keeps auto-reconnect. Co-Authored-By: Claude Opus 5.5 <[email protected]>
🔧 PR Build ArtifactsVersion: All environments built successfully. Download the zip files:
|
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.
Why
Follow-up to #1272, for bus powered devices (Pow-U etc.) with a weak signal or an unavailable AP.
setAutoReconnect(true)lets the ESP32 core retry immediately after every failed connection attempt. #1272 also stopped the disconnect event from turning WiFi off. Together, while the AP can't be reached, the radio retries back to back and never rests. That draws the most current exactly when the device's supply is weakest.What changed (
src/WiFiClientConnectionHandler.*)connect()andeventHandler(). ESP8266 keepssetAutoReconnect(true).linkUpflag. It is set onSTA_CONNECTEDand cleared indisconnect(). The disconnect event uses it to tell the two cases apart:connect()then does the fast same-AP retry from Reduce WiFi connect current draw on bus powered devices #1272 with the radio still on.disconnect(RECONNECT_TIMEOUT)turns WiFi off for 5 s. The nextconnect()restarts the radio and scans all channels.Effect on the #1272 fallback
The fast same-AP retry now gets a single attempt. If it fails, the device falls back to a full scan after ~5 s instead of waiting out
CONNECTION_TIMEOUT(30 s). With a wrong password or an AP that changed channel, the fallback comes sooner than in #1272.disconnect()is called from the WiFi event handler again, as it was before #1272.Measurements
Pow-U (ESP32-S2) at 5 V from a Nordic PPK2, staying connected to the AP. Recorded for 2 min starting ~150 s after boot, built on top of #1306:
While connected, power is unchanged, as expected. The failed-connect path this PR targets has not been measured yet.
Testing
pio runfor esp32s2, esp32 and esp8266: all build (esp8266 flash at 98.4%)Reconnecting to WiFi network: … (channel N, AP …)and rejoins the same AP🤖 Generated with Claude Code