Skip to content

Redesign ESP8266WiFiMulti.[cpp|h] #7619

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 3 commits into from
Oct 2, 2020
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
40 changes: 28 additions & 12 deletions libraries/ESP8266WiFi/examples/WiFiMulti/WiFiMulti.ino
Original file line number Diff line number Diff line change
@@ -1,33 +1,49 @@
/*
This sketch trys to Connect to the best AP based on a given list
This sketch shows how to use multiple WiFi networks.

In this example, ESP8266 works in AP mode.
It demonstrates:
- Fast connect to previous WiFi network at startup
- 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

To enable debugging output, select in the Arduino iDE:
- Tools | Debug Port: Serial
- Tools | Debug Level: WiFi
*/

#include <ESP8266WiFi.h>
#include <ESP8266WiFiMulti.h>

ESP8266WiFiMulti wifiMulti;

// WiFi connect timeout per AP. Increase when connecting takes longer.
const uint32_t connectTimeoutMs = 5000;

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

// Set WiFi to station mode
WiFi.mode(WIFI_STA);

// Register multi WiFi networks
wifiMulti.addAP("ssid_from_AP_1", "your_password_for_AP_1");
wifiMulti.addAP("ssid_from_AP_2", "your_password_for_AP_2");
wifiMulti.addAP("ssid_from_AP_3", "your_password_for_AP_3");

Serial.println("Connecting Wifi...");
if (wifiMulti.run() == WL_CONNECTED) {
Serial.println("");
Serial.println("WiFi connected");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
}
// More is possible
}

void loop() {
if (wifiMulti.run() != WL_CONNECTED) {
// Maintain WiFi connection
if (wifiMulti.run(connectTimeoutMs) == WL_CONNECTED) {
Serial.print("WiFi connected: ");
Serial.print(WiFi.SSID());
Serial.print(" ");
Serial.println(WiFi.localIP());
} else {
Serial.println("WiFi not connected!");
delay(1000);
}

delay(1000);
}
Loading