Skip to content

Commit 1381489

Browse files
mhightower83hasenradball
authored andcommitted
Expand access to SDK's struct bss_info (esp8266#8683)
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 esp8266#7965 (comment)
1 parent 018f8ea commit 1381489

File tree

3 files changed

+34
-2
lines changed

3 files changed

+34
-2
lines changed

libraries/ESP8266WiFi/examples/WiFiScan/WiFiScan.ino

+25-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ void loop() {
2222
String ssid;
2323
int32_t rssi;
2424
uint8_t encryptionType;
25-
uint8_t* bssid;
25+
uint8_t *bssid;
2626
int32_t channel;
2727
bool hidden;
2828
int scanResult;
@@ -40,7 +40,30 @@ void loop() {
4040
for (int8_t i = 0; i < scanResult; i++) {
4141
WiFi.getNetworkInfo(i, ssid, encryptionType, rssi, bssid, channel, hidden);
4242

43-
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());
43+
// get extra info
44+
const bss_info *bssInfo = WiFi.getScanInfoByIndex(i);
45+
String phyMode;
46+
const char *wps = "";
47+
if (bssInfo) {
48+
phyMode.reserve(12);
49+
phyMode = F("802.11");
50+
String slash;
51+
if (bssInfo->phy_11b) {
52+
phyMode += 'b';
53+
slash = '/';
54+
}
55+
if (bssInfo->phy_11g) {
56+
phyMode += slash + 'g';
57+
slash = '/';
58+
}
59+
if (bssInfo->phy_11n) {
60+
phyMode += slash + 'n';
61+
}
62+
if (bssInfo->wps) {
63+
wps = PSTR("WPS");
64+
}
65+
}
66+
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());
4467
yield();
4568
}
4669
} else {

libraries/ESP8266WiFi/src/ESP8266WiFiScan.cpp

+8
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,14 @@ void ESP8266WiFiScanClass::scanDelete() {
147147
_scanComplete = false;
148148
}
149149

150+
/**
151+
* returns const pointer to the requested scanned wifi entry for furthor parsing.
152+
* @param networkItem int
153+
* @return struct bss_info*, may be NULL
154+
*/
155+
const bss_info *ESP8266WiFiScanClass::getScanInfoByIndex(int i) {
156+
return reinterpret_cast<const bss_info*>(_getScanInfoByIndex(i));
157+
};
150158

151159
/**
152160
* loads all infos from a scanned wifi in to the ptr parameters

libraries/ESP8266WiFi/src/ESP8266WiFiScan.h

+1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ class ESP8266WiFiScanClass {
4141
void scanDelete();
4242

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

4647
String SSID(uint8_t networkItem);

0 commit comments

Comments
 (0)