Skip to content

Set "disabled" PM at reset, provide PM constants and better documentation #6976

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

Merged
merged 3 commits into from
Oct 1, 2022

Conversation

jepler
Copy link

@jepler jepler commented Sep 30, 2022

Sets the 0x00a11140 power saving mode at reset time, which is called PM_DISABLED.

The following PM constants are provided:

cyw43.PM_DISABLED    = 0xa11140
cyw43.PM_AGGRESSIVE  = 0xa11c82
cyw43.PM_STANDARD    = 0xa11142
cyw43.PM_PERFORMANCE = 0x111022

"STANDARD" is what was called "DEFAULT" in cyw43 documentation, except we're overriding the default.

Closes: #6958 (pending testing from @anecdata)

Copy link
Member

@anecdata anecdata left a comment

Choose a reason for hiding this comment

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

Based on a couple of days of uP testing, and today with CP, I think this is the way to go, at least for now. Connections will be more reliable, and users will have less grief.

I've been running side-by-side power modes 0 and 2 for a couple of hours based on the prior merge (automatically re-connecting to the AP after an OSError: 2), and the 0 (power-save OFF) has been successively doing requests every 10 minutes without any disconnections or failures. The 2 (prior PR, and uP, default power save) output is:

Connected? 192.168.6.199
2022-09-30T12:26:15-05:00 600 200 OK b'This is a test of Adafruit WiFi!\nIf you can read this, its working :)'
2022-09-30T12:36:19-05:00 600 200 OK b'This is a test of Adafruit WiFi!\nIf you can read this, its working :)'
2022-09-30T12:46:22-05:00 600 200 OK b'This is a test of Adafruit WiFi!\nIf you can read this, its working :)'
[Errno 2] No such file/directory
Connected? 192.168.6.199
2022-09-30T12:56:42-05:00 600 200 OK b'This is a test of Adafruit WiFi!\nIf you can read this, its working :)'
2022-09-30T13:06:46-05:00 600 200 OK b'This is a test of Adafruit WiFi!\nIf you can read this, its working :)'
2022-09-30T13:16:51-05:00 600 200 OK b'This is a test of Adafruit WiFi!\nIf you can read this, its working :)'
[Errno 2] No such file/directory
Connected? 192.168.6.199
2022-09-30T13:27:12-05:00 600 200 OK b'This is a test of Adafruit WiFi!\nIf you can read this, its working :)'
[Errno 2] No such file/directory
Connected? 192.168.6.199
2022-09-30T13:37:34-05:00 600 200 OK b'This is a test of Adafruit WiFi!\nIf you can read this, its working :)'
[Errno 2] No such file/directory
Connected? 192.168.6.199
2022-09-30T13:47:55-05:00 600 200 OK b'This is a test of Adafruit WiFi!\nIf you can read this, its working :)'
[Errno 2] No such file/directory
Connected? 192.168.6.199
2022-09-30T13:58:16-05:00 600 200 OK b'This is a test of Adafruit WiFi!\nIf you can read this, its working :)'
[Errno 2] No such file/directory
Connected? 192.168.6.199
2022-09-30T14:08:37-05:00 600 200 OK b'This is a test of Adafruit WiFi!\nIf you can read this, its working :)'
[Errno 2] No such file/directory
Connected? 192.168.6.199
2022-09-30T14:18:58-05:00 600 200 OK b'This is a test of Adafruit WiFi!\nIf you can read this, its working :)'
[Errno 2] No such file/directory
Connected? 192.168.6.199
2022-09-30T14:29:19-05:00 600 200 OK b'This is a test of Adafruit WiFi!\nIf you can read this, its working :)'
[Errno 2] No such file/directory
Connected? 192.168.6.199
2022-09-30T14:39:40-05:00 600 200 OK b'This is a test of Adafruit WiFi!\nIf you can read this, its working :)'

Frequent OSError, but recoverable with reconnection to the AP. I'll restest the modes with artifacts from this PR when available, and let it go overnight or longer. But I'm good with this approach. Thank you!

@jepler
Copy link
Author

jepler commented Sep 30, 2022

I think maybe this doesn't do its intended purpose, because cyw43_arch_enable_sta_mode calls cyw43_wifi_set_up which calls cyw43_wifi_pm. So you can't set the PM mode before putting the wifi up!

@anecdata
Copy link
Member

Is that wlan.activate(True) in uP? Maybe default it or an extra keyword arg added to wifi.radio.start_station() or wifi.radio.connect() (and wifi.radio.start_ap()), or some such.

@jepler
Copy link
Author

jepler commented Sep 30, 2022

My plan is to keep the value given to set_power_management and re-enforce it when bringing up the interface.

@anecdata
Copy link
Member

anecdata commented Sep 30, 2022

I think maybe this doesn't do its intended purpose, because cyw43_arch_enable_sta_mode calls cyw43_wifi_set_up which calls cyw43_wifi_pm. So you can't set the PM mode before putting the wifi up!

In uP, the pm config is a method on the network.WLAN which had already been activated. In my CP testing above (and continuing consistent with that report), results may be depending on the fact that they both started with a reload not a reset.

@jepler
Copy link
Author

jepler commented Sep 30, 2022

Updated version maybe sets power management off by default as intended.

.. the value actually needs to be enforced each time the STA or AP
is enabled, because internally there's a call to cyw43_wifi_pm with the
library's defaut power management value, not ours.

Add a getter, though it only returns our idea of what the power
management register is set to, it doesn't read out from the actual
hardware, sadly.
Copy link
Member

@anecdata anecdata left a comment

Choose a reason for hiding this comment

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

Looking good after 60 minutes. Hard-reset, then requests at 10-minute intervals. The board running the new CircuitPython default (no power-save; no calls to cyw43.set_power_management()) has had no disconnections.

@dhalbert
Copy link
Collaborator

dhalbert commented Oct 1, 2022

@jepler Could you fix the two typos I noted above, and possibly address the other comment above?

@jepler jepler requested a review from dhalbert October 1, 2022 15:10
@jepler
Copy link
Author

jepler commented Oct 1, 2022

Done @dhalbert

Copy link
Collaborator

@dhalbert dhalbert left a comment

Choose a reason for hiding this comment

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

Ready for merge after this? I can stop the unnecessary rebuilds, since this is only a doc change.

@jepler
Copy link
Author

jepler commented Oct 1, 2022

Yes I think it's ready!

@dhalbert dhalbert merged commit c518d68 into adafruit:main Oct 1, 2022
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.

Raspberry Pi Pico W network becomes inaccessible when not used for some time
3 participants