AutoConnectWithReset.ino 1.4 KB

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