diff --git a/WiFiManager.cpp b/WiFiManager.cpp index c7303e3..e92c1ee 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -445,8 +445,8 @@ void WiFiManager::setupConfigPortal() { dnsServer->start(DNS_PORT, F("*"), WiFi.softAPIP()); /* Setup httpd callbacks, web pages: root, wifi config pages, SO captive portal detectors and not found. */ - server->on(String(FPSTR(R_wifi)).c_str(), std::bind(&WiFiManager::handleWifi, this, true)); server->on(String(FPSTR(R_root)).c_str(), std::bind(&WiFiManager::handleRoot, this)); + server->on(String(FPSTR(R_wifi)).c_str(), std::bind(&WiFiManager::handleWifi, this, true)); server->on(String(FPSTR(R_wifinoscan)).c_str(), std::bind(&WiFiManager::handleWifi, this, false)); server->on(String(FPSTR(R_wifisave)).c_str(), std::bind(&WiFiManager::handleWifiSave, this)); server->on(String(FPSTR(R_info)).c_str(), std::bind(&WiFiManager::handleInfo, this)); diff --git a/examples/DEV/OnDemandConfigPortal/OnDemandConfigPortal.ino b/examples/DEV/OnDemandConfigPortal/OnDemandConfigPortal.ino index b7f495f..d209f31 100644 --- a/examples/DEV/OnDemandConfigPortal/OnDemandConfigPortal.ino +++ b/examples/DEV/OnDemandConfigPortal/OnDemandConfigPortal.ino @@ -54,7 +54,8 @@ void setup() { Serial.setDebugOutput(true); // delay(3000); Serial.println("\n Starting"); - + WiFi.setSleepMode(WIFI_NONE_SLEEP); + //WiFiManager //Local intialization. Once its business is done, there is no need to keep it around // WiFiManager wm; diff --git a/examples/AutoConnect/AutoConnectNonBlocking/AutoConnectNonBlocking.ino b/examples/NonBlocking/AutoConnectNonBlocking/AutoConnectNonBlocking.ino similarity index 100% rename from examples/AutoConnect/AutoConnectNonBlocking/AutoConnectNonBlocking.ino rename to examples/NonBlocking/AutoConnectNonBlocking/AutoConnectNonBlocking.ino diff --git a/examples/NonBlocking/OnDemandNonBlocking/onDemandNonBlocking.ino b/examples/NonBlocking/OnDemandNonBlocking/onDemandNonBlocking.ino new file mode 100644 index 0000000..c250038 --- /dev/null +++ b/examples/NonBlocking/OnDemandNonBlocking/onDemandNonBlocking.ino @@ -0,0 +1,61 @@ +/** + * OnDemandWebPortal.ino + * example of running the webportal or configportal manually and no blocking + * trigger pin will start a webportal for 120 seconds then turn it off. + * startCP = true will start the configportal AP and webportal + */ +#include // https://github.com/tzapu/WiFiManager + +// select which pin will trigger the configuration portal when set to LOW +#define TRIGGER_PIN 0 + +WiFiManager wm; + +unsigned int timeout = 120; // seconds to run for +unsigned int startTime = millis(); +bool portalRunning = false; +bool startCP = false; // start AP and webserver if true, else start only webserver + +void setup() { + // put your setup code here, to run once + Serial.begin(115200); + Serial.println("\n Starting"); + pinMode(TRIGGER_PIN, INPUT_PULLUP); +} + +void loop() { + doWiFiManager(); + // put your main code here, to run repeatedly: +} + +void doWiFiManager(){ + // is auto timeout portal running + if(portalRunning){ + wm.process(); + if((millis()-startTime) > (timeout*1000)){ + Serial.println("portaltimeout"); + portalRunning = false; + if(startCP){ + wm.stopConfigPortal(); + } + else{ + wm.stopWebPortal(); + } + } + } + + // is configuration portal requested? + if(digitalRead(TRIGGER_PIN) == LOW && (!portalRunning)) { + Serial.println("Button Pressed, Starting Portal"); + if(startCP){ + wm.startConfigPortal(); + } + else{ + wm.startWebPortal(); + } + portalRunning = true; + startTime = millis(); + } +} + + diff --git a/examples/OnDemandConfigPortal/OnDemandConfigPortal.ino b/examples/OnDemandConfigPortal/OnDemandConfigPortal.ino index 357276b..e9252c3 100644 --- a/examples/OnDemandConfigPortal/OnDemandConfigPortal.ino +++ b/examples/OnDemandConfigPortal/OnDemandConfigPortal.ino @@ -9,8 +9,7 @@ // select which pin will trigger the configuration portal when set to LOW #define TRIGGER_PIN 0 -int timeout = 120; // seconds to run for -bool webportalrunning = false; +int timeout = 120; // seconds to run for void setup() { // put your setup code here, to run once: diff --git a/examples/OnDemandWebPortal/OnDemandWebPortal.ino b/examples/OnDemandWebPortal/OnDemandWebPortal.ino deleted file mode 100644 index 07f61e9..0000000 --- a/examples/OnDemandWebPortal/OnDemandWebPortal.ino +++ /dev/null @@ -1,43 +0,0 @@ -/** - * OnDemandWebPortal.ino - * example of running the webportal manually, independantly from the captiveportal - * trigger pin will start a webportal for 120 seconds then turn it off. - * - */ -#include // https://github.com/tzapu/WiFiManager - -// select which pin will trigger the configuration portal when set to LOW -#define TRIGGER_PIN 0 - -WiFiManager wm; - -int timeout = 120; // seconds to run for -bool webportalrunning = false; -int start = millis(); - -void setup() { - // put your setup code here, to run once: - Serial.begin(115200); - Serial.println("\n Starting"); - pinMode(TRIGGER_PIN, INPUT_PULLUP); -} - - -void loop() { - if(webportalrunning){ - wm.process(); - if(millis()-start > timeout*1000){ - Serial.println("webportaltimeout"); - webportalrunning = false; - wm.stopWebPortal(); // auto off - } - } - // is configuration portal requested? - if ( digitalRead(TRIGGER_PIN) == LOW && !webportalrunning) { - wm.startWebPortal(); - // wm.startWebPortal(); - webportalrunning = true; - start = millis(); - } - // put your main code here, to run repeatedly: -}