AutoConnectWithReset.ino 1.3 KB

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