onDemandWebPortal.ino 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. /**
  2. * OnDemandWebPortal.ino
  3. * example of running the webportal (always NON blocking)
  4. */
  5. #include <WiFiManager.h> // https://github.com/tzapu/WiFiManager
  6. // select which pin will trigger the configuration portal when set to LOW
  7. #define TRIGGER_PIN 0
  8. WiFiManager wm;
  9. bool portalRunning = false;
  10. void setup() {
  11. WiFi.mode(WIFI_STA); // explicitly set mode, esp defaults to STA+AP
  12. // put your setup code here, to run once
  13. Serial.begin(115200);
  14. Serial.println("\n Starting");
  15. pinMode(TRIGGER_PIN, INPUT_PULLUP);
  16. }
  17. void loop() {
  18. checkButton();
  19. // put your main code here, to run repeatedly:
  20. }
  21. void checkButton(){
  22. // is auto timeout portal running
  23. if(portalRunning){
  24. wm.process();
  25. }
  26. // is configuration portal requested?
  27. if(digitalRead(TRIGGER_PIN) == LOW) {
  28. delay(50);
  29. if(digitalRead(TRIGGER_PIN) == LOW) {
  30. if(!portalRunning){
  31. Serial.println("Button Pressed, Starting Portal");
  32. wm.startWebPortal();
  33. portalRunning = true;
  34. }
  35. else{
  36. Serial.println("Button Pressed, Stopping Portal");
  37. wm.startWebPortal();
  38. portalRunning = false;
  39. }
  40. }
  41. }
  42. }