-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathx40_wifi.ino
44 lines (34 loc) · 1.07 KB
/
x40_wifi.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
WiFiEventHandler wifiIpHandler;
void wifiSetup() {
if (WiFi.getAutoConnect()) WiFi.setAutoConnect(false);
if (WiFi.getMode() != WIFI_STA) WiFi.mode(WIFI_STA);
logInfo("Connecting...");
ledSetState(LED_FAST_BLINK);
wifiIpHandler = WiFi.onStationModeGotIP([](const WiFiEventStationModeGotIP & evt) {
// this executes when module reconnects and gets IP from DHCP
// can be called multiple times
logValue("Got IP: ", evt.ip);
});
if (WiFi.SSID() == "") {
logInfo("No saved credentials");
ledSetState(LED_SLOW_BLINK);
WiFiManager wifiManager;
String ap = WIFI_AP_NAME;
ap += chipId;
if (!wifiManager.startConfigPortal(ap.c_str())) {
logInfo("Failed to connect or setup, rebooting...");
delay(1000);
ESP.reset();
while (1) delay(1);
}
} else if (!WiFi.isConnected()) { // calling WiFi.begin when already connected does all kind of weird stuff
logValue("Stored SSID: ", WiFi.SSID());
WiFi.begin();
}
}
void wifiReset() {
WiFi.disconnect(true);
delay(1000);
ESP.reset();
while (1) delay(1);
}