/************************************************************** * WiFiManager is a library for the ESP8266/Arduino platform * (https://github.com/esp8266/Arduino) to enable easy * configuration and reconfiguration of WiFi credentials and * store them in EEPROM. * inspired by http://www.esp8266.com/viewtopic.php?f=29&t=2520 * https://github.com/chriscook8/esp-arduino-apboot * Built by AlexT https://github.com/tzapu * Licensed under MIT license **************************************************************/ #ifndef WiFiManager_h #define WiFiManager_h #include #include #include #include #include class WiFiManager { public: WiFiManager(); void begin(); void begin(char const *apName); boolean autoConnect(); boolean autoConnect(char const *apName); boolean hasConnected(); String beginConfigMode(void); void startWebConfig(); String getSSID(); String getPassword(); void setSSID(String s); void setPassword(String p); void resetSettings(); //for conveniennce String urldecode(const char*); //sets timeout before webserver loop ends and exits even if there has been no setup. //usefully for devices that failed to connect at some point and got stuck in a webserver loop //in seconds void setTimeout(unsigned long seconds); void setDebugOutput(boolean debug); //sets a custom ip /gateway /subnet configuration void setAPConfig(IPAddress ip, IPAddress gw, IPAddress sn); int serverLoop(); private: DNSServer dnsServer; ESP8266WebServer server; const int WM_DONE = 0; const int WM_WAIT = 10; const String HTTP_404 = "HTTP/1.1 404 Not Found\r\n\r\n"; const String HTTP_200 = "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n"; const String HTTP_HEAD = "{v}"; const String HTTP_STYLE = ""; const String HTTP_SCRIPT = ""; const String HTTP_HEAD_END = ""; const String HTTP_ITEM = ""; const String HTTP_FORM = "

"; const String HTTP_SAVED = "
Credentials Saved
Node will reboot in 5 seconds.
"; const String HTTP_END = ""; //const char HTTP_END[] PROGMEM = R"=====( // //)====="; int _eepromStart; const char* _apName = "no-net"; String _ssid = ""; String _pass = ""; unsigned long timeout = 0; unsigned long start = 0; IPAddress _ip; IPAddress _gw; IPAddress _sn; String getEEPROMString(int start, int len); void setEEPROMString(int start, int len, String string); bool keepLooping = true; int status = WL_IDLE_STATUS; void connectWifi(String ssid, String pass); void handleRoot(); void handleWifi(bool scan); void handleWifiSave(); void handleNotFound(); void handle204(); boolean captivePortal(); // DNS server const byte DNS_PORT = 53; boolean isIp(String str); String toStringIp(IPAddress ip); boolean connect; boolean _debug = true; template void DEBUG_PRINT(Generic text); }; #endif