OnDemandConfigPortal.ino 1.8 KB

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