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