OnDemandConfigPortal.ino 2.0 KB

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