-
Notifications
You must be signed in to change notification settings - Fork 53
Wifi multi network support for esp32/esp8266/PicoW #601
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
Changes from 20 commits
01b6968
1f8c507
768406a
2f0d637
1299f29
d9efecb
7d2b366
a0aa472
5abd2ab
b9adb8b
2daf005
e1dc72f
10afca0
54f7593
f83db5e
9e14378
044bef5
adac2b2
46421e9
3c1af56
a4a4880
4e099ab
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,6 +24,7 @@ | |
#include "Adafruit_MQTT_Client.h" | ||
#include "Arduino.h" | ||
#include "WiFi.h" | ||
#include "WiFiMulti.h" | ||
#include <WiFiClientSecure.h> | ||
extern Wippersnapper WS; | ||
|
||
|
@@ -109,7 +110,14 @@ class Wippersnapper_ESP32 : public Wippersnapper { | |
|
||
// Was the network within secrets.json found? | ||
for (int i = 0; i < n; ++i) { | ||
if (strcmp(_ssid, WiFi.SSID(i).c_str()) == 0) | ||
if (strlen(WS._multiNetworks[0].ssid) > 0) { | ||
// multi network mode | ||
for (int j = 0; j < 5; j++) { | ||
if (strcmp(WS._multiNetworks[j].ssid, WiFi.SSID(i).c_str()) == 0) | ||
return true; | ||
} | ||
} // else single network mode | ||
else if (strcmp(_ssid, WiFi.SSID(i).c_str()) == 0) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider changing this to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The normal network ssid doesn't get added to the altNetworks, so this check needs to still happen. I should move this to be a separate check, dropping the else, probably above the multi-network/altNetworks check as that will be the less common path. |
||
return true; | ||
} | ||
|
||
|
@@ -191,6 +199,7 @@ class Wippersnapper_ESP32 : public Wippersnapper { | |
const char *_ssid; ///< WiFi SSID | ||
const char *_pass; ///< WiFi password | ||
WiFiClientSecure *_mqtt_client; ///< Pointer to a WiFi client object (TLS/SSL) | ||
WiFiMulti _wifiMulti; ///< WiFiMulti object for multi-network mode | ||
|
||
const char *_aio_root_ca_staging = | ||
"-----BEGIN CERTIFICATE-----\n" | ||
|
@@ -262,11 +271,35 @@ class Wippersnapper_ESP32 : public Wippersnapper { | |
if (strlen(_ssid) == 0) { | ||
_status = WS_SSID_INVALID; | ||
} else { | ||
WiFi.setAutoReconnect(false); | ||
brentru marked this conversation as resolved.
Show resolved
Hide resolved
|
||
_disconnect(); | ||
delay(100); | ||
WiFi.begin(_ssid, _pass); | ||
_status = WS_NET_DISCONNECTED; | ||
delay(5000); | ||
if (strlen(WS._multiNetworks[0].ssid) > 0) { | ||
tyeth marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// multi network mode | ||
_wifiMulti.APlistClean(); | ||
_wifiMulti.setAllowOpenAP(false); | ||
// add default network | ||
_wifiMulti.addAP(_ssid, _pass); | ||
// add array of alternative networks | ||
for (int i = 0; i < 3; i++) { | ||
tyeth marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if (strlen(WS._multiNetworks[i].ssid) > 0) { | ||
_wifiMulti.addAP(WS._multiNetworks[i].ssid, | ||
WS._multiNetworks[i].pass); | ||
} | ||
} | ||
if (_wifiMulti.run(20000) == WL_CONNECTED) { | ||
_status = WS_NET_CONNECTED; | ||
} else { | ||
_status = WS_NET_DISCONNECTED; | ||
} | ||
} else { | ||
// single network mode | ||
WiFi.begin(_ssid, _pass); | ||
_status = WS_NET_DISCONNECTED; | ||
WS.feedWDT(); | ||
delay(5000); | ||
} | ||
WS.feedWDT(); | ||
} | ||
} | ||
|
||
|
Uh oh!
There was an error while loading. Please reload this page.