From f2580463e43bc1bc8f1e929916c52e36edcb6c7f Mon Sep 17 00:00:00 2001 From: Shawn A Date: Sun, 27 Aug 2017 10:55:26 -0500 Subject: [PATCH] fix const char corruptions #400 fixing non blocking, non blocking does not handle timeouts for the user --- WiFiManager.cpp | 27 ++++++++++++++++----------- WiFiManager.h | 6 +++--- 2 files changed, 19 insertions(+), 14 deletions(-) diff --git a/WiFiManager.cpp b/WiFiManager.cpp index a0428e8..b43feae 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -133,11 +133,11 @@ bool WiFiManager::startAP(){ bool ret = true; // start soft AP with password or anonymous - if (_apPassword != NULL) { - ret = WiFi.softAP(_apName, _apPassword);//password option + if (_apPassword != "") { + ret = WiFi.softAP(_apName.c_str(), _apPassword.c_str());//password option } else { DEBUG_WM(F("AP has anonymous access")); - ret = WiFi.softAP(_apName); + ret = WiFi.softAP(_apName.c_str()); } delay(500); // slight delay to make sure we get an AP IP @@ -205,7 +205,7 @@ boolean WiFiManager::startConfigPortal(char const *apName, char const *apPasswo DEBUG_WM("Enabling AP"); - _apName = apName; + _apName = apName; // @todo check valid apname ? _apPassword = apPassword; if(!validApPassword()) return false; @@ -217,8 +217,12 @@ boolean WiFiManager::startConfigPortal(char const *apName, char const *apPasswo uint8_t state; bool result = false; - if(!_configPortalIsBlocking) return result; + if(!_configPortalIsBlocking){ + DEBUG_WM(F("Config Portal Running, non blocking/processing")); + return result; + } + DEBUG_WM(F("Config Portal Running, blocking")); // blocking loop waiting for config while(1){ @@ -815,7 +819,8 @@ void WiFiManager::handleNotFound() { * Return true in that case so the page handler do not try to handle the request again. */ boolean WiFiManager::captivePortal() { - if (!isIp(server->hostHeader()) ) { +DEBUG_WM(server->hostHeader()); + if (!isIp(server->hostHeader()) && false) { DEBUG_WM(F("Request redirected to captive portal")); server->sendHeader("Location", String("http://") + toStringIp(server->client().localIP()), true); server->send ( 302, "text/plain", ""); // Empty content inhibits Content-length header so we have to close the socket ourselves. @@ -893,12 +898,12 @@ String WiFiManager::toStringIp(IPAddress ip) { boolean WiFiManager::validApPassword(){ // check that ap password is valid, return false - if (_apPassword == "") _apPassword = NULL; - if (_apPassword != NULL) { - if (strlen(_apPassword) < 8 || strlen(_apPassword) > 63) { + if (_apPassword == NULL) _apPassword = ""; + if (_apPassword != "") { + if (_apPassword.length() < 8 || _apPassword.length() > 63) { DEBUG_WM(F("AccessPoint set password is INVALID")); - _apPassword = NULL; - return false; // @todo FATAL or fallback to NULL ? + _apPassword = ""; + return false; // @todo FATAL or fallback to empty ? } DEBUG_WM(F("AccessPoint set password is VALID")); DEBUG_WM(_apPassword); diff --git a/WiFiManager.h b/WiFiManager.h index eb56a04..d156ecf 100644 --- a/WiFiManager.h +++ b/WiFiManager.h @@ -134,8 +134,8 @@ class WiFiManager void startWPS(); bool startAP(); - const char* _apName = "no-net"; - const char* _apPassword = NULL; + String _apName = "no-net"; + String _apPassword = ""; String _ssid = ""; String _pass = ""; unsigned long _configPortalTimeout = 0; @@ -155,7 +155,7 @@ class WiFiManager boolean _removeDuplicateAPs = true; boolean _shouldBreakAfterConfig = false; boolean _tryWPS = false; - boolean _configPortalIsBlocking = true; + boolean _configPortalIsBlocking = false; const char* _customHeadElement = "";