AutoConnectWithFeedback.ino 1.4 KB

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