reworkgin examples

This commit is contained in:
Shawn A
2018-09-07 16:16:44 -05:00
parent 2610dcb2c5
commit 1e10ffa49a
4 changed files with 80 additions and 23 deletions
@@ -0,0 +1,46 @@
/**
* OnDemandConfigPortal.ino
* example of running the configPortal AP manually, independantly from the captiveportal
* trigger pin will start a configPortal AP 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
int timeout = 120; // seconds to run for
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
Serial.println("\n Starting");
pinMode(TRIGGER_PIN, INPUT_PULLUP);
}
void loop() {
// is configuration portal requested?
if ( digitalRead(TRIGGER_PIN) == LOW) {
WiFiManager wm;
//reset settings - for testing
//wifiManager.resetSettings();
// set configportal timeout
wm.setConfigPortalTimeout(timeout);
if (!wm.startConfigPortal("OnDemandAP")) {
Serial.println("failed to connect and hit timeout");
delay(3000);
//reset and try again, or maybe put it to deep sleep
ESP.restart();
delay(5000);
}
//if you get here you have connected to the WiFi
Serial.println("connected...yeey :)");
}
// put your main code here, to run repeatedly:
}
@@ -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;
}
}
}
}