Skip to content

Commit 309a13a

Browse files
committed
WiFi.BSSID and scan result BSSID with parameter as in WiFi libraries by
Arduino
1 parent 6d9ebea commit 309a13a

File tree

4 files changed

+23
-5
lines changed

4 files changed

+23
-5
lines changed

Diff for: libraries/WiFi/src/WiFiSTA.cpp

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

Diff for: 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();

Diff for: 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
}

Diff for: 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)