PersWiFiManager.h 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. #ifndef PERSWIFIMANAGER_H
  2. #define PERSWIFIMANAGER_H
  3. #include <ESP8266WiFi.h>
  4. #include <ESP8266WebServer.h>
  5. #include <DNSServer.h>
  6. #define WIFI_CONNECT_TIMEOUT 30
  7. class PersWiFiManager {
  8. public:
  9. typedef std::function<void(void)> WiFiChangeHandlerFunction;
  10. PersWiFiManager(ESP8266WebServer& s, DNSServer& d);
  11. bool attemptConnection(const String& ssid = "", const String& pass = "");
  12. void setupWiFiHandlers();
  13. bool begin(const String& ssid = "", const String& pass = "");
  14. String getApSsid();
  15. void setApCredentials(const String& apSsid, const String& apPass = "");
  16. void setConnectNonBlock(bool b);
  17. void handleWiFi();
  18. void startApMode();
  19. void onConnect(WiFiChangeHandlerFunction fn);
  20. void onAp(WiFiChangeHandlerFunction fn);
  21. private:
  22. ESP8266WebServer * _server;
  23. DNSServer * _dnsServer;
  24. String _apSsid, _apPass;
  25. bool _connectNonBlock;
  26. unsigned long _connectStartTime;
  27. WiFiChangeHandlerFunction _connectHandler;
  28. WiFiChangeHandlerFunction _apHandler;
  29. };//class
  30. #endif