wifi disconnect cleanup
This commit is contained in:
parent
80a694116a
commit
6db1dded52
@ -1,8 +1,10 @@
|
||||
#include "wifi.h"
|
||||
#include "log.h"
|
||||
#include "mqtt.h"
|
||||
|
||||
#include <WiFi.h>
|
||||
#include <ArduinoOTA.h>
|
||||
#include <lwip/apps/sntp.h>
|
||||
|
||||
#define NTP_SERVER "pool.ntp.org"
|
||||
|
||||
@ -31,15 +33,28 @@ void wifiSetup() {
|
||||
WiFi.setAutoReconnect(false);
|
||||
wifiConnect();
|
||||
otaSetup();
|
||||
configTime(TIMEZONE_OFFSET, DST_OFFSET, NTP_SERVER, WiFi.gatewayIP().toString().c_str());
|
||||
bootDelay();
|
||||
}
|
||||
|
||||
void wifiConnect() {
|
||||
WiFi.disconnect();
|
||||
yield();
|
||||
wifiConnected = false;
|
||||
wifiLastConnectTry = millis();
|
||||
|
||||
sntp_stop();
|
||||
ArduinoOTA.end();
|
||||
mqttDisconnect();
|
||||
|
||||
WiFi.disconnect();
|
||||
WiFi.enableAP(false);
|
||||
WiFi.setAutoConnect(false);
|
||||
WiFi.setAutoReconnect(false);
|
||||
yield();
|
||||
|
||||
info("WIFI", "Connecting WiFi: %s", WIFI_SSID);
|
||||
|
||||
WiFiClass::hostname(HOSTNAME);
|
||||
yield();
|
||||
|
||||
WiFi.begin(WIFI_SSID, WIFI_PKEY);
|
||||
yield();
|
||||
}
|
||||
@ -83,7 +98,6 @@ void otaSetup() {
|
||||
}
|
||||
error("OTA", name);
|
||||
});
|
||||
ArduinoOTA.begin();
|
||||
}
|
||||
|
||||
void bootDelay() {
|
||||
@ -122,11 +136,15 @@ void wifiLoop() {
|
||||
wifiConnected = false;
|
||||
info("WIFI", "WiFi disconnected!");
|
||||
wifiConnect();
|
||||
} else {
|
||||
ArduinoOTA.handle();
|
||||
}
|
||||
} else {
|
||||
if (hasIp) {
|
||||
wifiConnected = true;
|
||||
info("WIFI", "Connected as: %s", WiFi.localIP().toString().c_str());
|
||||
ArduinoOTA.begin();
|
||||
configTime(0, 0, WiFi.gatewayIP().toString().c_str(), "pool.ntp.org");
|
||||
} else if (millis() - wifiLastConnectTry > 10000) {
|
||||
info("WIFI", "WiFi timeout!");
|
||||
wifiConnect();
|
||||
|
||||
Loading…
Reference in New Issue
Block a user