AutoConnectWithFeedback.ino 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. #include <WiFiManager.h> // https://github.com/tzapu/WiFiManager
  2. void configModeCallback (WiFiManager *myWiFiManager) {
  3. Serial.println("Entered config mode");
  4. Serial.println(WiFi.softAPIP());
  5. //if you used auto generated SSID, print it
  6. Serial.println(myWiFiManager->getConfigPortalSSID());
  7. }
  8. void setup() {
  9. // put your setup code here, to run once:
  10. Serial.begin(115200);
  11. //WiFiManager
  12. //Local intialization. Once its business is done, there is no need to keep it around
  13. WiFiManager wifiManager;
  14. //reset settings - for testing
  15. //wifiManager.resetSettings();
  16. //set callback that gets called when connecting to previous WiFi fails, and enters Access Point mode
  17. wifiManager.setAPCallback(configModeCallback);
  18. //fetches ssid and pass and tries to connect
  19. //if it does not connect it starts an access point with the specified name
  20. //here "AutoConnectAP"
  21. //and goes into a blocking loop awaiting configuration
  22. if(!wifiManager.autoConnect()) {
  23. Serial.println("failed to connect and hit timeout");
  24. //reset and try again, or maybe put it to deep sleep
  25. ESP.restart();
  26. delay(1000);
  27. }
  28. //if you get here you have connected to the WiFi
  29. Serial.println("connected...yeey :)");
  30. }
  31. void loop() {
  32. // put your main code here, to run repeatedly:
  33. }