Skip to content
New issue

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

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

Already on GitHub? # to your account

Expand access to SDK's struct bss_info #8683

Merged
merged 3 commits into from
Oct 10, 2022
Merged
Show file tree
Hide file tree
Changes from 2 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
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 struct bss_info *bssInfo = WiFi.getNetworkInfo(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 uint8_t
* @return struct bss_info*, may be NULL
*/
const struct bss_info *ESP8266WiFiScanClass::getNetworkInfo(uint8_t i) {
return reinterpret_cast<const struct bss_info*>(_getScanInfoByIndex(i));
}
mcspr marked this conversation as resolved.
Show resolved Hide resolved

/**
* 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 struct bss_info *getNetworkInfo(uint8_t 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