From 7495fe2999dd695d45f3527002fb3c1a312cc2c6 Mon Sep 17 00:00:00 2001 From: Christopher Liebman Date: Sat, 24 Mar 2018 18:29:30 -0700 Subject: [PATCH] add setEnableConfigPortal(boolean enable) - if false dont open condig portal from autoConnect() --- WiFiManager.cpp | 21 ++++++++++++++++++++- WiFiManager.h | 3 +++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/WiFiManager.cpp b/WiFiManager.cpp index 694e16c56..31d562f3e 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -259,6 +259,12 @@ boolean WiFiManager::autoConnect(char const *apName, char const *apPassword) { } return true; } + + // possibly skip the config portal + if (!_enableConfigPortal) { + return false; + } + // not connected start configportal return startConfigPortal(apName, apPassword); } @@ -1931,6 +1937,19 @@ void WiFiManager::setScanDispPerc(boolean enabled){ _scanDispOptions = enabled; } +/** + * toggle configportal if autoconnect failed + * if enabled, then the configportal will be activated on autoconnect failure + * @since $dev + * @access public + * @param boolean enabled [true] + */ +void WiFiManager::setEnableConfigPortal(boolean enable) +{ + _enableConfigPortal = enable; +} + + /** * set the hostname (dhcp client id) * @since $dev @@ -2313,4 +2332,4 @@ void WiFiManager::WiFi_autoReconnect(){ WiFi.onEvent(WiFiEvent); } #endif -} \ No newline at end of file +} diff --git a/WiFiManager.h b/WiFiManager.h index 61f8a01f8..51bdb4ce6 100644 --- a/WiFiManager.h +++ b/WiFiManager.h @@ -204,6 +204,8 @@ class WiFiManager void setWiFiAutoReconnect(boolean enabled); // if true, wifiscan will show percentage instead of quality icons, until we have better templating void setScanDispPerc(boolean enabled); + // if true (default) then start the config portal from autoConnect if connection failed + void setEnableConfigPortal(boolean enable); // set a custom hostname, sets sta and ap dhcp client id for esp32, and sta for esp8266 bool setHostname(const char * hostname); // show erase wifi onfig button on info page, true @@ -292,6 +294,7 @@ class WiFiManager boolean _scanDispOptions = false; // show percentage in scans not icons boolean _paramsInWifi = true; // show custom parameters on wifi page boolean _showInfoErase = true; // info page erase button + boolean _enableConfigPortal = true; // use config portal if autoconnect failed const char * _hostname = ""; const char* _customHeadElement = ""; // store custom head element html from user