mirror of
https://github.com/alexhopeoconnor/WiFiManager.git
synced 2026-10-04 02:48:13 +10:00
reworkgin examples
This commit is contained in:
@@ -58,6 +58,7 @@ void setup() {
|
||||
|
||||
if(!res) {
|
||||
Serial.println("Failed to connect or hit timeout");
|
||||
// ESP.restart();
|
||||
}
|
||||
else {
|
||||
//if you get here you have connected to the WiFi
|
||||
@@ -65,33 +66,38 @@ void setup() {
|
||||
}
|
||||
}
|
||||
|
||||
void loop() {
|
||||
void checkButton(){
|
||||
// check for button press
|
||||
if ( digitalRead(TRIGGER_PIN) == LOW ) {
|
||||
// poor mans debounce, not recommended for production code
|
||||
// poor mans debounce/press-hold, not recommended for production code
|
||||
delay(50);
|
||||
if( digitalRead(TRIGGER_PIN) == LOW ){
|
||||
|
||||
delay(3000); // reset timer
|
||||
if( digitalRead(TRIGGER_PIN) == LOW ){
|
||||
Serial.println("Erasing Config");
|
||||
// holding button 3000 ms, reset settings
|
||||
wm.resetSettings();
|
||||
ESP.restart();
|
||||
}
|
||||
|
||||
Serial.println("Starting config portal");
|
||||
wm.setConfigPortalTimeout(120);
|
||||
|
||||
if (!wm.startConfigPortal("OnDemandAP")) {
|
||||
Serial.println("failed to connect or hit timeout");
|
||||
delay(3000);
|
||||
} else {
|
||||
//if you get here you have connected to the WiFi
|
||||
Serial.println("connected...yeey :)");
|
||||
delay(3000); // reset delay hold
|
||||
if( digitalRead(TRIGGER_PIN) == LOW ){
|
||||
Serial.println("Erasing Config");
|
||||
wm.resetSettings();
|
||||
ESP.restart();
|
||||
}
|
||||
|
||||
// start portal w delay
|
||||
Serial.println("Starting config portal");
|
||||
wm.setConfigPortalTimeout(120);
|
||||
|
||||
if (!wm.startConfigPortal("OnDemandAP")) {
|
||||
Serial.println("failed to connect or hit timeout");
|
||||
delay(3000);
|
||||
// ESP.restart();
|
||||
} else {
|
||||
//if you get here you have connected to the WiFi
|
||||
Serial.println("connected...yeey :)");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void loop() {
|
||||
checkButton();
|
||||
// put your main code here, to run repeatedly:
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
/**
|
||||
* OnDemandWebPortal.ino
|
||||
* example of running the webportal or configportal manually and no blocking
|
||||
* OnDemandNonBlocking.ino
|
||||
* example of running the webportal or configportal manually and non blocking
|
||||
* trigger pin will start a webportal for 120 seconds then turn it off.
|
||||
* startCP = true will start the configportal AP and webportal
|
||||
* startCP = true will start both the configportal AP and webportal
|
||||
*/
|
||||
#include <WiFiManager.h> // https://github.com/tzapu/WiFiManager
|
||||
|
||||
@@ -46,11 +46,12 @@ void doWiFiManager(){
|
||||
|
||||
// is configuration portal requested?
|
||||
if(digitalRead(TRIGGER_PIN) == LOW && (!portalRunning)) {
|
||||
Serial.println("Button Pressed, Starting Portal");
|
||||
if(startCP){
|
||||
Serial.println("Button Pressed, Starting Config Portal");
|
||||
wm.startConfigPortal();
|
||||
}
|
||||
else{
|
||||
Serial.println("Button Pressed, Starting Web Portal");
|
||||
wm.startWebPortal();
|
||||
}
|
||||
portalRunning = true;
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
/**
|
||||
* OnDemandWebPortal.ino
|
||||
* example of running the webportal (always NON blocking)
|
||||
*/
|
||||
#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;
|
||||
|
||||
bool portalRunning = false;
|
||||
|
||||
void setup() {
|
||||
// put your setup code here, to run once
|
||||
Serial.begin(115200);
|
||||
Serial.println("\n Starting");
|
||||
pinMode(TRIGGER_PIN, INPUT_PULLUP);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
checkButton();
|
||||
// put your main code here, to run repeatedly:
|
||||
}
|
||||
|
||||
void checkButton(){
|
||||
// is auto timeout portal running
|
||||
if(portalRunning){
|
||||
wm.process();
|
||||
}
|
||||
|
||||
// is configuration portal requested?
|
||||
if(digitalRead(TRIGGER_PIN) == LOW) {
|
||||
delay(50)
|
||||
if(digitalRead(TRIGGER_PIN) == LOW) {
|
||||
if(!portalRunning){
|
||||
Serial.println("Button Pressed, Starting Portal");
|
||||
wm.startWebPortal();
|
||||
portalRunning = true;
|
||||
}
|
||||
else{
|
||||
Serial.println("Button Pressed, Stopping Portal");
|
||||
wm.startWebPortal();
|
||||
portalRunning = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user