diff options
| author | Ryan T. Hamilton <astrobokonon@gmail.com> | 2020-09-28 17:25:09 -0700 |
|---|---|---|
| committer | Ryan T. Hamilton <astrobokonon@gmail.com> | 2020-09-28 17:25:09 -0700 |
| commit | 2a4a244245e3e03bfb89dcc49e56e83b71291bb2 (patch) | |
| tree | 29a04147528bf9784b222bc71c81298c2cb1eeca /ports | |
| parent | 7b7ef8edde2f7769b03776135b590ec7337cfa70 (diff) | |
Add ap_ssid and ap_bssid
Diffstat (limited to 'ports')
| -rw-r--r-- | ports/esp32s2/common-hal/wifi/Radio.c | 39 |
1 files changed, 37 insertions, 2 deletions
diff --git a/ports/esp32s2/common-hal/wifi/Radio.c b/ports/esp32s2/common-hal/wifi/Radio.c index 0184793a1..019e8316c 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; |
