AutoConnectWithReset.ino 1.2 KB

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