-
Notifications
You must be signed in to change notification settings - Fork 1.9k
/
OnDemandWebPortal.ino
51 lines (42 loc) · 1.12 KB
/
OnDemandWebPortal.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/**
* 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() {
WiFi.mode(WIFI_STA); // explicitly set mode, esp defaults to STA+AP
// 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.stopWebPortal();
portalRunning = false;
}
}
}
}