WiFi.BSSID and scan result BSSID with parameter as in WiFi libraries by (#8853)

Arduino
This commit is contained in:
Juraj Andrássy 2023-11-10 23:29:46 +01:00 committed by GitHub
parent 3fa2807aad
commit 0b6d20ed65
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 23 additions and 5 deletions

View file

@ -717,14 +717,23 @@ String WiFiSTAClass::psk() const
* Return the current bssid / mac associated with the network if configured
* @return bssid uint8_t *
*/
uint8_t* WiFiSTAClass::BSSID(void)
uint8_t* WiFiSTAClass::BSSID(uint8_t* buff)
{
static uint8_t bssid[6];
wifi_ap_record_t info;
if(WiFiGenericClass::getMode() == WIFI_MODE_NULL){
return NULL;
}
if(!esp_wifi_sta_get_ap_info(&info)) {
esp_err_t err = esp_wifi_sta_get_ap_info(&info);
if (buff != NULL) {
if(err) {
memset(buff, 0, 6);
} else {
memcpy(buff, info.bssid, 6);
}
return buff;
}
if(!err) {
memcpy(bssid, info.bssid, 6);
return reinterpret_cast<uint8_t*>(bssid);
}

View file

@ -98,7 +98,7 @@ public:
String SSID() const;
String psk() const;
uint8_t * BSSID();
uint8_t * BSSID(uint8_t* bssid = NULL);
String BSSIDstr();
int8_t RSSI();

View file

@ -243,11 +243,20 @@ int32_t WiFiScanClass::RSSI(uint8_t i)
/**
* return MAC / BSSID of scanned wifi
* @param i specify from which network item want to get the information
* @param buff optional buffer for the result uint8_t array with length 6
* @return uint8_t * MAC / BSSID of scanned wifi
*/
uint8_t * WiFiScanClass::BSSID(uint8_t i)
uint8_t * WiFiScanClass::BSSID(uint8_t i, uint8_t* buff)
{
wifi_ap_record_t* it = reinterpret_cast<wifi_ap_record_t*>(_getScanInfoByIndex(i));
if(buff != NULL) {
if(!it) {
memset(buff, 0, 6);
} else {
memcpy(buff, it->bssid, 6);
}
return buff;
}
if(!it) {
return 0;
}

View file

@ -42,7 +42,7 @@ public:
String SSID(uint8_t networkItem);
wifi_auth_mode_t encryptionType(uint8_t networkItem);
int32_t RSSI(uint8_t networkItem);
uint8_t * BSSID(uint8_t networkItem);
uint8_t * BSSID(uint8_t networkItem, uint8_t* bssid = NULL);
String BSSIDstr(uint8_t networkItem);
int32_t channel(uint8_t networkItem);
static void * getScanInfoByIndex(int i) { return _getScanInfoByIndex(i); };