Skip to content

Commit a66a99b

Browse files
owens-billpfalcon
authored andcommitted
esp8266: Added wifi_mode() to read and set WiFi operating mode.
1 parent a160b70 commit a66a99b

2 files changed

Lines changed: 22 additions & 0 deletions

File tree

esp8266/modesp.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -509,6 +509,16 @@ void error_check(bool status, const char *msg) {
509509
}
510510
}
511511

512+
STATIC mp_obj_t esp_wifi_mode(mp_uint_t n_args, const mp_obj_t *args) {
513+
if (n_args == 0) {
514+
return mp_obj_new_int(wifi_get_opmode());
515+
} else {
516+
wifi_set_opmode(mp_obj_get_int(args[0]));
517+
return mp_const_none;
518+
}
519+
}
520+
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(esp_wifi_mode_obj, 0, 1, esp_wifi_mode);
521+
512522
STATIC mp_obj_t esp_phy_mode(mp_uint_t n_args, const mp_obj_t *args) {
513523
if (n_args == 0) {
514524
return mp_obj_new_int(wifi_get_phy_mode());
@@ -565,6 +575,7 @@ STATIC const mp_map_elem_t esp_module_globals_table[] = {
565575

566576
{ MP_OBJ_NEW_QSTR(MP_QSTR_mac), (mp_obj_t)&esp_mac_obj },
567577
{ MP_OBJ_NEW_QSTR(MP_QSTR_getaddrinfo), (mp_obj_t)&esp_getaddrinfo_obj },
578+
{ MP_OBJ_NEW_QSTR(MP_QSTR_wifi_mode), (mp_obj_t)&esp_wifi_mode_obj },
568579
{ MP_OBJ_NEW_QSTR(MP_QSTR_phy_mode), (mp_obj_t)&esp_phy_mode_obj },
569580
{ MP_OBJ_NEW_QSTR(MP_QSTR_sleep_type), (mp_obj_t)&esp_sleep_type_obj },
570581
{ MP_OBJ_NEW_QSTR(MP_QSTR_deepsleep), (mp_obj_t)&esp_deepsleep_obj },
@@ -585,6 +596,13 @@ STATIC const mp_map_elem_t esp_module_globals_table[] = {
585596
MP_OBJ_NEW_SMALL_INT(LIGHT_SLEEP_T) },
586597
{ MP_OBJ_NEW_QSTR(MP_QSTR_SLEEP_MODEM),
587598
MP_OBJ_NEW_SMALL_INT(MODEM_SLEEP_T) },
599+
600+
{ MP_OBJ_NEW_QSTR(MP_QSTR_STA_MODE),
601+
MP_OBJ_NEW_SMALL_INT(STATION_MODE)},
602+
{ MP_OBJ_NEW_QSTR(MP_QSTR_AP_MODE),
603+
MP_OBJ_NEW_SMALL_INT(SOFTAP_MODE)},
604+
{ MP_OBJ_NEW_QSTR(MP_QSTR_STA_AP_MODE),
605+
MP_OBJ_NEW_SMALL_INT(STATIONAP_MODE)},
588606
#endif
589607
};
590608

esp8266/qstrdefsport.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ Q(esp)
5656
Q(socket)
5757
Q(connect)
5858
Q(disconnect)
59+
Q(wifi_mode)
5960
Q(phy_mode)
6061
Q(sleep_type)
6162
Q(deepsleep)
@@ -89,6 +90,9 @@ Q(MODE_11N)
8990
Q(SLEEP_NONE)
9091
Q(SLEEP_LIGHT)
9192
Q(SLEEP_MODEM)
93+
Q(STA_MODE)
94+
Q(AP_MODE)
95+
Q(STA_AP_MODE)
9296

9397
// network module
9498
Q(network)

0 commit comments

Comments
 (0)