Skip to content

Add support for hidden SSID's Multi WiFi #7629

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

Merged
merged 5 commits into from
Jan 21, 2021
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
4 changes: 4 additions & 0 deletions libraries/ESP8266WiFi/examples/WiFiMulti/WiFiMulti.ino
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
- Registering multiple networks (at least 1)
- Connect to WiFi with strongest signal (RSSI)
- Fall back to connect to next WiFi when a connection failed or lost
- Fall back to connect to hidden SSID's which are not reported by WiFi scan

To enable debugging output, select in the Arduino iDE:
- Tools | Debug Port: Serial
Expand All @@ -21,6 +22,9 @@ ESP8266WiFiMulti wifiMulti;
const uint32_t connectTimeoutMs = 5000;

void setup() {
// Don't save WiFi configuration in flash - optional
WiFi.persistent(false);

Serial.begin(115200);
Serial.println("\nESP8266 Multi WiFi example");

Expand Down
30 changes: 28 additions & 2 deletions libraries/ESP8266WiFi/src/ESP8266WiFiMulti.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -326,12 +326,18 @@ wl_status_t ESP8266WiFiMulti::connectWiFiMulti(uint32_t connectTimeoutMs)
}
DEBUG_WIFI_MULTI("\n");

// Create indices for AP connection failures
uint8_t connectSkipIndex[_APlist.size()];
memset(connectSkipIndex, 0, sizeof(connectSkipIndex));

// Connect to known WiFi AP's sorted by RSSI
for (int8_t i = 0; i < numNetworks; i++) {
// Get network information
WiFi.getNetworkInfo(known[i], ssid, encType, rssi, bssid, channel, hidden);

for (auto entry : _APlist) {
for (uint8_t j = 0; j < _APlist.size(); j++) {
auto &entry = _APlist[j];

// Check SSID
if (ssid == entry.ssid) {
DEBUG_WIFI_MULTI("[WIFIM] Connecting %s\n", ssid);
Expand All @@ -343,13 +349,33 @@ wl_status_t ESP8266WiFiMulti::connectWiFiMulti(uint32_t connectTimeoutMs)
if (waitWiFiConnect(connectTimeoutMs) == WL_CONNECTED) {
return WL_CONNECTED;
}

// Failed to connect, skip for hidden SSID connects
connectSkipIndex[j] = true;
}
}
}

// Try to connect to hidden AP's which are not reported by WiFi scan
for (uint8_t i = 0; i < _APlist.size(); i++) {
auto &entry = _APlist[i];

if (!connectSkipIndex[i]) {
DEBUG_WIFI_MULTI("[WIFIM] Try hidden connect %s\n", entry.ssid);

// Connect to WiFi
WiFi.begin(entry.ssid, entry.passphrase);

// Wait for status change
if (waitWiFiConnect(connectTimeoutMs) == WL_CONNECTED) {
return WL_CONNECTED;
}
}
}

DEBUG_WIFI_MULTI("[WIFIM] Could not connect\n", ssid);

// Coult not connect to any WiFi network
// Could not connect to any WiFi network
return WL_CONNECT_FAILED;
}

Expand Down