From d7dd2153e79462b8e784278804f9a394077b6cca Mon Sep 17 00:00:00 2001 From: TKTF50 Date: Mon, 4 May 2020 13:47:34 -0400 Subject: [PATCH] Added preserveAPMode setting --- src/AutoConnect.cpp | 17 +++++++++++++---- src/AutoConnect.h | 4 ++++ 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/AutoConnect.cpp b/src/AutoConnect.cpp index a078a1c..de896ac 100644 --- a/src/AutoConnect.cpp +++ b/src/AutoConnect.cpp @@ -79,10 +79,19 @@ bool AutoConnect::begin(const char* ssid, const char* passphrase, unsigned long // Overwrite for the current timeout value. _connectTimeout = timeout; - // Start WiFi connection with station mode. - WiFi.softAPdisconnect(true); - WiFi.mode(WIFI_STA); - delay(100); + if (_apConfig.preserveAPMode && !_apConfig.autoRise) { + // Captive portal will not be started on connection failure. Enable Station mode + // without disabling any current soft AP. + cs = WiFi.enableSTA(true); + AC_DBG(PSTR("Enable WIFI_STA: %s\n"), cs ? "Ok" : "Failed"); + } + else { + // Start WiFi connection with station mode. + WiFi.softAPdisconnect(true); + cs = WiFi.mode(WIFI_STA); + delay(100); + AC_DBG(PSTR("Switch to WIFI_STA: %s\n"), cs ? "Ok" : "Failed"); + } // Set host name if (_apConfig.hostName.length()) diff --git a/src/AutoConnect.h b/src/AutoConnect.h index a483087..c996ca6 100644 --- a/src/AutoConnect.h +++ b/src/AutoConnect.h @@ -105,6 +105,7 @@ class AutoConnectConfig { autoReconnect(false), immediateStart(false), retainPortal(false), + preserveAPMode(false), portalTimeout(AUTOCONNECT_CAPTIVEPORTAL_TIMEOUT), menuItems(AC_MENUITEM_CONFIGNEW | AC_MENUITEM_OPENSSIDS | AC_MENUITEM_DISCONNECT | AC_MENUITEM_RESET | AC_MENUITEM_UPDATE | AC_MENUITEM_HOME), ticker(false), @@ -141,6 +142,7 @@ class AutoConnectConfig { autoReconnect(false), immediateStart(false), retainPortal(false), + preserveAPMode(false), portalTimeout(portalTimeout), menuItems(AC_MENUITEM_CONFIGNEW | AC_MENUITEM_OPENSSIDS | AC_MENUITEM_DISCONNECT | AC_MENUITEM_RESET | AC_MENUITEM_UPDATE | AC_MENUITEM_HOME), ticker(false), @@ -177,6 +179,7 @@ class AutoConnectConfig { autoReconnect = o.autoReconnect; immediateStart = o.immediateStart; retainPortal = o.retainPortal; + preserveAPMode = o.preserveAPMode; portalTimeout = o.portalTimeout; menuItems = o.menuItems; ticker = o.ticker; @@ -213,6 +216,7 @@ class AutoConnectConfig { bool autoReconnect; /**< Automatic reconnect with past SSID */ bool immediateStart; /**< Skips WiFi.begin(), start portal immediately */ bool retainPortal; /**< Even if the captive portal times out, it maintains the portal state. */ + bool preserveAPMode; /**< Keep existing AP WiFi mode if captive portal won't be started. */ unsigned long portalTimeout; /**< Timeout value for stay in the captive portal */ uint16_t menuItems; /**< A compound value of the menu items to be attached */ bool ticker; /**< Drives LED flicker according to WiFi connection status. */