From f56ceca0318a7793a18166a5095d5493c024dd34 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrick=20Ha=C3=9Fel?= Date: Wed, 10 Apr 2024 12:52:36 +0200 Subject: [PATCH] BOOT_DELAY FIX --- lib/patrix/wifi.cpp | 44 +++++++++++++++++++++++++------------------- 1 file changed, 25 insertions(+), 19 deletions(-) diff --git a/lib/patrix/wifi.cpp b/lib/patrix/wifi.cpp index 1deadb1..1162335 100644 --- a/lib/patrix/wifi.cpp +++ b/lib/patrix/wifi.cpp @@ -1,6 +1,7 @@ #include "wifi.h" #include "log.h" #include "mqtt.h" +#include "console.h" #include #include @@ -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(); }