OnDemandConfigPortal.ino 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. #include <ESP8266WiFi.h> //https://github.com/esp8266/Arduino
  2. //needed for library
  3. #include <ESP8266WebServer.h>
  4. #include <DNSServer.h>
  5. #include <WiFiManager.h> //https://github.com/tzapu/WiFiManager
  6. // select wich pin will trigger the configuraton portal when set to LOW
  7. // ESP-01 users please note: the only pins available (0 and 2), are shared
  8. // with the bootloader, so always set them HIGH at power-up
  9. #define TRIGGER_PIN 0
  10. void setup() {
  11. // put your setup code here, to run once:
  12. Serial.begin(115200);
  13. Serial.println("\n Starting");
  14. pinMode(TRIGGER_PIN, INPUT);
  15. }
  16. void loop() {
  17. // is configuration portal requested?
  18. if ( digitalRead(TRIGGER_PIN) == LOW ) {
  19. //WiFiManager
  20. //Local intialization. Once its business is done, there is no need to keep it around
  21. WiFiManager wifiManager;
  22. //reset settings - for testing
  23. //wifiManager.resetSettings();
  24. //sets timeout until configuration portal gets turned off
  25. //useful to make it all retry or go to sleep
  26. //in seconds
  27. //wifiManager.setTimeout(120);
  28. //it starts an access point with the specified name
  29. //here "AutoConnectAP"
  30. //and goes into a blocking loop awaiting configuration
  31. //WITHOUT THIS THE AP DOES NOT SEEM TO WORK PROPERLY WITH SDK 1.5 , update to at least 1.5.1
  32. //WiFi.mode(WIFI_STA);
  33. if (!wifiManager.startConfigPortal("OnDemandAP")) {
  34. Serial.println("failed to connect and hit timeout");
  35. delay(3000);
  36. //reset and try again, or maybe put it to deep sleep
  37. ESP.reset();
  38. delay(5000);
  39. }
  40. //if you get here you have connected to the WiFi
  41. Serial.println("connected...yeey :)");
  42. }
  43. // put your main code here, to run repeatedly:
  44. }