8000 ports/esp32-esp8266: Add support for set/get the wifi power saving mode. by glenn20 · Pull Request #8993 · micropython/micropython · GitHub
[go: up one dir, main page]

Skip to content

ports/esp32-esp8266: Add support for set/get the wifi power saving mode. #8993

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 1 commit into from
May 6, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
16 changes: 16 additions & 0 deletions docs/library/network.WLAN.rst
Original file line number Diff line number Diff line change
Expand Up @@ -133,4 +133,20 @@ Methods
hostname The hostname that will be sent to DHCP (STA interfaces) and mDNS (if supported, both STA and AP). (Deprecated, use :func:`network.hostname` instead)
reconnects Number of reconnect attempts to make (integer, 0=none, -1=unlimited)
txpower Maximum transmit power in dBm (integer or float)
pm WiFi Power Management setting (see below for allowed values)
============= ===========

Constants
---------

.. data:: WLAN.PM_PERFORMANCE
WLAN.PM_POWERSAVE
WLAN.PM_NONE

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
15 changes: 15 additions & 0 deletions ports/esp32/network_wlan.c
Original file line number Diff line number Diff line change
Expand Up @@ -508,6 +508,10 @@ STATIC mp_obj_t network_wlan_config(size_t n_args, const mp_obj_t *args, mp_map_
esp_exceptions(esp_wifi_set_protocol(self->if_id, mp_obj_get_int(kwargs->table[i].value)));
break;
}
case MP_QSTR_pm: {
esp_exceptions(esp_wifi_set_ps(mp_obj_get_int(kwargs->table[i].value)));
break;
}
default:
goto unknown;
}
Expand Down Expand Up @@ -602,6 +606,12 @@ STATIC mp_obj_t network_wlan_config(size_t n_args, const mp_obj_t *args, mp_map_
val = MP_OBJ_NEW_SMALL_INT(protocol_bitmap);
break;
}
case MP_QSTR_pm: {
wifi_ps_type_t ps_type;
esp_exceptions(esp_wifi_get_ps(&ps_type));
val = MP_OBJ_NEW_SMALL_INT(ps_type);
break;
}
default:
goto unknown;
}
Expand All @@ -627,6 +637,11 @@ STATIC const mp_rom_map_elem_t wlan_if_locals_dict_table[] = {
{ MP_ROM_QSTR(MP_QSTR_isconnected), MP_ROM_PTR(&network_wlan_isconnected_obj) },
{ MP_ROM_QSTR(MP_QSTR_config), MP_ROM_PTR(&network_wlan_config_obj) },
{ MP_ROM_QSTR(MP_QSTR_ifconfig), MP_ROM_PTR(&esp_network_ifconfig_obj) },

// Constants
{ 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) },
};
STATIC MP_DEFINE_CONST_DICT(wlan_if_locals_dict, wlan_if_locals_dict_table);

Expand Down
13 changes: 13 additions & 0 deletions ports/esp8266/network_wlan.c
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,10 @@ STATIC mp_obj_t esp_config(size_t n_args, const mp_obj_t *args, mp_map_t *kwargs
system_phy_set_max_tpw(power);
break;
}
case MP_QSTR_pm: {
wifi_set_sleep_type(mp_obj_get_int(kwargs->table[i].value));
break;
}
default:
goto unknown;
}
Expand Down Expand Up @@ -486,6 +490,10 @@ STATIC mp_obj_t esp_config(size_t n_args, const mp_obj_t *args, mp_map_t *kwargs
val = mp_obj_new_int(wifi_get_phy_mode());
break;
}
case MP_QSTR_pm: {
val = MP_OBJ_NEW_SMALL_INT(wifi_get_sleep_type());
break;
}
default:
goto unknown;
}
Expand All @@ -511,6 +519,11 @@ STATIC const mp_rom_map_elem_t wlan_if_locals_dict_table[] = {
{ MP_ROM_QSTR(MP_QSTR_isconnected), MP_ROM_PTR(&esp_isconnected_obj) },
{ MP_ROM_QSTR(MP_QSTR_config), MP_ROM_PTR(&esp_config_obj) },
{ MP_ROM_QSTR(MP_QSTR_ifconfig), MP_ROM_PTR(&esp_ifconfig_obj) },

// Constants
{ MP_ROM_QSTR(MP_QSTR_PM_NONE), MP_ROM_INT(NONE_SLEEP_T) },
{ MP_ROM_QSTR(MP_QSTR_PM_PERFORMANCE), MP_ROM_INT(MODEM_SLEEP_T) },
{ MP_ROM_QSTR(MP_QSTR_PM_POWERSAVE), MP_ROM_INT(LIGHT_SLEEP_T) },
};

STATIC MP_DEFINE_CONST_DICT(wlan_if_locals_dict, wlan_if_locals_dict_table);
Expand Down
0