8000 esp32/8266: WLAN(): add support for set/get wifi power saving mode. · micropython/micropython@67b8547 · GitHub
[go: up one dir, main page]

Skip to content

Commit 67b8547

Browse files
committed
esp32/8266: WLAN(): add support for set/get wifi power saving mode.
For esp32 and esp8266: adds: - 'pm' option to WLAN.config() to set/get the wifi power saving mode; and - PM_NONE, PM_MIN_MODEM, PM_MAX_MODEM and PM_LIGHT_SLEEP (eps8266 only) constants to the WLAN class.
1 parent e4d90be commit 67b8547

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

ports/esp32/network_wlan.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -493,6 +493,10 @@ STATIC mp_obj_t network_wlan_config(size_t n_args, const mp_obj_t *args, mp_map_
493493
esp_exceptions(esp_wifi_set_protocol(self->if_id, mp_obj_get_int(kwargs->table[i].value)));
494494
break;
495495
}
496+
case MP_QSTR_pm: {
497+
esp_exceptions(esp_wifi_set_ps(mp_obj_get_int(kwargs->table[i].value)));
498+
break;
499+
}
496500
default:
497501
goto unknown;
498502
}
@@ -587,6 +591,12 @@ STATIC mp_obj_t network_wlan_config(size_t n_args, const mp_obj_t *args, mp_map_
587591
val = MP_OBJ_NEW_SMALL_INT(protocol_bitmap);
588592
break;
589593
}
594+
case MP_QSTR_pm: {
595+
wifi_ps_type_t ps_type;
596+
esp_exceptions(esp_wifi_get_ps(&ps_type));
597+
val = MP_OBJ_NEW_SMALL_INT(ps_type);
598+
break;
599+
}
590600
default:
591601
goto unknown;
592602
}
@@ -612,6 +622,11 @@ STATIC const mp_rom_map_elem_t wlan_if_locals_dict_table[] = {
612622
{ MP_ROM_QSTR(MP_QSTR_isconnected), MP_ROM_PTR(&network_wlan_isconnected_obj) },
613623
{ MP_ROM_QSTR(MP_QSTR_config), MP_ROM_PTR(&network_wlan_config_obj) },
614624
{ MP_ROM_QSTR(MP_QSTR_ifconfig), MP_ROM_PTR(&esp_ifconfig_obj) },
625+
626+
// Constants
627+
{ MP_ROM_QSTR(MP_QSTR_PM_NONE), MP_ROM_INT(WIFI_PS_NONE) },
628+
{ MP_ROM_QSTR(MP_QSTR_PM_MIN_MODEM), MP_ROM_INT(WIFI_PS_MIN_MODEM) },
629+
{ MP_ROM_QSTR(MP_QSTR_PM_MAX_MODEM), MP_ROM_INT(WIFI_PS_MAX_MODEM) },
615630
};
616631
STATIC MP_DEFINE_CONST_DICT(wlan_if_locals_dict, wlan_if_locals_dict_table);
617632

ports/esp8266/modnetwork.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,10 @@ STATIC mp_obj_t esp_config(size_t n_args, const mp_obj_t *args, mp_map_t *kwargs
410410
wifi_set_phy_mode(mp_obj_get_int(kwargs->table[i].value));
411411
break;
412412
}
413+
case MP_QSTR_pm: {
414+
wifi_set_sleep_type(mp_obj_get_int(kwargs->table[i].value));
415+
break;
416+
}
413417
default:
414418
goto unknown;
415419
}
@@ -481,6 +485,10 @@ STATIC mp_obj_t esp_config(size_t n_args, const mp_obj_t *args, mp_map_t *kwargs
481485
val = mp_obj_new_int(wifi_get_phy_mode());
482486
break;
483487
}
488+
case MP_QSTR_pm: {
489+
val = MP_OBJ_NEW_SMALL_INT(wifi_get_sleep_type());
490+
break;
491+
}
484492
default:
485493
goto unknown;
486494
}
@@ -506,6 +514,12 @@ STATIC const mp_rom_map_elem_t wlan_if_locals_dict_table[] = {
506514
{ MP_ROM_QSTR(MP_QSTR_isconnected), MP_ROM_PTR(&esp_isconnected_obj) },
507515
{ MP_ROM_QSTR(MP_QSTR_config), MP_ROM_PTR(&esp_config_obj) },
508516
{ MP_ROM_QSTR(MP_QSTR_ifconfig), MP_ROM_PTR(&esp_ifconfig_obj) },
517+
518+
// Constants
519+
{ MP_ROM_QSTR(MP_QSTR_PM_NONE), MP_ROM_INT(NONE_SLEEP_T) },
520+
{ MP_ROM_QSTR(MP_QSTR_PM_MIN_MODEM), MP_ROM_INT(MODEM_SLEEP_T) },
521+
{ MP_ROM_QSTR(MP_QSTR_PM_MAX_MODEM), MP_ROM_INT(MODEM_SLEEP_T) },
522+
{ MP_ROM_QSTR(MP_QSTR_PM_LIGHT_SLEEP), MP_ROM_INT(LIGHT_SLEEP_T) },
509523
};
510524

511525
STATIC MP_DEFINE_CONST_DICT(wlan_if_locals_dict, wlan_if_locals_dict_table);

0 commit comments

Comments
 (0)
0