Document platform-specific WiFi power management constants for ESP32, ESP8266, and Cyw43
The WiFi power management constants (PM_NONE, PM_PERFORMANCE, PM_POWERSAVE) in network.WLAN were undocumented in reference stubs, and their platform-specific numeric values were not clarified.
Changes
-
Enhanced
reference/micropython/network/WLAN.pyi:- Added detailed docstring documenting PM constants with platform-specific values
- Documented value discrepancy between ESP32 (0,1,2) and ESP8266 (0,2,1)
- Added RP2 Pico W/Cyw43 values (16, 10555714, 17)
- Included C constant mappings for ESP32 (WIFI_PS_NONE, WIFI_PS_MIN_MODEM, WIFI_PS_MAX_MODEM)
- Recommended using symbolic constants for cross-platform portability
-
Updated
tests/quality_tests/feat_networking/check_network/check_wlan.py:- Added examples demonstrating symbolic constant usage
Example
import network
wlan = network.WLAN(network.STA_IF)
# Platform-portable approach (recommended)
wlan.config(pm=network.WLAN.PM_NONE) # Disable power management
wlan.config(pm=network.WLAN.PM_PERFORMANCE) # Balanced mode
wlan.config(pm=network.WLAN.PM_POWERSAVE) # Maximum power saving
# Platform-specific magic numbers (avoid)
wlan.config(pm=0xa11140) # Only works on RP2 Pico W
Values verified against published stubs for v1.24.1+ across ESP32, ESP8266, and RP2 ports.
Original prompt
This section details on the original issue you should resolve
<issue_title>Add powermanagement constants for ESPxxx and Cyw43</issue_title> <issue_description>Document constants for ESPxxx and cyw43 in reference stubs
network.wlan
{ MP_ROM_QSTR(MP_QSTR_PM_NONE), MP_ROM_INT(WIFI_PS_NONE) }, { MP_ROM_QSTR(MP_QSTR_PM_PERFORMANCE), MP_ROM_INT(WIFI_PS_MIN_MODEM) }, { MP_ROM_QSTR(MP_QSTR_PM_POWERSAVE), MP_ROM_INT(WIFI_PS_MAX_MODEM) },https://github.com/micropython/micropython/blob/2762fe680a03706d3c21efe51db9b1f8d193d2d0/ports/esp32/network_wlan.c#L774C1-L776C74</issue_description>
Comments on the Issue (you are @copilot in this section)
- Fixes Josverl/micropython-stubs#847
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.