AutoConnect.ino 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. #if defined(ESP8266)
  2. #include <ESP8266WiFi.h> //https://github.com/esp8266/Arduino
  3. #else
  4. #include <WiFi.h>
  5. #endif
  6. //needed for library
  7. #include <DNSServer.h>
  8. #include <ESPAsyncWebServer.h>
  9. #include <ESPAsyncWiFiManager.h> //https://github.com/tzapu/WiFiManager
  10. AsyncWebServer server(80);
  11. DNSServer dns;
  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. AsyncWiFiManager wifiManager(&server,&dns);
  18. //reset saved settings
  19. //wifiManager.resetSettings();
  20. //set custom ip for portal
  21. //wifiManager.setAPConfig(IPAddress(10,0,1,1), IPAddress(10,0,1,1), IPAddress(255,255,255,0));
  22. //fetches ssid and pass from eeprom 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. wifiManager.autoConnect("AutoConnectAP");
  27. //or use this for auto generated name ESP + ChipID
  28. //wifiManager.autoConnect();
  29. //if you get here you have connected to the WiFi
  30. Serial.println("connected...yeey :)");
  31. }
  32. void loop() {
  33. // put your main code here, to run repeatedly:
  34. }