OnDemandConfigPortal.ino 1.8 KB

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