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