Skip to content

Wifi low power #101

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed

Wifi low power #101

wants to merge 3 commits into from

Conversation

anecdata
Copy link
Member

@anecdata anecdata commented Jun 6, 2020

Expose the NINA firmware setPowerMode function. Note that:

Modem-sleep mode works in Station-only mode and the station must connect to the AP first.

NINA firmware currently implements only WiFi.lowPowerMode() or WiFi.noLowPowerMode(), and low power mode defaults to WIFI_PS_MIN_MODEM:

Minimum modem power saving. In this mode, station wakes up to receive beacon every DTIM period

Preliminary testing of low power mode vs. no low power mode indicates potentially significant difference in power usage, but it is dependent on AP settings and wi-fi usage within the client CircuitPython application.

However, though I may be misunderstanding something, it appears that the default NINA build enables WIFI_PS_MIN_MODEM (though I don't pretend to understand the build process and can't find where it's done in the code). Crude testing with this PR code shows similar battery life for code with no call to esp.wifi_set_power_mode() and call to esp.wifi_set_power_mode(True). Call to esp.wifi_set_power_mode(False) does increase power usage, but there may be a benefit in some cases:

provides minimum latency for receiving Wi-Fi data in real time

Background information is here:
https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-guides/wifi.html#esp32-wi-fi-power-saving-mode

A future enhancement for lower power usage, which would require a change to NINA, could add the option for the higher power saving mode by using esp_wifi_set_ps() with the WIFI_PS_MAX_MODEM value (caveats in the link above), instead of the current call toWiFi.lowPowerMode().

There are other low-power features of the ESP32, but they would require development from scratch in the NINA firmware, plus exposure in this library. There's always the EN pin for super low power usage ;-)

@anecdata anecdata marked this pull request as draft June 6, 2020 03:23
@anecdata
Copy link
Member Author

anecdata commented Jun 6, 2020

Relevant to issue #63

I'd welcome some eyes on this, especially to confirm that NINA already uses MIN modem low power mode. I have an INA219 on order to make better measurements.

In any case, this would allow the option of turning modem low power mode on and off.

@anecdata anecdata marked this pull request as ready for review June 6, 2020 15:32
@jerryneedell
Copy link
Contributor

@anecdata does this require any specific build of the NiNa Firmware?

@anecdata
Copy link
Member Author

anecdata commented Jun 6, 2020

@jerryneedell No, it's independent of any other feature added, and should work all the way back to 1.2.2 at least.

The only caveat I'd add is if the build or IDF changed the default modem low power mode at some point, then default behavior could be different.

Copy link
Contributor

@jerryneedell jerryneedell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ran a test running "cheerlights" on a grandcentral_m4_express with NiNa 1.6

"normal" current draw is 70mA quiet and 130mA active
"power_mode - False" cirrent draw is 140ma quiet to 160mA actve

the LED color was the same for both test (16 Neopixel ring)

looks like it has a significant impact

@jerryneedell
Copy link
Contributor

better example -- just run esp32spi_simpletest
with normal settings -- after completions current goes back to ~70mA

with wiifi_set_power_mode(False) it stays at ~140mA after completion

@anecdata
Copy link
Member Author

anecdata commented Jun 6, 2020

Thanks, Jerry. That's similar to the pattern I observed, and appears to confirm that MIN power save is on by default (at least in recent version of NINA).

@anecdata
Copy link
Member Author

anecdata commented Jun 6, 2020

From research for this issue, it seemed the feature in IDF pre-dates our NINA (2017-ish), although there was a fix in IDF 3.2.2 (which I'm not sure of, but we may not have picked up until NINA 1.4.0) for buffering broadcast/multicast during modem low power mode. ...Nevermind... that 3.2.2 fix was a softAP issue.

@anecdata
Copy link
Member Author

@brentru Any thoughts?

If there's little value in being able to turn off low-power (or perhaps that and using this as a stub for later adding the WIFI_PS_MAX_MODEMhigher-power-save mode (which needs NINA changes), then we can just close this.

@brentru
Copy link
Member

brentru commented Jun 19, 2020

@anecdata Agreed - let's close this in favor of adding the more effective power save mode in nina-fw. Thanks for trying it out.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants