AutoConnectWithReset.ino 1.4 KB

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