Repository navigation
Query the WiFi driver once per connection, not on every isConnected() - #1306
Merged
Merged
Conversation
a66a925 made isConnected() call WiFi.BSSID() and WiFi.channel() on every call, to remember the AP for a fast reconnect. isConnected() runs on every loop(), and those driver queries woke the radio from modem sleep for ~12 ms each time. With WiFi power saving enabled the radio was awake about half the time instead of ~4%, raising the average draw of a Pow-U from ~105 mA to ~145 mA at 5 V. Record the AP only when none is remembered. lastChannel is already reset by disconnect() and by the fast retry in connect(), so it is recorded again after every reconnect. Co-Authored-By: Claude Opus 5.5 <[email protected]>
🔧 PR Build ArtifactsVersion: All environments built successfully. Download the zip files:
|
2 of 5 tasks
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
v2.6.0-rc2 makes a Pow-U draw about 38% more power than v2.5.7: 145 mA instead of 105 mA at 5 V (724 mW instead of 527 mW).
mainbehaves the same as rc2. On HAN powered devices this eats into the margin that #1272 was meant to improve.The cause is in #1272 (a66a925).
isConnected()callsWiFi.BSSID()andWiFi.channel()on every call to remember the AP for the fast reconnect.isConnected()runs on everyloop(), about 40 times per second. Each of those driver queries wakes the radio from modem sleep for ~12 ms, so with WiFi power saving enabled the radio was awake 54% of the time instead of ~4%. I have not checked which of the two calls is responsible; the fix avoids both.What changed (
src/WiFiClientConnectionHandler.cpp)isConnected()records the BSSID and channel only when none is remembered (lastChannel == 0).lastChannelis already reset bydisconnect()and by the fast retry inconnect(), so the AP is recorded again after every reconnect.Measurements
Same Pow-U (ESP32-S2) and config, powered at 5 V by a Nordic PPK2 (source mode, 100 kS/s). WiFi power saving was at max modem sleep, no meter connected. Recording started ~150 s after boot.
main(d25d6c1)main+ this PRThe v2.5.7 and rc2 runs are 10 min each. The
mainruns are 2 min, which is enough: 2-minute windows of the long runs vary by less than 1 mA.On rc2 and
mainthe 1 ms trace shows a ~12 ms step to ~175 mA on every loop pass, about every 24 ms. With this PR the trace matches v2.5.7.Trade-offs
If the ESP32 core auto-reconnects to a different AP without
loop()ever seeing the link down, the remembered BSSID stays stale until the next disconnect. Before this PR it was refreshed on every call.Testing
pio runfor esp32s2, esp32 and esp8266: all build (esp8266 flash at 98.4%)Reconnecting to WiFi network: … (channel N, AP xx:xx:…)with the correct AP, and reconnects🤖 Generated with Claude Code