OnDemandConfigPortal.ino 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. /**
  2. * OnDemandConfigPortal.ino
  3. * example of running the configPortal AP manually, independantly from the captiveportal
  4. * trigger pin will start a configPortal AP for 120 seconds then turn it off.
  5. *
  6. */
  7. #include <WiFiManager.h> // https://github.com/tzapu/WiFiManager
  8. // select which pin will trigger the configuration portal when set to LOW
  9. #define TRIGGER_PIN 0
  10. int timeout = 120; // seconds to run for
  11. void setup() {
  12. WiFi.mode(WIFI_STA); // explicitly set mode, esp defaults to STA+AP
  13. // put your setup code here, to run once:
  14. Serial.begin(115200);
  15. Serial.println("\n Starting");
  16. pinMode(TRIGGER_PIN, INPUT_PULLUP);
  17. }
  18. void loop() {
  19. // is configuration portal requested?
  20. if ( digitalRead(TRIGGER_PIN) == LOW) {
  21. WiFiManager wm;
  22. //reset settings - for testing
  23. //wifiManager.resetSettings();
  24. // set configportal timeout
  25. wm.setConfigPortalTimeout(timeout);
  26. if (!wm.startConfigPortal("OnDemandAP")) {
  27. Serial.println("failed to connect and hit timeout");
  28. delay(3000);
  29. //reset and try again, or maybe put it to deep sleep
  30. ESP.restart();
  31. delay(5000);
  32. }
  33. //if you get here you have connected to the WiFi
  34. Serial.println("connected...yeey :)");
  35. }
  36. // put your main code here, to run repeatedly:
  37. }