From 04ffd0dca0db404028da8ef2eb43f82b6e1b24ab Mon Sep 17 00:00:00 2001 From: "Ryan T. Hamilton" Date: Sat, 19 Sep 2020 13:38:04 -0700 Subject: [PATCH 01/10] Add gateway, subnet, and rssi info for current connected AP ap_rssi is a bound method, which I'm not keen on, but it works --- ports/esp32s2/common-hal/wifi/Radio.c | 38 +++++++++++++++++++++++ shared-bindings/wifi/Radio.c | 44 +++++++++++++++++++++++++++ shared-bindings/wifi/Radio.h | 3 ++ 3 files changed, 85 insertions(+) diff --git a/ports/esp32s2/common-hal/wifi/Radio.c b/ports/esp32s2/common-hal/wifi/Radio.c index a0b8b6adc5..4b2e7b64ee 100644 --- a/ports/esp32s2/common-hal/wifi/Radio.c +++ b/ports/esp32s2/common-hal/wifi/Radio.c @@ -147,6 +147,44 @@ wifi_radio_error_t common_hal_wifi_radio_connect(wifi_radio_obj_t *self, uint8_t return WIFI_RADIO_ERROR_NONE; } +mp_obj_t common_hal_wifi_radio_get_ap_rssi(wifi_radio_obj_t *self) { + if (!esp_netif_is_netif_up(self->netif)) { + return mp_const_none; + } + // Make sure the interface is in STA mode + wifi_mode_t if_mode; + esp_wifi_get_mode(&if_mode); + if (if_mode != WIFI_MODE_STA){ + return mp_const_none; + } + + wifi_ap_record_t ap_info; + esp_wifi_sta_get_ap_info(&ap_info); + + mp_obj_t rssi; + rssi = MP_OBJ_NEW_SMALL_INT(ap_info.rssi); + + return rssi; +} + +mp_obj_t common_hal_wifi_radio_get_ipv4_gateway(wifi_radio_obj_t *self) { + if (!esp_netif_is_netif_up(self->netif)) { + return mp_const_none; + } + esp_netif_ip_info_t ip_info; + esp_netif_get_ip_info(self->netif, &ip_info); + return common_hal_ipaddress_new_ipv4address(ip_info.gw.addr); +} + +mp_obj_t common_hal_wifi_radio_get_ipv4_subnet(wifi_radio_obj_t *self) { + if (!esp_netif_is_netif_up(self->netif)) { + return mp_const_none; + } + esp_netif_ip_info_t ip_info; + esp_netif_get_ip_info(self->netif, &ip_info); + return common_hal_ipaddress_new_ipv4address(ip_info.netmask.addr); +} + mp_obj_t common_hal_wifi_radio_get_ipv4_address(wifi_radio_obj_t *self) { if (!esp_netif_is_netif_up(self->netif)) { return mp_const_none; diff --git a/shared-bindings/wifi/Radio.c b/shared-bindings/wifi/Radio.c index 928f21da90..6f1935191d 100644 --- a/shared-bindings/wifi/Radio.c +++ b/shared-bindings/wifi/Radio.c @@ -163,6 +163,47 @@ STATIC mp_obj_t wifi_radio_connect(size_t n_args, const mp_obj_t *pos_args, mp_m } STATIC MP_DEFINE_CONST_FUN_OBJ_KW(wifi_radio_connect_obj, 1, wifi_radio_connect); +//| ap_rssi: int +//| """RSSI of the currently connected AP. Returns none if not connected""" +//| +STATIC mp_obj_t wifi_radio_get_ap_rssi(mp_obj_t self) { + return common_hal_wifi_radio_get_ap_rssi(self); + +} +MP_DEFINE_CONST_FUN_OBJ_1(wifi_radio_get_ap_rssi_obj, wifi_radio_get_ap_rssi); + +//| ipv4_gateway: Optional[ipaddress.IPv4Address] +//| """IP v4 Address of the gateway when connected to an access point. None otherwise.""" +//| +STATIC mp_obj_t wifi_radio_get_ipv4_gateway(mp_obj_t self) { + return common_hal_wifi_radio_get_ipv4_gateway(self); + +} +MP_DEFINE_CONST_FUN_OBJ_1(wifi_radio_get_ipv4_gateway_obj, wifi_radio_get_ipv4_gateway); + +const mp_obj_property_t wifi_radio_ipv4_gateway_obj = { + .base.type = &mp_type_property, + .proxy = { (mp_obj_t)&wifi_radio_get_ipv4_gateway_obj, + (mp_obj_t)&mp_const_none_obj, + (mp_obj_t)&mp_const_none_obj }, +}; + +//| ipv4_subnet: Optional[ipaddress.IPv4Address] +//| """IP v4 Address of the subnet when connected to an access point. None otherwise.""" +//| +STATIC mp_obj_t wifi_radio_get_ipv4_subnet(mp_obj_t self) { + return common_hal_wifi_radio_get_ipv4_subnet(self); + +} +MP_DEFINE_CONST_FUN_OBJ_1(wifi_radio_get_ipv4_subnet_obj, wifi_radio_get_ipv4_subnet); + +const mp_obj_property_t wifi_radio_ipv4_subnet_obj = { + .base.type = &mp_type_property, + .proxy = { (mp_obj_t)&wifi_radio_get_ipv4_subnet_obj, + (mp_obj_t)&mp_const_none_obj, + (mp_obj_t)&mp_const_none_obj }, +}; + //| ipv4_address: Optional[ipaddress.IPv4Address] //| """IP v4 Address of the radio when connected to an access point. None otherwise.""" //| @@ -219,6 +260,9 @@ STATIC const mp_rom_map_elem_t wifi_radio_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_connect), MP_ROM_PTR(&wifi_radio_connect_obj) }, // { MP_ROM_QSTR(MP_QSTR_connect_to_enterprise), MP_ROM_PTR(&wifi_radio_connect_to_enterprise_obj) }, + { MP_ROM_QSTR(MP_QSTR_ap_rssi), MP_ROM_PTR(&wifi_radio_get_ap_rssi_obj) }, + { MP_ROM_QSTR(MP_QSTR_ipv4_gateway), MP_ROM_PTR(&wifi_radio_ipv4_gateway_obj) }, + { MP_ROM_QSTR(MP_QSTR_ipv4_subnet), MP_ROM_PTR(&wifi_radio_ipv4_subnet_obj) }, { MP_ROM_QSTR(MP_QSTR_ipv4_address), MP_ROM_PTR(&wifi_radio_ipv4_address_obj) }, // { MP_ROM_QSTR(MP_QSTR_access_point_active), MP_ROM_PTR(&wifi_radio_access_point_active_obj) }, diff --git a/shared-bindings/wifi/Radio.h b/shared-bindings/wifi/Radio.h index b5341d51c9..3c8ecbebd1 100644 --- a/shared-bindings/wifi/Radio.h +++ b/shared-bindings/wifi/Radio.h @@ -53,6 +53,9 @@ extern void common_hal_wifi_radio_stop_scanning_networks(wifi_radio_obj_t *self) extern wifi_radio_error_t common_hal_wifi_radio_connect(wifi_radio_obj_t *self, uint8_t* ssid, size_t ssid_len, uint8_t* password, size_t password_len, uint8_t channel, mp_float_t timeout, uint8_t* bssid, size_t bssid_len); +extern mp_obj_t common_hal_wifi_radio_get_ap_rssi(wifi_radio_obj_t *self); +extern mp_obj_t common_hal_wifi_radio_get_ipv4_gateway(wifi_radio_obj_t *self); +extern mp_obj_t common_hal_wifi_radio_get_ipv4_subnet(wifi_radio_obj_t *self); extern mp_obj_t common_hal_wifi_radio_get_ipv4_address(wifi_radio_obj_t *self); extern mp_int_t common_hal_wifi_radio_ping(wifi_radio_obj_t *self, mp_obj_t ip_address, mp_float_t timeout); From bc8863a3c788c7a44c164e35c71a7ec83cf29823 Mon Sep 17 00:00:00 2001 From: "Ryan T. Hamilton" Date: Sat, 19 Sep 2020 21:04:07 -0700 Subject: [PATCH 02/10] Simplify now that I have it working still need to figure out the bound method business --- ports/esp32s2/common-hal/wifi/Radio.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/ports/esp32s2/common-hal/wifi/Radio.c b/ports/esp32s2/common-hal/wifi/Radio.c index 4b2e7b64ee..5bc69eab40 100644 --- a/ports/esp32s2/common-hal/wifi/Radio.c +++ b/ports/esp32s2/common-hal/wifi/Radio.c @@ -151,6 +151,7 @@ mp_obj_t common_hal_wifi_radio_get_ap_rssi(wifi_radio_obj_t *self) { if (!esp_netif_is_netif_up(self->netif)) { return mp_const_none; } + // Make sure the interface is in STA mode wifi_mode_t if_mode; esp_wifi_get_mode(&if_mode); @@ -161,10 +162,7 @@ mp_obj_t common_hal_wifi_radio_get_ap_rssi(wifi_radio_obj_t *self) { wifi_ap_record_t ap_info; esp_wifi_sta_get_ap_info(&ap_info); - mp_obj_t rssi; - rssi = MP_OBJ_NEW_SMALL_INT(ap_info.rssi); - - return rssi; + return MP_OBJ_NEW_SMALL_INT(ap_info.rssi); } mp_obj_t common_hal_wifi_radio_get_ipv4_gateway(wifi_radio_obj_t *self) { From 2fa269ccbc981c00eaf4f0bf6d7f5eaa52db4d08 Mon Sep 17 00:00:00 2001 From: "Ryan T. Hamilton" Date: Mon, 21 Sep 2020 20:56:03 -0700 Subject: [PATCH 03/10] Additional error handling --- ports/esp32s2/common-hal/wifi/Radio.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/ports/esp32s2/common-hal/wifi/Radio.c b/ports/esp32s2/common-hal/wifi/Radio.c index 5bc69eab40..44f0fe2cf1 100644 --- a/ports/esp32s2/common-hal/wifi/Radio.c +++ b/ports/esp32s2/common-hal/wifi/Radio.c @@ -160,9 +160,15 @@ mp_obj_t common_hal_wifi_radio_get_ap_rssi(wifi_radio_obj_t *self) { } wifi_ap_record_t ap_info; - esp_wifi_sta_get_ap_info(&ap_info); - - return MP_OBJ_NEW_SMALL_INT(ap_info.rssi); + // From esp_wifi.h, the possible return values (typos theirs): + // ESP_OK: succeed + // ESP_ERR_WIFI_CONN: The station interface don't initialized + // ESP_ERR_WIFI_NOT_CONNECT: The station is in disconnect status + if (esp_wifi_sta_get_ap_info(&ap_info) != ESP_OK){ + return mp_const_none; + } else { + return mp_obj_new_int(ap_info.rssi); + } } mp_obj_t common_hal_wifi_radio_get_ipv4_gateway(wifi_radio_obj_t *self) { From a77966a73640a8699d116e0f484199338c4477e9 Mon Sep 17 00:00:00 2001 From: "Ryan T. Hamilton" Date: Mon, 21 Sep 2020 21:36:46 -0700 Subject: [PATCH 04/10] Try to reuse/share existing objects --- ports/esp32s2/common-hal/wifi/Radio.c | 24 +++++++++--------------- ports/esp32s2/common-hal/wifi/Radio.h | 2 ++ 2 files changed, 11 insertions(+), 15 deletions(-) diff --git a/ports/esp32s2/common-hal/wifi/Radio.c b/ports/esp32s2/common-hal/wifi/Radio.c index 44f0fe2cf1..ab61778595 100644 --- a/ports/esp32s2/common-hal/wifi/Radio.c +++ b/ports/esp32s2/common-hal/wifi/Radio.c @@ -153,21 +153,18 @@ mp_obj_t common_hal_wifi_radio_get_ap_rssi(wifi_radio_obj_t *self) { } // Make sure the interface is in STA mode - wifi_mode_t if_mode; - esp_wifi_get_mode(&if_mode); - if (if_mode != WIFI_MODE_STA){ + if (self->sta_mode){ return mp_const_none; } - wifi_ap_record_t ap_info; // From esp_wifi.h, the possible return values (typos theirs): // ESP_OK: succeed // ESP_ERR_WIFI_CONN: The station interface don't initialized // ESP_ERR_WIFI_NOT_CONNECT: The station is in disconnect status - if (esp_wifi_sta_get_ap_info(&ap_info) != ESP_OK){ + if (esp_wifi_sta_get_ap_info(&self->ap_info) != ESP_OK){ return mp_const_none; } else { - return mp_obj_new_int(ap_info.rssi); + return mp_obj_new_int(self->ap_info.rssi); } } @@ -175,27 +172,24 @@ mp_obj_t common_hal_wifi_radio_get_ipv4_gateway(wifi_radio_obj_t *self) { if (!esp_netif_is_netif_up(self->netif)) { return mp_const_none; } - esp_netif_ip_info_t ip_info; - esp_netif_get_ip_info(self->netif, &ip_info); - return common_hal_ipaddress_new_ipv4address(ip_info.gw.addr); + esp_netif_get_ip_info(self->netif, &self->ip_info); + return common_hal_ipaddress_new_ipv4address(self->ip_info.gw.addr); } mp_obj_t common_hal_wifi_radio_get_ipv4_subnet(wifi_radio_obj_t *self) { if (!esp_netif_is_netif_up(self->netif)) { return mp_const_none; } - esp_netif_ip_info_t ip_info; - esp_netif_get_ip_info(self->netif, &ip_info); - return common_hal_ipaddress_new_ipv4address(ip_info.netmask.addr); + esp_netif_get_ip_info(self->netif, &self->ip_info); + return common_hal_ipaddress_new_ipv4address(self->ip_info.netmask.addr); } mp_obj_t common_hal_wifi_radio_get_ipv4_address(wifi_radio_obj_t *self) { if (!esp_netif_is_netif_up(self->netif)) { return mp_const_none; } - esp_netif_ip_info_t ip_info; - esp_netif_get_ip_info(self->netif, &ip_info); - return common_hal_ipaddress_new_ipv4address(ip_info.ip.addr); + esp_netif_get_ip_info(self->netif, &self->ip_info); + return common_hal_ipaddress_new_ipv4address(self->ip_info.ip.addr); } mp_int_t common_hal_wifi_radio_ping(wifi_radio_obj_t *self, mp_obj_t ip_address, mp_float_t timeout) { diff --git a/ports/esp32s2/common-hal/wifi/Radio.h b/ports/esp32s2/common-hal/wifi/Radio.h index 205aef1761..ddcd9dc0d0 100644 --- a/ports/esp32s2/common-hal/wifi/Radio.h +++ b/ports/esp32s2/common-hal/wifi/Radio.h @@ -46,6 +46,8 @@ typedef struct { StaticEventGroup_t event_group; EventGroupHandle_t event_group_handle; wifi_config_t sta_config; + wifi_ap_record_t ap_info; + esp_netif_ip_info_t ip_info; esp_netif_t *netif; bool started; bool ap_mode; From deefeecb454931a1476be0f852b78dfea0975d92 Mon Sep 17 00:00:00 2001 From: "Ryan T. Hamilton" Date: Sat, 26 Sep 2020 14:27:42 -0700 Subject: [PATCH 05/10] Fix ap_rssi bound_method Forgot to make it a property! --- shared-bindings/wifi/Radio.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/shared-bindings/wifi/Radio.c b/shared-bindings/wifi/Radio.c index 6f1935191d..6c4e6a4f65 100644 --- a/shared-bindings/wifi/Radio.c +++ b/shared-bindings/wifi/Radio.c @@ -172,6 +172,13 @@ STATIC mp_obj_t wifi_radio_get_ap_rssi(mp_obj_t self) { } MP_DEFINE_CONST_FUN_OBJ_1(wifi_radio_get_ap_rssi_obj, wifi_radio_get_ap_rssi); +const mp_obj_property_t wifi_radio_ap_rssi_obj = { + .base.type = &mp_type_property, + .proxy = { (mp_obj_t)&wifi_radio_get_ap_rssi_obj, + (mp_obj_t)&mp_const_none_obj, + (mp_obj_t)&mp_const_none_obj }, +}; + //| ipv4_gateway: Optional[ipaddress.IPv4Address] //| """IP v4 Address of the gateway when connected to an access point. None otherwise.""" //| @@ -260,7 +267,7 @@ STATIC const mp_rom_map_elem_t wifi_radio_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_connect), MP_ROM_PTR(&wifi_radio_connect_obj) }, // { MP_ROM_QSTR(MP_QSTR_connect_to_enterprise), MP_ROM_PTR(&wifi_radio_connect_to_enterprise_obj) }, - { MP_ROM_QSTR(MP_QSTR_ap_rssi), MP_ROM_PTR(&wifi_radio_get_ap_rssi_obj) }, + { MP_ROM_QSTR(MP_QSTR_ap_rssi), MP_ROM_PTR(&wifi_radio_ap_rssi_obj) }, { MP_ROM_QSTR(MP_QSTR_ipv4_gateway), MP_ROM_PTR(&wifi_radio_ipv4_gateway_obj) }, { MP_ROM_QSTR(MP_QSTR_ipv4_subnet), MP_ROM_PTR(&wifi_radio_ipv4_subnet_obj) }, { MP_ROM_QSTR(MP_QSTR_ipv4_address), MP_ROM_PTR(&wifi_radio_ipv4_address_obj) }, From 66d55738c1315b223d3e5ed6bc710f8b1e443836 Mon Sep 17 00:00:00 2001 From: "Ryan T. Hamilton" Date: Mon, 28 Sep 2020 16:49:20 -0700 Subject: [PATCH 06/10] Enable DNS info --- ports/esp32s2/common-hal/wifi/Radio.c | 14 ++++++++++++++ ports/esp32s2/common-hal/wifi/Radio.h | 1 + shared-bindings/wifi/Radio.c | 17 +++++++++++++++++ shared-bindings/wifi/Radio.h | 1 + 4 files changed, 33 insertions(+) diff --git a/ports/esp32s2/common-hal/wifi/Radio.c b/ports/esp32s2/common-hal/wifi/Radio.c index ab61778595..0184793a1a 100644 --- a/ports/esp32s2/common-hal/wifi/Radio.c +++ b/ports/esp32s2/common-hal/wifi/Radio.c @@ -192,6 +192,20 @@ mp_obj_t common_hal_wifi_radio_get_ipv4_address(wifi_radio_obj_t *self) { return common_hal_ipaddress_new_ipv4address(self->ip_info.ip.addr); } +mp_obj_t common_hal_wifi_radio_get_ipv4_dns(wifi_radio_obj_t *self) { + if (!esp_netif_is_netif_up(self->netif)) { + return mp_const_none; + } + + esp_netif_get_dns_info(self->netif, ESP_NETIF_DNS_MAIN, &self->dns_info); + + // dns_info is of type esp_netif_dns_info_t, which is just ever so slightly + // different than esp_netif_ip_info_t used for + // common_hal_wifi_radio_get_ipv4_address (includes both ipv4 and 6), + // so some extra jumping is required to get to the actual address + return common_hal_ipaddress_new_ipv4address(self->dns_info.ip.u_addr.ip4.addr); +} + mp_int_t common_hal_wifi_radio_ping(wifi_radio_obj_t *self, mp_obj_t ip_address, mp_float_t timeout) { esp_ping_config_t ping_config = ESP_PING_DEFAULT_CONFIG(); ipaddress_ipaddress_to_esp_idf(ip_address, &ping_config.target_addr); diff --git a/ports/esp32s2/common-hal/wifi/Radio.h b/ports/esp32s2/common-hal/wifi/Radio.h index ddcd9dc0d0..7c0cb996d7 100644 --- a/ports/esp32s2/common-hal/wifi/Radio.h +++ b/ports/esp32s2/common-hal/wifi/Radio.h @@ -48,6 +48,7 @@ typedef struct { wifi_config_t sta_config; wifi_ap_record_t ap_info; esp_netif_ip_info_t ip_info; + esp_netif_dns_info_t dns_info; esp_netif_t *netif; bool started; bool ap_mode; diff --git a/shared-bindings/wifi/Radio.c b/shared-bindings/wifi/Radio.c index 6c4e6a4f65..8c556aafe6 100644 --- a/shared-bindings/wifi/Radio.c +++ b/shared-bindings/wifi/Radio.c @@ -227,6 +227,22 @@ const mp_obj_property_t wifi_radio_ipv4_address_obj = { (mp_obj_t)&mp_const_none_obj }, }; +//| ipv4_dns: Optional[ipaddress.IPv4Address] +//| """IP v4 Address of the DNS server in use when connected to an access point. None otherwise.""" +//| +STATIC mp_obj_t wifi_radio_get_ipv4_dns(mp_obj_t self) { + return common_hal_wifi_radio_get_ipv4_dns(self); + +} +MP_DEFINE_CONST_FUN_OBJ_1(wifi_radio_get_ipv4_dns_obj, wifi_radio_get_ipv4_dns); + +const mp_obj_property_t wifi_radio_ipv4_dns_obj = { + .base.type = &mp_type_property, + .proxy = { (mp_obj_t)&wifi_radio_get_ipv4_dns_obj, + (mp_obj_t)&mp_const_none_obj, + (mp_obj_t)&mp_const_none_obj }, +}; + //| def ping(self, ip, *, timeout: float = 0.5) -> float: //| """Ping an IP to test connectivity. Returns echo time in seconds. //| Returns None when it times out.""" @@ -268,6 +284,7 @@ STATIC const mp_rom_map_elem_t wifi_radio_locals_dict_table[] = { // { MP_ROM_QSTR(MP_QSTR_connect_to_enterprise), MP_ROM_PTR(&wifi_radio_connect_to_enterprise_obj) }, { MP_ROM_QSTR(MP_QSTR_ap_rssi), MP_ROM_PTR(&wifi_radio_ap_rssi_obj) }, + { MP_ROM_QSTR(MP_QSTR_ipv4_dns), MP_ROM_PTR(&wifi_radio_ipv4_dns_obj) }, { MP_ROM_QSTR(MP_QSTR_ipv4_gateway), MP_ROM_PTR(&wifi_radio_ipv4_gateway_obj) }, { MP_ROM_QSTR(MP_QSTR_ipv4_subnet), MP_ROM_PTR(&wifi_radio_ipv4_subnet_obj) }, { MP_ROM_QSTR(MP_QSTR_ipv4_address), MP_ROM_PTR(&wifi_radio_ipv4_address_obj) }, diff --git a/shared-bindings/wifi/Radio.h b/shared-bindings/wifi/Radio.h index 3c8ecbebd1..fd0807a86e 100644 --- a/shared-bindings/wifi/Radio.h +++ b/shared-bindings/wifi/Radio.h @@ -54,6 +54,7 @@ extern void common_hal_wifi_radio_stop_scanning_networks(wifi_radio_obj_t *self) extern wifi_radio_error_t common_hal_wifi_radio_connect(wifi_radio_obj_t *self, uint8_t* ssid, size_t ssid_len, uint8_t* password, size_t password_len, uint8_t channel, mp_float_t timeout, uint8_t* bssid, size_t bssid_len); extern mp_obj_t common_hal_wifi_radio_get_ap_rssi(wifi_radio_obj_t *self); +extern mp_obj_t common_hal_wifi_radio_get_ipv4_dns(wifi_radio_obj_t *self); extern mp_obj_t common_hal_wifi_radio_get_ipv4_gateway(wifi_radio_obj_t *self); extern mp_obj_t common_hal_wifi_radio_get_ipv4_subnet(wifi_radio_obj_t *self); extern mp_obj_t common_hal_wifi_radio_get_ipv4_address(wifi_radio_obj_t *self); From 2a4a244245e3e03bfb89dcc49e56e83b71291bb2 Mon Sep 17 00:00:00 2001 From: "Ryan T. Hamilton" Date: Mon, 28 Sep 2020 17:25:09 -0700 Subject: [PATCH 07/10] Add ap_ssid and ap_bssid --- ports/esp32s2/common-hal/wifi/Radio.c | 39 +++++++++++++++++++++++++-- shared-bindings/wifi/Radio.c | 34 +++++++++++++++++++++++ shared-bindings/wifi/Radio.h | 2 ++ 3 files changed, 73 insertions(+), 2 deletions(-) diff --git a/ports/esp32s2/common-hal/wifi/Radio.c b/ports/esp32s2/common-hal/wifi/Radio.c index 0184793a1a..019e8316c1 100644 --- a/ports/esp32s2/common-hal/wifi/Radio.c +++ b/ports/esp32s2/common-hal/wifi/Radio.c @@ -38,6 +38,8 @@ #include "esp-idf/components/esp_wifi/include/esp_wifi.h" #include "esp-idf/components/lwip/include/apps/ping/ping_sock.h" +#define MAC_ADDRESS_LENGTH 6 + static void start_station(wifi_radio_obj_t *self) { if (self->sta_mode) { return; @@ -73,8 +75,6 @@ void common_hal_wifi_radio_set_enabled(wifi_radio_obj_t *self, bool enabled) { } } -#define MAC_ADDRESS_LENGTH 6 - mp_obj_t common_hal_wifi_radio_get_mac_address(wifi_radio_obj_t *self) { uint8_t mac[MAC_ADDRESS_LENGTH]; esp_wifi_get_mac(ESP_IF_WIFI_STA, mac); @@ -168,6 +168,41 @@ mp_obj_t common_hal_wifi_radio_get_ap_rssi(wifi_radio_obj_t *self) { } } +mp_obj_t common_hal_wifi_radio_get_ap_ssid(wifi_radio_obj_t *self) { + if (!esp_netif_is_netif_up(self->netif)) { + return mp_const_none; + } + + // Make sure the interface is in STA mode + if (self->sta_mode){ + return mp_const_none; + } + + if (esp_wifi_sta_get_ap_info(&self->ap_info) != ESP_OK){ + return mp_const_none; + } else { + const char* cstr = (const char*) self->ap_info.ssid; + return mp_obj_new_str(cstr, strlen(cstr)); + } +} + +mp_obj_t common_hal_wifi_radio_get_ap_bssid(wifi_radio_obj_t *self) { + if (!esp_netif_is_netif_up(self->netif)) { + return mp_const_none; + } + + // Make sure the interface is in STA mode + if (self->sta_mode){ + return mp_const_none; + } + + if (esp_wifi_sta_get_ap_info(&self->ap_info) != ESP_OK){ + return mp_const_none; + } else { + return mp_obj_new_bytes(self->ap_info.bssid, MAC_ADDRESS_LENGTH); + } +} + mp_obj_t common_hal_wifi_radio_get_ipv4_gateway(wifi_radio_obj_t *self) { if (!esp_netif_is_netif_up(self->netif)) { return mp_const_none; diff --git a/shared-bindings/wifi/Radio.c b/shared-bindings/wifi/Radio.c index 8c556aafe6..96abadf6ff 100644 --- a/shared-bindings/wifi/Radio.c +++ b/shared-bindings/wifi/Radio.c @@ -179,6 +179,38 @@ const mp_obj_property_t wifi_radio_ap_rssi_obj = { (mp_obj_t)&mp_const_none_obj }, }; +//| ap_ssid: int +//| """SSID of the currently connected AP. Returns none if not connected""" +//| +STATIC mp_obj_t wifi_radio_get_ap_ssid(mp_obj_t self) { + return common_hal_wifi_radio_get_ap_ssid(self); + +} +MP_DEFINE_CONST_FUN_OBJ_1(wifi_radio_get_ap_ssid_obj, wifi_radio_get_ap_ssid); + +const mp_obj_property_t wifi_radio_ap_ssid_obj = { + .base.type = &mp_type_property, + .proxy = { (mp_obj_t)&wifi_radio_get_ap_ssid_obj, + (mp_obj_t)&mp_const_none_obj, + (mp_obj_t)&mp_const_none_obj }, +}; + +//| ap_bssid: int +//| """BSSID (usually MAC) of the currently connected AP. Returns none if not connected""" +//| +STATIC mp_obj_t wifi_radio_get_ap_bssid(mp_obj_t self) { + return common_hal_wifi_radio_get_ap_bssid(self); + +} +MP_DEFINE_CONST_FUN_OBJ_1(wifi_radio_get_ap_bssid_obj, wifi_radio_get_ap_bssid); + +const mp_obj_property_t wifi_radio_ap_bssid_obj = { + .base.type = &mp_type_property, + .proxy = { (mp_obj_t)&wifi_radio_get_ap_bssid_obj, + (mp_obj_t)&mp_const_none_obj, + (mp_obj_t)&mp_const_none_obj }, +}; + //| ipv4_gateway: Optional[ipaddress.IPv4Address] //| """IP v4 Address of the gateway when connected to an access point. None otherwise.""" //| @@ -284,6 +316,8 @@ STATIC const mp_rom_map_elem_t wifi_radio_locals_dict_table[] = { // { MP_ROM_QSTR(MP_QSTR_connect_to_enterprise), MP_ROM_PTR(&wifi_radio_connect_to_enterprise_obj) }, { MP_ROM_QSTR(MP_QSTR_ap_rssi), MP_ROM_PTR(&wifi_radio_ap_rssi_obj) }, + { MP_ROM_QSTR(MP_QSTR_ap_ssid), MP_ROM_PTR(&wifi_radio_ap_ssid_obj) }, + { MP_ROM_QSTR(MP_QSTR_ap_bssid), MP_ROM_PTR(&wifi_radio_ap_bssid_obj) }, { MP_ROM_QSTR(MP_QSTR_ipv4_dns), MP_ROM_PTR(&wifi_radio_ipv4_dns_obj) }, { MP_ROM_QSTR(MP_QSTR_ipv4_gateway), MP_ROM_PTR(&wifi_radio_ipv4_gateway_obj) }, { MP_ROM_QSTR(MP_QSTR_ipv4_subnet), MP_ROM_PTR(&wifi_radio_ipv4_subnet_obj) }, diff --git a/shared-bindings/wifi/Radio.h b/shared-bindings/wifi/Radio.h index fd0807a86e..bf30ac3405 100644 --- a/shared-bindings/wifi/Radio.h +++ b/shared-bindings/wifi/Radio.h @@ -54,6 +54,8 @@ extern void common_hal_wifi_radio_stop_scanning_networks(wifi_radio_obj_t *self) extern wifi_radio_error_t common_hal_wifi_radio_connect(wifi_radio_obj_t *self, uint8_t* ssid, size_t ssid_len, uint8_t* password, size_t password_len, uint8_t channel, mp_float_t timeout, uint8_t* bssid, size_t bssid_len); extern mp_obj_t common_hal_wifi_radio_get_ap_rssi(wifi_radio_obj_t *self); +extern mp_obj_t common_hal_wifi_radio_get_ap_ssid(wifi_radio_obj_t *self); +extern mp_obj_t common_hal_wifi_radio_get_ap_bssid(wifi_radio_obj_t *self); extern mp_obj_t common_hal_wifi_radio_get_ipv4_dns(wifi_radio_obj_t *self); extern mp_obj_t common_hal_wifi_radio_get_ipv4_gateway(wifi_radio_obj_t *self); extern mp_obj_t common_hal_wifi_radio_get_ipv4_subnet(wifi_radio_obj_t *self); From b336039aab03bd9f609bad0c211981961b6685d2 Mon Sep 17 00:00:00 2001 From: "Ryan T. Hamilton" Date: Thu, 15 Oct 2020 23:18:30 -0700 Subject: [PATCH 08/10] Disable the long way and return an ap_info object still needs work and cleanup --- ports/esp32s2/common-hal/wifi/Radio.c | 83 +++++++++++++++++---------- ports/esp32s2/common-hal/wifi/Radio.h | 2 + shared-bindings/wifi/Radio.c | 73 ++++++++++++++--------- shared-bindings/wifi/Radio.h | 5 +- 4 files changed, 104 insertions(+), 59 deletions(-) diff --git a/ports/esp32s2/common-hal/wifi/Radio.c b/ports/esp32s2/common-hal/wifi/Radio.c index 13bcccc809..b1f9e67e05 100644 --- a/ports/esp32s2/common-hal/wifi/Radio.c +++ b/ports/esp32s2/common-hal/wifi/Radio.c @@ -25,6 +25,7 @@ */ #include "shared-bindings/wifi/Radio.h" +#include "shared-bindings/wifi/Network.h" #include @@ -149,6 +150,30 @@ wifi_radio_error_t common_hal_wifi_radio_connect(wifi_radio_obj_t *self, uint8_t return WIFI_RADIO_ERROR_NONE; } +mp_obj_t common_hal_wifi_radio_get_ap_info(wifi_radio_obj_t *self) { + if (!esp_netif_is_netif_up(self->netif)) { + return mp_const_none; + } + + // Make sure the interface is in STA mode + if (self->sta_mode){ + return mp_const_none; + } + + wifi_network_obj_t *apnet = m_new_obj(wifi_network_obj_t); + apnet->base.type = &wifi_network_type; + // From esp_wifi.h, the possible return values (typos theirs): + // ESP_OK: succeed + // ESP_ERR_WIFI_CONN: The station interface don't initialized + // ESP_ERR_WIFI_NOT_CONNECT: The station is in disconnect status + if (esp_wifi_sta_get_ap_info(&self->apnet.record) != ESP_OK){ + return mp_const_none; + } else { + memcpy(&apnet->record, &self->apnet.record, sizeof(wifi_ap_record_t)); + return MP_OBJ_FROM_PTR(apnet); + } +} + mp_obj_t common_hal_wifi_radio_get_ap_rssi(wifi_radio_obj_t *self) { if (!esp_netif_is_netif_up(self->netif)) { return mp_const_none; @@ -170,40 +195,40 @@ mp_obj_t common_hal_wifi_radio_get_ap_rssi(wifi_radio_obj_t *self) { } } -mp_obj_t common_hal_wifi_radio_get_ap_ssid(wifi_radio_obj_t *self) { - if (!esp_netif_is_netif_up(self->netif)) { - return mp_const_none; - } +// mp_obj_t common_hal_wifi_radio_get_ap_ssid(wifi_radio_obj_t *self) { +// if (!esp_netif_is_netif_up(self->netif)) { +// return mp_const_none; +// } - // Make sure the interface is in STA mode - if (self->sta_mode){ - return mp_const_none; - } +// // Make sure the interface is in STA mode +// if (self->sta_mode){ +// return mp_const_none; +// } - if (esp_wifi_sta_get_ap_info(&self->ap_info) != ESP_OK){ - return mp_const_none; - } else { - const char* cstr = (const char*) self->ap_info.ssid; - return mp_obj_new_str(cstr, strlen(cstr)); - } -} +// if (esp_wifi_sta_get_ap_info(&self->ap_info) != ESP_OK){ +// return mp_const_none; +// } else { +// const char* cstr = (const char*) self->ap_info.ssid; +// return mp_obj_new_str(cstr, strlen(cstr)); +// } +// } -mp_obj_t common_hal_wifi_radio_get_ap_bssid(wifi_radio_obj_t *self) { - if (!esp_netif_is_netif_up(self->netif)) { - return mp_const_none; - } +// mp_obj_t common_hal_wifi_radio_get_ap_bssid(wifi_radio_obj_t *self) { +// if (!esp_netif_is_netif_up(self->netif)) { +// return mp_const_none; +// } - // Make sure the interface is in STA mode - if (self->sta_mode){ - return mp_const_none; - } +// // Make sure the interface is in STA mode +// if (self->sta_mode){ +// return mp_const_none; +// } - if (esp_wifi_sta_get_ap_info(&self->ap_info) != ESP_OK){ - return mp_const_none; - } else { - return mp_obj_new_bytes(self->ap_info.bssid, MAC_ADDRESS_LENGTH); - } -} +// if (esp_wifi_sta_get_ap_info(&self->ap_info) != ESP_OK){ +// return mp_const_none; +// } else { +// return mp_obj_new_bytes(self->ap_info.bssid, MAC_ADDRESS_LENGTH); +// } +// } mp_obj_t common_hal_wifi_radio_get_ipv4_gateway(wifi_radio_obj_t *self) { if (!esp_netif_is_netif_up(self->netif)) { diff --git a/ports/esp32s2/common-hal/wifi/Radio.h b/ports/esp32s2/common-hal/wifi/Radio.h index 272c3a62e9..f441096f7d 100644 --- a/ports/esp32s2/common-hal/wifi/Radio.h +++ b/ports/esp32s2/common-hal/wifi/Radio.h @@ -32,6 +32,7 @@ #include "components/esp_event/include/esp_event.h" #include "shared-bindings/wifi/ScannedNetworks.h" +#include "shared-bindings/wifi/Network.h" // Event bits for the Radio event group. #define WIFI_SCAN_DONE_BIT BIT0 @@ -47,6 +48,7 @@ typedef struct { EventGroupHandle_t event_group_handle; wifi_config_t sta_config; wifi_ap_record_t ap_info; + wifi_network_obj_t apnet; esp_netif_ip_info_t ip_info; esp_netif_dns_info_t dns_info; esp_netif_t *netif; diff --git a/shared-bindings/wifi/Radio.c b/shared-bindings/wifi/Radio.c index 96abadf6ff..d755327694 100644 --- a/shared-bindings/wifi/Radio.c +++ b/shared-bindings/wifi/Radio.c @@ -179,37 +179,37 @@ const mp_obj_property_t wifi_radio_ap_rssi_obj = { (mp_obj_t)&mp_const_none_obj }, }; -//| ap_ssid: int -//| """SSID of the currently connected AP. Returns none if not connected""" -//| -STATIC mp_obj_t wifi_radio_get_ap_ssid(mp_obj_t self) { - return common_hal_wifi_radio_get_ap_ssid(self); +// //| ap_ssid: int +// //| """SSID of the currently connected AP. Returns none if not connected""" +// //| +// STATIC mp_obj_t wifi_radio_get_ap_ssid(mp_obj_t self) { +// return common_hal_wifi_radio_get_ap_ssid(self); -} -MP_DEFINE_CONST_FUN_OBJ_1(wifi_radio_get_ap_ssid_obj, wifi_radio_get_ap_ssid); +// } +// MP_DEFINE_CONST_FUN_OBJ_1(wifi_radio_get_ap_ssid_obj, wifi_radio_get_ap_ssid); -const mp_obj_property_t wifi_radio_ap_ssid_obj = { - .base.type = &mp_type_property, - .proxy = { (mp_obj_t)&wifi_radio_get_ap_ssid_obj, - (mp_obj_t)&mp_const_none_obj, - (mp_obj_t)&mp_const_none_obj }, -}; +// const mp_obj_property_t wifi_radio_ap_ssid_obj = { +// .base.type = &mp_type_property, +// .proxy = { (mp_obj_t)&wifi_radio_get_ap_ssid_obj, +// (mp_obj_t)&mp_const_none_obj, +// (mp_obj_t)&mp_const_none_obj }, +// }; -//| ap_bssid: int -//| """BSSID (usually MAC) of the currently connected AP. Returns none if not connected""" -//| -STATIC mp_obj_t wifi_radio_get_ap_bssid(mp_obj_t self) { - return common_hal_wifi_radio_get_ap_bssid(self); +// //| ap_bssid: int +// //| """BSSID (usually MAC) of the currently connected AP. Returns none if not connected""" +// //| +// STATIC mp_obj_t wifi_radio_get_ap_bssid(mp_obj_t self) { +// return common_hal_wifi_radio_get_ap_bssid(self); -} -MP_DEFINE_CONST_FUN_OBJ_1(wifi_radio_get_ap_bssid_obj, wifi_radio_get_ap_bssid); +// } +// MP_DEFINE_CONST_FUN_OBJ_1(wifi_radio_get_ap_bssid_obj, wifi_radio_get_ap_bssid); -const mp_obj_property_t wifi_radio_ap_bssid_obj = { - .base.type = &mp_type_property, - .proxy = { (mp_obj_t)&wifi_radio_get_ap_bssid_obj, - (mp_obj_t)&mp_const_none_obj, - (mp_obj_t)&mp_const_none_obj }, -}; +// const mp_obj_property_t wifi_radio_ap_bssid_obj = { +// .base.type = &mp_type_property, +// .proxy = { (mp_obj_t)&wifi_radio_get_ap_bssid_obj, +// (mp_obj_t)&mp_const_none_obj, +// (mp_obj_t)&mp_const_none_obj }, +// }; //| ipv4_gateway: Optional[ipaddress.IPv4Address] //| """IP v4 Address of the gateway when connected to an access point. None otherwise.""" @@ -275,6 +275,22 @@ const mp_obj_property_t wifi_radio_ipv4_dns_obj = { (mp_obj_t)&mp_const_none_obj }, }; +//| ap_info: Optional[Network] +//| """None otherwise.""" +//| +STATIC mp_obj_t wifi_radio_get_ap_info(mp_obj_t self) { + return common_hal_wifi_radio_get_ap_info(self); + +} +MP_DEFINE_CONST_FUN_OBJ_1(wifi_radio_get_ap_info_obj, wifi_radio_get_ap_info); + +const mp_obj_property_t wifi_radio_ap_info_obj = { + .base.type = &mp_type_property, + .proxy = { (mp_obj_t)&wifi_radio_get_ap_info_obj, + (mp_obj_t)&mp_const_none_obj, + (mp_obj_t)&mp_const_none_obj }, +}; + //| def ping(self, ip, *, timeout: float = 0.5) -> float: //| """Ping an IP to test connectivity. Returns echo time in seconds. //| Returns None when it times out.""" @@ -315,9 +331,10 @@ STATIC const mp_rom_map_elem_t wifi_radio_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_connect), MP_ROM_PTR(&wifi_radio_connect_obj) }, // { MP_ROM_QSTR(MP_QSTR_connect_to_enterprise), MP_ROM_PTR(&wifi_radio_connect_to_enterprise_obj) }, + { MP_ROM_QSTR(MP_QSTR_ap_info), MP_ROM_PTR(&wifi_radio_ap_info_obj) }, { MP_ROM_QSTR(MP_QSTR_ap_rssi), MP_ROM_PTR(&wifi_radio_ap_rssi_obj) }, - { MP_ROM_QSTR(MP_QSTR_ap_ssid), MP_ROM_PTR(&wifi_radio_ap_ssid_obj) }, - { MP_ROM_QSTR(MP_QSTR_ap_bssid), MP_ROM_PTR(&wifi_radio_ap_bssid_obj) }, + // { MP_ROM_QSTR(MP_QSTR_ap_ssid), MP_ROM_PTR(&wifi_radio_ap_ssid_obj) }, + // { MP_ROM_QSTR(MP_QSTR_ap_bssid), MP_ROM_PTR(&wifi_radio_ap_bssid_obj) }, { MP_ROM_QSTR(MP_QSTR_ipv4_dns), MP_ROM_PTR(&wifi_radio_ipv4_dns_obj) }, { MP_ROM_QSTR(MP_QSTR_ipv4_gateway), MP_ROM_PTR(&wifi_radio_ipv4_gateway_obj) }, { MP_ROM_QSTR(MP_QSTR_ipv4_subnet), MP_ROM_PTR(&wifi_radio_ipv4_subnet_obj) }, diff --git a/shared-bindings/wifi/Radio.h b/shared-bindings/wifi/Radio.h index bf30ac3405..6dca40c56b 100644 --- a/shared-bindings/wifi/Radio.h +++ b/shared-bindings/wifi/Radio.h @@ -53,9 +53,10 @@ extern void common_hal_wifi_radio_stop_scanning_networks(wifi_radio_obj_t *self) extern wifi_radio_error_t common_hal_wifi_radio_connect(wifi_radio_obj_t *self, uint8_t* ssid, size_t ssid_len, uint8_t* password, size_t password_len, uint8_t channel, mp_float_t timeout, uint8_t* bssid, size_t bssid_len); +extern mp_obj_t common_hal_wifi_radio_get_ap_info(wifi_radio_obj_t *self); extern mp_obj_t common_hal_wifi_radio_get_ap_rssi(wifi_radio_obj_t *self); -extern mp_obj_t common_hal_wifi_radio_get_ap_ssid(wifi_radio_obj_t *self); -extern mp_obj_t common_hal_wifi_radio_get_ap_bssid(wifi_radio_obj_t *self); +// extern mp_obj_t common_hal_wifi_radio_get_ap_ssid(wifi_radio_obj_t *self); +// extern mp_obj_t common_hal_wifi_radio_get_ap_bssid(wifi_radio_obj_t *self); extern mp_obj_t common_hal_wifi_radio_get_ipv4_dns(wifi_radio_obj_t *self); extern mp_obj_t common_hal_wifi_radio_get_ipv4_gateway(wifi_radio_obj_t *self); extern mp_obj_t common_hal_wifi_radio_get_ipv4_subnet(wifi_radio_obj_t *self); From 9d840aab0b81db61e185eeac5d8359489ff36320 Mon Sep 17 00:00:00 2001 From: "Ryan T. Hamilton" Date: Thu, 15 Oct 2020 23:45:11 -0700 Subject: [PATCH 09/10] Cleaned up and now testing --- ports/esp32s2/common-hal/wifi/Radio.c | 66 ++------------------------- ports/esp32s2/common-hal/wifi/Radio.h | 3 +- shared-bindings/wifi/Radio.c | 53 +-------------------- shared-bindings/wifi/Radio.h | 3 -- 4 files changed, 7 insertions(+), 118 deletions(-) diff --git a/ports/esp32s2/common-hal/wifi/Radio.c b/ports/esp32s2/common-hal/wifi/Radio.c index b1f9e67e05..6203a151bd 100644 --- a/ports/esp32s2/common-hal/wifi/Radio.c +++ b/ports/esp32s2/common-hal/wifi/Radio.c @@ -160,76 +160,20 @@ mp_obj_t common_hal_wifi_radio_get_ap_info(wifi_radio_obj_t *self) { return mp_const_none; } - wifi_network_obj_t *apnet = m_new_obj(wifi_network_obj_t); - apnet->base.type = &wifi_network_type; + wifi_network_obj_t *ap_info = m_new_obj(wifi_network_obj_t); + ap_info->base.type = &wifi_network_type; // From esp_wifi.h, the possible return values (typos theirs): // ESP_OK: succeed // ESP_ERR_WIFI_CONN: The station interface don't initialized // ESP_ERR_WIFI_NOT_CONNECT: The station is in disconnect status - if (esp_wifi_sta_get_ap_info(&self->apnet.record) != ESP_OK){ + if (esp_wifi_sta_get_ap_info(&self->ap_info.record) != ESP_OK){ return mp_const_none; } else { - memcpy(&apnet->record, &self->apnet.record, sizeof(wifi_ap_record_t)); - return MP_OBJ_FROM_PTR(apnet); + memcpy(&ap_info->record, &self->ap_info.record, sizeof(wifi_ap_record_t)); + return MP_OBJ_FROM_PTR(ap_info); } } -mp_obj_t common_hal_wifi_radio_get_ap_rssi(wifi_radio_obj_t *self) { - if (!esp_netif_is_netif_up(self->netif)) { - return mp_const_none; - } - - // Make sure the interface is in STA mode - if (self->sta_mode){ - return mp_const_none; - } - - // From esp_wifi.h, the possible return values (typos theirs): - // ESP_OK: succeed - // ESP_ERR_WIFI_CONN: The station interface don't initialized - // ESP_ERR_WIFI_NOT_CONNECT: The station is in disconnect status - if (esp_wifi_sta_get_ap_info(&self->ap_info) != ESP_OK){ - return mp_const_none; - } else { - return mp_obj_new_int(self->ap_info.rssi); - } -} - -// mp_obj_t common_hal_wifi_radio_get_ap_ssid(wifi_radio_obj_t *self) { -// if (!esp_netif_is_netif_up(self->netif)) { -// return mp_const_none; -// } - -// // Make sure the interface is in STA mode -// if (self->sta_mode){ -// return mp_const_none; -// } - -// if (esp_wifi_sta_get_ap_info(&self->ap_info) != ESP_OK){ -// return mp_const_none; -// } else { -// const char* cstr = (const char*) self->ap_info.ssid; -// return mp_obj_new_str(cstr, strlen(cstr)); -// } -// } - -// mp_obj_t common_hal_wifi_radio_get_ap_bssid(wifi_radio_obj_t *self) { -// if (!esp_netif_is_netif_up(self->netif)) { -// return mp_const_none; -// } - -// // Make sure the interface is in STA mode -// if (self->sta_mode){ -// return mp_const_none; -// } - -// if (esp_wifi_sta_get_ap_info(&self->ap_info) != ESP_OK){ -// return mp_const_none; -// } else { -// return mp_obj_new_bytes(self->ap_info.bssid, MAC_ADDRESS_LENGTH); -// } -// } - mp_obj_t common_hal_wifi_radio_get_ipv4_gateway(wifi_radio_obj_t *self) { if (!esp_netif_is_netif_up(self->netif)) { return mp_const_none; diff --git a/ports/esp32s2/common-hal/wifi/Radio.h b/ports/esp32s2/common-hal/wifi/Radio.h index f441096f7d..c7f484eafd 100644 --- a/ports/esp32s2/common-hal/wifi/Radio.h +++ b/ports/esp32s2/common-hal/wifi/Radio.h @@ -47,8 +47,7 @@ typedef struct { StaticEventGroup_t event_group; EventGroupHandle_t event_group_handle; wifi_config_t sta_config; - wifi_ap_record_t ap_info; - wifi_network_obj_t apnet; + wifi_network_obj_t ap_info; esp_netif_ip_info_t ip_info; esp_netif_dns_info_t dns_info; esp_netif_t *netif; diff --git a/shared-bindings/wifi/Radio.c b/shared-bindings/wifi/Radio.c index d755327694..4503310095 100644 --- a/shared-bindings/wifi/Radio.c +++ b/shared-bindings/wifi/Radio.c @@ -163,54 +163,6 @@ STATIC mp_obj_t wifi_radio_connect(size_t n_args, const mp_obj_t *pos_args, mp_m } STATIC MP_DEFINE_CONST_FUN_OBJ_KW(wifi_radio_connect_obj, 1, wifi_radio_connect); -//| ap_rssi: int -//| """RSSI of the currently connected AP. Returns none if not connected""" -//| -STATIC mp_obj_t wifi_radio_get_ap_rssi(mp_obj_t self) { - return common_hal_wifi_radio_get_ap_rssi(self); - -} -MP_DEFINE_CONST_FUN_OBJ_1(wifi_radio_get_ap_rssi_obj, wifi_radio_get_ap_rssi); - -const mp_obj_property_t wifi_radio_ap_rssi_obj = { - .base.type = &mp_type_property, - .proxy = { (mp_obj_t)&wifi_radio_get_ap_rssi_obj, - (mp_obj_t)&mp_const_none_obj, - (mp_obj_t)&mp_const_none_obj }, -}; - -// //| ap_ssid: int -// //| """SSID of the currently connected AP. Returns none if not connected""" -// //| -// STATIC mp_obj_t wifi_radio_get_ap_ssid(mp_obj_t self) { -// return common_hal_wifi_radio_get_ap_ssid(self); - -// } -// MP_DEFINE_CONST_FUN_OBJ_1(wifi_radio_get_ap_ssid_obj, wifi_radio_get_ap_ssid); - -// const mp_obj_property_t wifi_radio_ap_ssid_obj = { -// .base.type = &mp_type_property, -// .proxy = { (mp_obj_t)&wifi_radio_get_ap_ssid_obj, -// (mp_obj_t)&mp_const_none_obj, -// (mp_obj_t)&mp_const_none_obj }, -// }; - -// //| ap_bssid: int -// //| """BSSID (usually MAC) of the currently connected AP. Returns none if not connected""" -// //| -// STATIC mp_obj_t wifi_radio_get_ap_bssid(mp_obj_t self) { -// return common_hal_wifi_radio_get_ap_bssid(self); - -// } -// MP_DEFINE_CONST_FUN_OBJ_1(wifi_radio_get_ap_bssid_obj, wifi_radio_get_ap_bssid); - -// const mp_obj_property_t wifi_radio_ap_bssid_obj = { -// .base.type = &mp_type_property, -// .proxy = { (mp_obj_t)&wifi_radio_get_ap_bssid_obj, -// (mp_obj_t)&mp_const_none_obj, -// (mp_obj_t)&mp_const_none_obj }, -// }; - //| ipv4_gateway: Optional[ipaddress.IPv4Address] //| """IP v4 Address of the gateway when connected to an access point. None otherwise.""" //| @@ -276,7 +228,7 @@ const mp_obj_property_t wifi_radio_ipv4_dns_obj = { }; //| ap_info: Optional[Network] -//| """None otherwise.""" +//| """Network object containing BSSID, SSID, channel, and RSSI when connected to an access point. None otherwise.""" //| STATIC mp_obj_t wifi_radio_get_ap_info(mp_obj_t self) { return common_hal_wifi_radio_get_ap_info(self); @@ -332,9 +284,6 @@ STATIC const mp_rom_map_elem_t wifi_radio_locals_dict_table[] = { // { MP_ROM_QSTR(MP_QSTR_connect_to_enterprise), MP_ROM_PTR(&wifi_radio_connect_to_enterprise_obj) }, { MP_ROM_QSTR(MP_QSTR_ap_info), MP_ROM_PTR(&wifi_radio_ap_info_obj) }, - { MP_ROM_QSTR(MP_QSTR_ap_rssi), MP_ROM_PTR(&wifi_radio_ap_rssi_obj) }, - // { MP_ROM_QSTR(MP_QSTR_ap_ssid), MP_ROM_PTR(&wifi_radio_ap_ssid_obj) }, - // { MP_ROM_QSTR(MP_QSTR_ap_bssid), MP_ROM_PTR(&wifi_radio_ap_bssid_obj) }, { MP_ROM_QSTR(MP_QSTR_ipv4_dns), MP_ROM_PTR(&wifi_radio_ipv4_dns_obj) }, { MP_ROM_QSTR(MP_QSTR_ipv4_gateway), MP_ROM_PTR(&wifi_radio_ipv4_gateway_obj) }, { MP_ROM_QSTR(MP_QSTR_ipv4_subnet), MP_ROM_PTR(&wifi_radio_ipv4_subnet_obj) }, diff --git a/shared-bindings/wifi/Radio.h b/shared-bindings/wifi/Radio.h index 6dca40c56b..38cc933372 100644 --- a/shared-bindings/wifi/Radio.h +++ b/shared-bindings/wifi/Radio.h @@ -54,9 +54,6 @@ extern void common_hal_wifi_radio_stop_scanning_networks(wifi_radio_obj_t *self) extern wifi_radio_error_t common_hal_wifi_radio_connect(wifi_radio_obj_t *self, uint8_t* ssid, size_t ssid_len, uint8_t* password, size_t password_len, uint8_t channel, mp_float_t timeout, uint8_t* bssid, size_t bssid_len); extern mp_obj_t common_hal_wifi_radio_get_ap_info(wifi_radio_obj_t *self); -extern mp_obj_t common_hal_wifi_radio_get_ap_rssi(wifi_radio_obj_t *self); -// extern mp_obj_t common_hal_wifi_radio_get_ap_ssid(wifi_radio_obj_t *self); -// extern mp_obj_t common_hal_wifi_radio_get_ap_bssid(wifi_radio_obj_t *self); extern mp_obj_t common_hal_wifi_radio_get_ipv4_dns(wifi_radio_obj_t *self); extern mp_obj_t common_hal_wifi_radio_get_ipv4_gateway(wifi_radio_obj_t *self); extern mp_obj_t common_hal_wifi_radio_get_ipv4_subnet(wifi_radio_obj_t *self); From 76f1db7a8795f2594db6b6d0d6f38a48a2cfd8af Mon Sep 17 00:00:00 2001 From: "Ryan T. Hamilton" Date: Sat, 17 Oct 2020 00:23:31 -0700 Subject: [PATCH 10/10] Set sta_mode flag for actual use/checking --- ports/esp32s2/common-hal/wifi/Radio.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/ports/esp32s2/common-hal/wifi/Radio.c b/ports/esp32s2/common-hal/wifi/Radio.c index 6203a151bd..80afc5eaad 100644 --- a/ports/esp32s2/common-hal/wifi/Radio.c +++ b/ports/esp32s2/common-hal/wifi/Radio.c @@ -53,6 +53,8 @@ static void start_station(wifi_radio_obj_t *self) { } esp_wifi_set_mode(next_mode); + self->sta_mode = 1; + esp_wifi_set_config(WIFI_MODE_STA, &self->sta_config); } @@ -156,7 +158,7 @@ mp_obj_t common_hal_wifi_radio_get_ap_info(wifi_radio_obj_t *self) { } // Make sure the interface is in STA mode - if (self->sta_mode){ + if (!self->sta_mode){ return mp_const_none; }