AutoConnectWithFeedback.ino 1.5 KB

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