Skip to content

Commit 0b6d20e

Browse files
authored
WiFi.BSSID and scan result BSSID with parameter as in WiFi libraries by (espressif#8853)
Arduino
1 parent 3fa2807 commit 0b6d20e

File tree

4 files changed

+23
-5
lines changed

4 files changed

+23
-5
lines changed

libraries/WiFi/src/WiFiSTA.cpp

+11-2
Original file line numberDiff line numberDiff line change
@@ -717,14 +717,23 @@ String WiFiSTAClass::psk() const
717717
* Return the current bssid / mac associated with the network if configured
718718
* @return bssid uint8_t *
719719
*/
720-
uint8_t* WiFiSTAClass::BSSID(void)
720+
uint8_t* WiFiSTAClass::BSSID(uint8_t* buff)
721721
{
722722
static uint8_t bssid[6];
723723
wifi_ap_record_t info;
724724
if(WiFiGenericClass::getMode() == WIFI_MODE_NULL){
725725
return NULL;
726726
}
727-
if(!esp_wifi_sta_get_ap_info(&info)) {
727+
esp_err_t err = esp_wifi_sta_get_ap_info(&info);
728+
if (buff != NULL) {
729+
if(err) {
730+
memset(buff, 0, 6);
731+
} else {
732+
memcpy(buff, info.bssid, 6);
733+
}
734+
return buff;
735+
}
736+
if(!err) {
728737
memcpy(bssid, info.bssid, 6);
729738
return reinterpret_cast<uint8_t*>(bssid);
730739
}

libraries/WiFi/src/WiFiSTA.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ class WiFiSTAClass
9898
String SSID() const;
9999
String psk() const;
100100

101-
uint8_t * BSSID();
101+
uint8_t * BSSID(uint8_t* bssid = NULL);
102102
String BSSIDstr();
103103

104104
int8_t RSSI();

libraries/WiFi/src/WiFiScan.cpp

+10-1
Original file line numberDiff line numberDiff line change
@@ -243,11 +243,20 @@ int32_t WiFiScanClass::RSSI(uint8_t i)
243243
/**
244244
* return MAC / BSSID of scanned wifi
245245
* @param i specify from which network item want to get the information
246+
* @param buff optional buffer for the result uint8_t array with length 6
246247
* @return uint8_t * MAC / BSSID of scanned wifi
247248
*/
248-
uint8_t * WiFiScanClass::BSSID(uint8_t i)
249+
uint8_t * WiFiScanClass::BSSID(uint8_t i, uint8_t* buff)
249250
{
250251
wifi_ap_record_t* it = reinterpret_cast<wifi_ap_record_t*>(_getScanInfoByIndex(i));
252+
if(buff != NULL) {
253+
if(!it) {
254+
memset(buff, 0, 6);
255+
} else {
256+
memcpy(buff, it->bssid, 6);
257+
}
258+
return buff;
259+
}
251260
if(!it) {
252261
return 0;
253262
}

libraries/WiFi/src/WiFiScan.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class WiFiScanClass
4242
String SSID(uint8_t networkItem);
4343
wifi_auth_mode_t encryptionType(uint8_t networkItem);
4444
int32_t RSSI(uint8_t networkItem);
45-
uint8_t * BSSID(uint8_t networkItem);
45+
uint8_t * BSSID(uint8_t networkItem, uint8_t* bssid = NULL);
4646
String BSSIDstr(uint8_t networkItem);
4747
int32_t channel(uint8_t networkItem);
4848
static void * getScanInfoByIndex(int i) { return _getScanInfoByIndex(i); };

0 commit comments

Comments
 (0)