8
8
- Connect to WiFi with strongest signal (RSSI)
9
9
- Fall back to connect to next WiFi when a connection failed or lost
10
10
- Fall back to connect to hidden SSID's which are not reported by WiFi scan
11
+ - Static IP assigned depending on which SSID is connected
11
12
12
13
To enable debugging output, select in the Arduino iDE:
13
14
- Tools | Debug Port: Serial
@@ -21,6 +22,8 @@ ESP8266WiFiMulti wifiMulti;
21
22
// WiFi connect timeout per AP. Increase when connecting takes longer.
22
23
const uint32_t connectTimeoutMs = 5000 ;
23
24
25
+ SSID_selected_callback_t connectedToSSID (char *ssid);
26
+
24
27
void setup () {
25
28
// Don't save WiFi configuration in flash - optional
26
29
WiFi.persistent (false );
@@ -35,9 +38,24 @@ void setup() {
35
38
wifiMulti.addAP (" ssid_from_AP_1" , " your_password_for_AP_1" );
36
39
wifiMulti.addAP (" ssid_from_AP_2" , " your_password_for_AP_2" );
37
40
wifiMulti.addAP (" ssid_from_AP_3" , " your_password_for_AP_3" );
41
+
42
+ wifiMulti.onSsidSelected (connectedToSSID);
43
+
38
44
// More is possible
39
45
}
40
46
47
+ SSID_selected_callback_t connectedToSSID (char *ssid)
48
+ {
49
+ // On connecting the second WiFi, assign static IP using config(...).
50
+ // For other SSID (if config has not already been called) DHCP will be used.
51
+ if (strcmp (ssid, " ssid_from_AP_2" ) == 0 ) {
52
+ IPAddress ip2 (192 ,168 ,1 ,123 );
53
+ IPAddress gw2 (192 ,168 ,1 ,1 );
54
+ IPAddress subnet2 (255 ,255 ,255 ,0 );
55
+ WiFi.config (ip2, gw2, subnet2);
56
+ }
57
+ }
58
+
41
59
void loop () {
42
60
// Maintain WiFi connection
43
61
if (wifiMulti.run (connectTimeoutMs) == WL_CONNECTED) {
0 commit comments