AutoConnectWithReset.ino 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #include <FS.h> //this needs to be first, or it all crashes and burns...
  2. #if defined(ESP8266)
  3. #include <ESP8266WiFi.h> //https://github.com/esp8266/Arduino
  4. #else
  5. #include <WiFi.h>
  6. #endif
  7. //needed for library
  8. #include <ESPAsyncDNSServer.h> //https://github.com/devyte/ESPAsyncDNSServer
  9. //https://github.com/me-no-dev/ESPAsyncUDP
  10. #include <ESPAsyncWebServer.h>
  11. #include <ESPAsyncWiFiManager.h> //https://github.com/tzapu/WiFiManager
  12. AsyncWebServer server(80);
  13. AsyncDNSServer dns;
  14. void setup() {
  15. // put your setup code here, to run once:
  16. Serial.begin(115200);
  17. Serial.println();
  18. //WiFiManager
  19. //Local intialization. Once its business is done, there is no need to keep it around
  20. AsyncWiFiManager wifiManager(&server,&dns);
  21. //exit after config instead of connecting
  22. wifiManager.setBreakAfterConfig(true);
  23. //reset settings - for testing
  24. //wifiManager.resetSettings();
  25. //tries to connect to last known settings
  26. //if it does not connect it starts an access point with the specified name
  27. //here "AutoConnectAP" with password "password"
  28. //and goes into a blocking loop awaiting configuration
  29. if (!wifiManager.autoConnect("AutoConnectAP", "password")) {
  30. Serial.println("failed to connect, we should reset as see if it connects");
  31. delay(3000);
  32. ESP.reset();
  33. delay(5000);
  34. }
  35. //if you get here you have connected to the WiFi
  36. Serial.println("connected...yeey :)");
  37. Serial.println("local ip");
  38. Serial.println(WiFi.localIP());
  39. }
  40. void loop() {
  41. // put your main code here, to run repeatedly:
  42. }