OnDemandConfigPortal.ino 1.8 KB

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