Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Nov 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions libraries/WiFi/src/WiFiSTA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -716,14 +716,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);
}
Expand Down
2 changes: 1 addition & 1 deletion libraries/WiFi/src/WiFiSTA.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ class WiFiSTAClass
String SSID() const;
String psk() const;

uint8_t * BSSID();
uint8_t * BSSID(uint8_t* bssid = NULL);
String BSSIDstr();

int8_t RSSI();
Expand Down
11 changes: 10 additions & 1 deletion libraries/WiFi/src/WiFiScan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion libraries/WiFi/src/WiFiScan.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class WiFiScanClass
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); };
Expand Down