add RSSI return and fix SSID and BSSID methods

fixes: https://github.com/espressif/arduino-esp32/issues/144
This commit is contained in:
me-no-dev 2017-01-24 00:56:12 +02:00
parent 13f3ac569b
commit 3c7d0e9905
2 changed files with 23 additions and 16 deletions

View File

@ -43,9 +43,6 @@ extern "C" {
#include <esp_smartconfig.h> #include <esp_smartconfig.h>
} }
extern "C" void esp_schedule();
extern "C" void esp_yield();
// ----------------------------------------------------------------------------------------------------------------------- // -----------------------------------------------------------------------------------------------------------------------
// ---------------------------------------------------- Private functions ------------------------------------------------ // ---------------------------------------------------- Private functions ------------------------------------------------
// ----------------------------------------------------------------------------------------------------------------------- // -----------------------------------------------------------------------------------------------------------------------
@ -404,9 +401,11 @@ wl_status_t WiFiSTAClass::status()
*/ */
String WiFiSTAClass::SSID() const String WiFiSTAClass::SSID() const
{ {
wifi_config_t conf; wifi_ap_record_t info;
esp_wifi_get_config(WIFI_IF_STA, &conf); if(!esp_wifi_sta_get_ap_info(&info)) {
return String(reinterpret_cast<char*>(conf.sta.ssid)); return String(reinterpret_cast<char*>(info.ssid));
}
return String();
} }
/** /**
@ -427,11 +426,13 @@ String WiFiSTAClass::psk() const
uint8_t* WiFiSTAClass::BSSID(void) uint8_t* WiFiSTAClass::BSSID(void)
{ {
static uint8_t bssid[6]; static uint8_t bssid[6];
wifi_config_t conf; wifi_ap_record_t info;
esp_wifi_get_config(WIFI_IF_STA, &conf); if(!esp_wifi_sta_get_ap_info(&info)) {
memcpy(bssid, conf.sta.bssid, 6); memcpy(bssid, info.bssid, 6);
return reinterpret_cast<uint8_t*>(bssid); return reinterpret_cast<uint8_t*>(bssid);
} }
return NULL;
}
/** /**
* Return the current bssid / mac associated with the network if configured * Return the current bssid / mac associated with the network if configured
@ -439,10 +440,12 @@ uint8_t* WiFiSTAClass::BSSID(void)
*/ */
String WiFiSTAClass::BSSIDstr(void) String WiFiSTAClass::BSSIDstr(void)
{ {
uint8_t* bssid = BSSID();
if(!bssid){
return String();
}
char mac[18] = { 0 }; char mac[18] = { 0 };
wifi_config_t conf; sprintf(mac, "%02X:%02X:%02X:%02X:%02X:%02X", bssid[0], bssid[1], bssid[2], bssid[3], bssid[4], bssid[5]);
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]);
return String(mac); return String(mac);
} }
@ -450,9 +453,13 @@ String WiFiSTAClass::BSSIDstr(void)
* Return the current network RSSI. * Return the current network RSSI.
* @return RSSI value * @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;
} }
/** /**

View File

@ -78,7 +78,7 @@ public:
uint8_t * BSSID(); uint8_t * BSSID();
String BSSIDstr(); String BSSIDstr();
int32_t RSSI(); int8_t RSSI();
static void _setStatus(wl_status_t status); static void _setStatus(wl_status_t status);
protected: protected: