From e71963d43988e7ae3359d3fa5c8e06073c581a33 Mon Sep 17 00:00:00 2001
From: Darrell
Date: Tue, 6 Sep 2022 10:57:30 -0400
Subject: [PATCH] Make portal timeout configurable (#658)
---
platformio.ini | 2 +-
src/defaults.h | 11 ++++++++---
src/main.cpp | 38 +++++++++++++++++++-------------------
3 files changed, 28 insertions(+), 23 deletions(-)
diff --git a/platformio.ini b/platformio.ini
index 7b875bd..de875a5 100644
--- a/platformio.ini
+++ b/platformio.ini
@@ -37,7 +37,7 @@ framework = arduino
lib_deps =
AsyncTCP = https://github.com/pbolduc/AsyncTCP.git@^1.2.0
https://github.com/ESPresense/ESPAsyncWebServer.git
- https://github.com/ESPresense/AsyncWiFiSettings.git#1.0.2
+ https://github.com/ESPresense/AsyncWiFiSettings.git#1.0.3
https://github.com/ESPresense/SoftFilters.git
https://github.com/ESPresense/NimBLE-Arduino.git
marvinroger/AsyncMqttClient@^0.9.0
diff --git a/src/defaults.h b/src/defaults.h
index be7f6b5..b976141 100644
--- a/src/defaults.h
+++ b/src/defaults.h
@@ -5,9 +5,14 @@
#define CHECK_FOR_UPDATES_INTERVAL 900000
#endif
-// Number of ms to keep up captive portal before retrying connecting
-#ifndef CAPTIVE_PORTAL_TIMEOUT
-#define CAPTIVE_PORTAL_TIMEOUT 300000
+// Number of seconds to wait for a Station Wifi connection to be established
+#ifndef DEFAULT_WIFI_TIMEOUT
+#define DEFAULT_WIFI_TIMEOUT 120
+#endif
+
+// Number of seconds to keep up captive portal (SoftAP) before rebooting
+#ifndef DEFAULT_PORTAL_TIMEOUT
+#define DEFAULT_PORTAL_TIMEOUT 300
#endif
#define UPDATE_STARTED -255
diff --git a/src/main.cpp b/src/main.cpp
index 727d545..aa0efac 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -114,29 +114,12 @@ void setupNetwork() {
WiFi.setScanMethod(WIFI_ALL_CHANNEL_SCAN);
GUI::Connected(false, false);
- unsigned int connectProgress = 0;
- AsyncWiFiSettings.onWaitLoop = [&connectProgress]() {
- GUI::Wifi(connectProgress++);
- SerialImprov::Loop(true);
- return 50;
- };
- unsigned int portalProgress = 0;
- AsyncWiFiSettings.onPortalWaitLoop = [&portalProgress]() {
- GUI::Portal(portalProgress++);
- SerialImprov::Loop(false);
-
- if (millis() > CAPTIVE_PORTAL_TIMEOUT)
- ESP.restart();
-
- return 50;
- };
- AsyncWiFiSettings.onHttpSetup = HttpWebServer::Init;
-
#ifdef VERSION
AsyncWiFiSettings.info("ESPresense Version: " + String(VERSION));
#endif
room = AsyncWiFiSettings.string("room", ESPMAC, "Room");
- auto wifiTimeout = AsyncWiFiSettings.integer("wifi_timeout", 45, "Seconds to wait for WiFi before captive portal (-1 = forever)");
+ auto wifiTimeout = AsyncWiFiSettings.integer("wifi_timeout", DEFAULT_WIFI_TIMEOUT, "Seconds to wait for WiFi before captive portal (-1 = forever)");
+ auto portalTimeout = 1000UL * AsyncWiFiSettings.integer("portal_timeout", DEFAULT_PORTAL_TIMEOUT, "Seconds to wait in captive portal before rebooting");
std::vector ethernetTypes = {"None", "WT32-ETH01", "ESP32-POE", "WESP32", "QuinLED-ESP32", "TwilightLord-ESP32", "ESP32Deux", "KIT-VE", "LilyGO-T-ETH-POE"};
ethernetType = AsyncWiFiSettings.dropdown("eth", ethernetTypes, 0, "Ethernet Type");
@@ -200,6 +183,23 @@ void setupNetwork() {
#endif
+ unsigned int connectProgress = 0;
+ AsyncWiFiSettings.onWaitLoop = [&connectProgress]() {
+ GUI::Wifi(connectProgress++);
+ SerialImprov::Loop(true);
+ return 50;
+ };
+ unsigned int portalProgress = 0;
+ AsyncWiFiSettings.onPortalWaitLoop = [&portalProgress, portalTimeout]() {
+ GUI::Portal(portalProgress++);
+ SerialImprov::Loop(false);
+
+ if (millis() > portalTimeout)
+ ESP.restart();
+
+ return 50;
+ };
+ AsyncWiFiSettings.onHttpSetup = HttpWebServer::Init;
AsyncWiFiSettings.hostname = "espresense-" + kebabify(room);
bool success = false;