Repository navigation
Reduce WiFi connect current draw on bus powered devices - #1272
Merged
Merged
Conversation
Apply the configured TX power right after the radio starts, instead of after association. Scans and association used to run at full power (~20 dBm) regardless of the setting, and on ESP8266 the setting was never applied at all since the only call sat in the ESP32-only event handler. When the connection is lost, no longer power the radio down and rescan all channels. The disconnect event only logs now; the next connect attempt retries on the last known channel (fast scan) with the radio still on, and only falls back to the full WiFi restart if that retry has not connected within CONNECTION_TIMEOUT. Both reduce the current spikes that brown out HAN powered boards (Pow-U etc.) with a weak signal. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Contributor
|
Interesting! Could this discovery be linked to the issues Stig Landrø saw? |
A fast scan on the remembered channel ends at the first AP matching the SSID. Mesh nodes often share a channel, so the retry could join a weaker node than the one the full scan had picked. Remember the BSSID as well and retry exactly that AP; if it is gone, the existing timeout falls back to a full WiFi restart and all-channel scan, which picks the strongest AP again. Co-Authored-By: Claude Opus 5.5 <[email protected]>
🔧 PR Build ArtifactsVersion: All environments built successfully. Download the zip files:
|
3 of 7 tasks
This was referenced Nov 5, 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.
Why
A HAN-powered Pow-U in a technical room with weak WiFi was reboot looping. On boot it sat in the supply-voltage wait (long yellow LED) because the capacitor could not charge fully, then browned out while WiFi was connecting. Two things in the WiFi client handler made connecting draw more current than necessary:
ARDUINO_EVENT_WIFI_STA_CONNECTED). Scans and connection attempts always ran at the full ~20 dBm. On ESP8266 the setting was never applied at all, because the onlysetOutputPowercall sat inside the ESP32-only event handler.STA_DISCONNECTEDevent turned WiFi off entirely (WiFi.mode(WIFI_OFF)). The next connect then restarted the radio and scanned all channels.What changed (
src/WiFiClientConnectionHandler.*)applyTxPower()helper, called right afterWiFi.mode(WIFI_STA)and before connecting. It is still reapplied once connected on ESP32, and it now works on ESP8266 too.isConnected()remembers the current channel and AP (BSSID). On the next connect attempt after a lost connection, it retries exactly that AP on its channel with the radio still on:WIFI_FAST_SCANwithbssid_seton ESP32,WiFi.begin(ssid, psk, channel, bssid)on ESP8266. That AP is the one the last full all-channel scan (WIFI_CONNECT_AP_BY_SIGNAL) picked as the strongest. Pinning the BSSID matters on mesh networks: a fast scan on the channel alone ends at the first matching node, and mesh nodes often share a channel.CONNECTION_TIMEOUT(30 s). An explicitdisconnect()clears the remembered channel.Trade-offs
btm_enabled. I have not verified whether a pinned BSSID blocks mesh steering via 802.11v on this SDK.Testing
pio runfor esp32s2, esp32 and esp8266: all buildReconnecting to WiFi network: … (channel N, AP xx:xx:…)instead ofclosing resources, and reconnects to the same AP🤖 Generated with Claude Code