12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
- #include <WiFiManager.h> // https://github.com/tzapu/WiFiManager
- #define TRIGGER_PIN 0
- WiFiManager wm;
- unsigned int timeout = 120;
- unsigned int startTime = millis();
- bool portalRunning = false;
- bool startAP = false;
- void setup() {
- WiFi.mode(WIFI_STA);
-
- Serial.begin(115200);
- Serial.println("\n Starting");
- pinMode(TRIGGER_PIN, INPUT_PULLUP);
- }
- void loop() {
- doWiFiManager();
-
- }
- void doWiFiManager(){
-
- if(portalRunning){
- wm.process();
- if((millis()-startTime) > (timeout*1000)){
- Serial.println("portaltimeout");
- portalRunning = false;
- if(startAP){
- wm.stopConfigPortal();
- }
- else{
- wm.stopWebPortal();
- }
- }
- }
-
- if(digitalRead(TRIGGER_PIN) == LOW && (!portalRunning)) {
- if(startAP){
- Serial.println("Button Pressed, Starting Config Portal");
- wm.setConfigPortalBlocking(false);
- wm.startConfigPortal();
- }
- else{
- Serial.println("Button Pressed, Starting Web Portal");
- wm.startWebPortal();
- }
- portalRunning = true;
- startTime = millis();
- }
- }
|