BOOT_DELAY FIX
This commit is contained in:
parent
33a8ad6198
commit
f56ceca031
@ -1,6 +1,7 @@
|
||||
#include "wifi.h"
|
||||
#include "log.h"
|
||||
#include "mqtt.h"
|
||||
#include "console.h"
|
||||
|
||||
#include <WiFi.h>
|
||||
#include <ArduinoOTA.h>
|
||||
@ -14,6 +15,10 @@
|
||||
|
||||
#define MIN_EPOCH_SECONDS 1712675973
|
||||
|
||||
#define BOOT_DELAY_MS (10 * 1000)
|
||||
|
||||
#define WIFI_TIMEOUT_MS (15 * 1000)
|
||||
|
||||
uint8_t otaLastLogStep = 0;
|
||||
|
||||
bool wifiConnected = false;
|
||||
@ -50,7 +55,7 @@ void wifiConnect() {
|
||||
WiFi.setAutoReconnect(false);
|
||||
yield();
|
||||
|
||||
info("WIFI", "Connecting WiFi: %s", WIFI_SSID);
|
||||
info("WIFI", "Connecting: %s", WIFI_SSID);
|
||||
|
||||
WiFiClass::hostname(HOSTNAME);
|
||||
yield();
|
||||
@ -101,22 +106,23 @@ void otaSetup() {
|
||||
}
|
||||
|
||||
void bootDelay() {
|
||||
#ifdef BOOT_DELAY
|
||||
info("BOOT DELAY", "Waiting for WiFi...");
|
||||
while ((uint32_t) WiFi.localIP() == 0) {
|
||||
delay(100);
|
||||
yield();
|
||||
wifiLoop();
|
||||
}
|
||||
info("BOOT DELAY", "WiFi connected!");
|
||||
unsigned long begin = millis();
|
||||
while (millis() - begin < 10000) {
|
||||
delay(100);
|
||||
yield();
|
||||
wifiLoop();
|
||||
}
|
||||
info("BOOT DELAY", "Boot delay completed!");
|
||||
#if !BOOT_DELAY
|
||||
return;
|
||||
#endif
|
||||
info("BOOT DELAY", "BOOT DELAY: Waiting for WiFi...");
|
||||
while ((uint32_t) WiFi.localIP() == 0) {
|
||||
consoleLoop();
|
||||
wifiLoop();
|
||||
}
|
||||
info("BOOT DELAY", "BOOT DELAY: WiFi connected!");
|
||||
info("BOOT DELAY", "BOOT DELAY: Waiting 10 seconds...");
|
||||
unsigned long bootDelayBegin = millis();
|
||||
while (millis() - bootDelayBegin < BOOT_DELAY_MS) {
|
||||
consoleLoop();
|
||||
wifiLoop();
|
||||
}
|
||||
info("BOOT DELAY", "BOOT DELAY: Complete!");
|
||||
info("BOOT DELAY", "BOOT DELAY: Resuming normal boot!");
|
||||
}
|
||||
|
||||
void wifiLoop() {
|
||||
@ -142,10 +148,10 @@ void wifiLoop() {
|
||||
} else {
|
||||
if (hasIp) {
|
||||
wifiConnected = true;
|
||||
info("WIFI", "Connected as: %s", WiFi.localIP().toString().c_str());
|
||||
info("WIFI", "Connected: ip=%s", WiFi.localIP().toString().c_str());
|
||||
ArduinoOTA.begin();
|
||||
configTime(0, 0, WiFi.gatewayIP().toString().c_str(), "pool.ntp.org");
|
||||
} else if (millis() - wifiLastConnectTry > 10000) {
|
||||
configTime(TIMEZONE_OFFSET, DST_OFFSET, WiFi.gatewayIP().toString().c_str(), NTP_SERVER);
|
||||
} else if (millis() - wifiLastConnectTry > WIFI_TIMEOUT_MS) {
|
||||
info("WIFI", "WiFi timeout!");
|
||||
wifiConnect();
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user