mirror of
https://github.com/alexhopeoconnor/WiFiManager.git
synced 2026-10-13 14:51:21 +10:00
non blocking examples
This commit is contained in:
+1
-1
@@ -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));
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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 <WiFiManager.h> // 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();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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 <WiFiManager.h> // 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:
|
||||
}
|
||||
Reference in New Issue
Block a user