From 3c7d0e990515b8806c127e272acb7633524824c7 Mon Sep 17 00:00:00 2001 From: me-no-dev Date: Tue, 24 Jan 2017 00:56:12 +0200 Subject: [PATCH] add RSSI return and fix SSID and BSSID methods fixes: https://github.com/espressif/arduino-esp32/issues/144 --- libraries/WiFi/src/WiFiSTA.cpp | 37 ++++++++++++++++++++-------------- libraries/WiFi/src/WiFiSTA.h | 2 +- 2 files changed, 23 insertions(+), 16 deletions(-) diff --git a/libraries/WiFi/src/WiFiSTA.cpp b/libraries/WiFi/src/WiFiSTA.cpp index 7d84d9a7..f8b17ae8 100644 --- a/libraries/WiFi/src/WiFiSTA.cpp +++ b/libraries/WiFi/src/WiFiSTA.cpp @@ -43,9 +43,6 @@ extern "C" { #include } -extern "C" void esp_schedule(); -extern "C" void esp_yield(); - // ----------------------------------------------------------------------------------------------------------------------- // ---------------------------------------------------- Private functions ------------------------------------------------ // ----------------------------------------------------------------------------------------------------------------------- @@ -404,9 +401,11 @@ wl_status_t WiFiSTAClass::status() */ String WiFiSTAClass::SSID() const { - wifi_config_t conf; - esp_wifi_get_config(WIFI_IF_STA, &conf); - return String(reinterpret_cast(conf.sta.ssid)); + wifi_ap_record_t info; + if(!esp_wifi_sta_get_ap_info(&info)) { + return String(reinterpret_cast(info.ssid)); + } + return String(); } /** @@ -427,10 +426,12 @@ String WiFiSTAClass::psk() const uint8_t* WiFiSTAClass::BSSID(void) { static uint8_t bssid[6]; - wifi_config_t conf; - esp_wifi_get_config(WIFI_IF_STA, &conf); - memcpy(bssid, conf.sta.bssid, 6); - return reinterpret_cast(bssid); + wifi_ap_record_t info; + if(!esp_wifi_sta_get_ap_info(&info)) { + memcpy(bssid, info.bssid, 6); + return reinterpret_cast(bssid); + } + return NULL; } /** @@ -439,10 +440,12 @@ uint8_t* WiFiSTAClass::BSSID(void) */ String WiFiSTAClass::BSSIDstr(void) { + uint8_t* bssid = BSSID(); + if(!bssid){ + return String(); + } char mac[18] = { 0 }; - wifi_config_t conf; - esp_wifi_get_config(WIFI_IF_STA, &conf); - sprintf(mac, "%02X:%02X:%02X:%02X:%02X:%02X", conf.sta.bssid[0], conf.sta.bssid[1], conf.sta.bssid[2], conf.sta.bssid[3], conf.sta.bssid[4], conf.sta.bssid[5]); + sprintf(mac, "%02X:%02X:%02X:%02X:%02X:%02X", bssid[0], bssid[1], bssid[2], bssid[3], bssid[4], bssid[5]); return String(mac); } @@ -450,9 +453,13 @@ String WiFiSTAClass::BSSIDstr(void) * Return the current network RSSI. * @return RSSI value */ -int32_t WiFiSTAClass::RSSI(void) +int8_t WiFiSTAClass::RSSI(void) { - return 0;//wifi_station_get_rssi(); + wifi_ap_record_t info; + if(!esp_wifi_sta_get_ap_info(&info)) { + return info.rssi; + } + return 0; } /** diff --git a/libraries/WiFi/src/WiFiSTA.h b/libraries/WiFi/src/WiFiSTA.h index 28b0aa6f..ad02cef3 100644 --- a/libraries/WiFi/src/WiFiSTA.h +++ b/libraries/WiFi/src/WiFiSTA.h @@ -78,7 +78,7 @@ public: uint8_t * BSSID(); String BSSIDstr(); - int32_t RSSI(); + int8_t RSSI(); static void _setStatus(wl_status_t status); protected: