@@ -105,6 +105,18 @@ STATIC mp_obj_t esp_scan(mp_obj_t cb_in) {
105105}
106106STATIC MP_DEFINE_CONST_FUN_OBJ_1 (esp_scan_obj , esp_scan );
107107
108+ /// \method isconnected()
109+ /// Return True if connected to an AP and an IP address has been assigned,
110+ /// false otherwise.
111+ STATIC mp_obj_t esp_isconnected () {
112+ if (wifi_station_get_connect_status () == STATION_GOT_IP ) {
113+ return mp_const_true ;
114+ }
115+ return mp_const_false ;
116+ }
117+
118+ STATIC MP_DEFINE_CONST_FUN_OBJ_0 (esp_isconnected_obj , esp_isconnected );
119+
108120STATIC const mp_map_elem_t mp_module_network_globals_table [] = {
109121 { MP_OBJ_NEW_QSTR (MP_QSTR___name__ ), MP_OBJ_NEW_QSTR (MP_QSTR_network ) },
110122 // MicroPython "network" module interface requires it to contains classes
@@ -116,6 +128,7 @@ STATIC const mp_map_elem_t mp_module_network_globals_table[] = {
116128 { MP_OBJ_NEW_QSTR (MP_QSTR_disconnect ), (mp_obj_t )& esp_disconnect_obj },
117129 { MP_OBJ_NEW_QSTR (MP_QSTR_status ), (mp_obj_t )& esp_status_obj },
118130 { MP_OBJ_NEW_QSTR (MP_QSTR_scan ), (mp_obj_t )& esp_scan_obj },
131+ { MP_OBJ_NEW_QSTR (MP_QSTR_isconnected ), (mp_obj_t )& esp_isconnected_obj },
119132
120133#if MODNETWORK_INCLUDE_CONSTANTS
121134 { MP_OBJ_NEW_QSTR (MP_QSTR_STAT_IDLE ),
0 commit comments