Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 29 additions & 6 deletions reference/micropython/network/WLAN.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,40 @@ class WLAN:
"""

PM_NONE: int
PM_POWERSAVE: int
PM_PERFORMANCE: int
PM_POWERSAVE: int

"""\
Allowed values for the ``WLAN.config(pm=...)`` network interface parameter:

* ``PM_PERFORMANCE``: enable WiFi power management to balance power
savings and WiFi performance
* ``PM_POWERSAVE``: enable WiFi power management with additional power
savings and reduced WiFi performance
* ``PM_NONE``: disable wifi power management
* ``PM_NONE``: disable WiFi power management (always on, highest performance, highest power consumption)
* ``PM_PERFORMANCE``: enable WiFi power management to balance power savings and WiFi performance
* ``PM_POWERSAVE``: enable WiFi power management with additional power savings and reduced WiFi performance

**Note:** The numeric values of these constants are platform-specific:

Copy link
Owner

Choose a reason for hiding this comment

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

Please summarize the different platform values in a table rather than extensive text

Copy link
Owner

Choose a reason for hiding this comment

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

@copilot see comment above

* **ESP32** (using Espressif WiFi driver):

- ``PM_NONE = 0`` (maps to WIFI_PS_NONE)
- ``PM_PERFORMANCE = 1`` (maps to WIFI_PS_MIN_MODEM)
- ``PM_POWERSAVE = 2`` (maps to WIFI_PS_MAX_MODEM)

* **ESP8266** (using Espressif WiFi driver):

- ``PM_NONE = 0``
- ``PM_PERFORMANCE = 2``
- ``PM_POWERSAVE = 1``

* **RP2 Pico W** (using Cyw43 driver):

- ``PM_NONE = 16`` (0x10)
- ``PM_PERFORMANCE = 10555714`` (0xa11142, aggressive power saving disabled)
- ``PM_POWERSAVE = 17`` (0x11, aggressive power saving enabled)

Always use the symbolic constants (``PM_NONE``, ``PM_PERFORMANCE``, ``PM_POWERSAVE``) rather than
numeric values for portability across different MicroPython ports and boards.

See: https://github.com/micropython/micropython/blob/master/ports/esp32/network_wlan.c
"""

def __init__(self, interface_id: int = ..., /) -> None:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,9 @@
# ref : https://github.com/Josverl/micropython-stubber/issues/338
wlan = network.WLAN(network.STA_IF)

wlan.config(pm = 0xa11140) # set power mode to get WiFi power-saving off (if needed)
wlan.config(pm = 0xa11140) # set power mode to get WiFi power-saving off (if needed)

# Better: Use symbolic constants for portability across different MicroPython ports
wlan.config(pm=network.WLAN.PM_NONE) # Disable power management
wlan.config(pm=network.WLAN.PM_PERFORMANCE) # Balanced power/performance
wlan.config(pm=network.WLAN.PM_POWERSAVE) # Maximum power saving