Skip to content

Commit

Permalink
Expand access to SDK's struct bss_info (#8683)
Browse files Browse the repository at this point in the history
The NONOS SDK's `struct bss_info` in `user_interface.h` has grown since the
beginning of this project. The additional elements are not accessible.
Add a method for R/O access to full `struct bss_info`.

See #7965 (comment)
  • Loading branch information
mhightower83 committed Oct 10, 2022
1 parent a0c7a85 commit 3df5693
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 2 deletions.
27 changes: 25 additions & 2 deletions libraries/ESP8266WiFi/examples/WiFiScan/WiFiScan.ino
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ void loop() {
String ssid;
int32_t rssi;
uint8_t encryptionType;
uint8_t* bssid;
uint8_t *bssid;
int32_t channel;
bool hidden;
int scanResult;
Expand All @@ -40,7 +40,30 @@ void loop() {
for (int8_t i = 0; i < scanResult; i++) {
WiFi.getNetworkInfo(i, ssid, encryptionType, rssi, bssid, channel, hidden);

Serial.printf(PSTR(" %02d: [CH %02d] [%02X:%02X:%02X:%02X:%02X:%02X] %ddBm %c %c %s\n"), i, channel, bssid[0], bssid[1], bssid[2], bssid[3], bssid[4], bssid[5], rssi, (encryptionType == ENC_TYPE_NONE) ? ' ' : '*', hidden ? 'H' : 'V', ssid.c_str());
// get extra info
const bss_info *bssInfo = WiFi.getScanInfoByIndex(i);
String phyMode;
const char *wps = "";
if (bssInfo) {
phyMode.reserve(12);
phyMode = F("802.11");
String slash;
if (bssInfo->phy_11b) {
phyMode += 'b';
slash = '/';
}
if (bssInfo->phy_11g) {
phyMode += slash + 'g';
slash = '/';
}
if (bssInfo->phy_11n) {
phyMode += slash + 'n';
}
if (bssInfo->wps) {
wps = PSTR("WPS");
}
}
Serial.printf(PSTR(" %02d: [CH %02d] [%02X:%02X:%02X:%02X:%02X:%02X] %ddBm %c %c %-11s %3S %s\n"), i, channel, bssid[0], bssid[1], bssid[2], bssid[3], bssid[4], bssid[5], rssi, (encryptionType == ENC_TYPE_NONE) ? ' ' : '*', hidden ? 'H' : 'V', phyMode.c_str(), wps, ssid.c_str());
yield();
}
} else {
Expand Down
8 changes: 8 additions & 0 deletions libraries/ESP8266WiFi/src/ESP8266WiFiScan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,14 @@ void ESP8266WiFiScanClass::scanDelete() {
_scanComplete = false;
}

/**
* returns const pointer to the requested scanned wifi entry for furthor parsing.
* @param networkItem int
* @return struct bss_info*, may be NULL
*/
const bss_info *ESP8266WiFiScanClass::getScanInfoByIndex(int i) {
return reinterpret_cast<const bss_info*>(_getScanInfoByIndex(i));
};

/**
* loads all infos from a scanned wifi in to the ptr parameters
Expand Down
1 change: 1 addition & 0 deletions libraries/ESP8266WiFi/src/ESP8266WiFiScan.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class ESP8266WiFiScanClass {
void scanDelete();

// scan result
const bss_info *getScanInfoByIndex(int i);
bool getNetworkInfo(uint8_t networkItem, String &ssid, uint8_t &encryptionType, int32_t &RSSI, uint8_t* &BSSID, int32_t &channel, bool &isHidden);

String SSID(uint8_t networkItem);
Expand Down

0 comments on commit 3df5693

Please sign in to comment.