diff --git a/CMakeLists.txt b/CMakeLists.txt index 7bd408a5e..c87bb2035 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 3.5) idf_component_register( SRCS "WiFiManager.cpp" INCLUDE_DIRS "." - REQUIRES arduino + PRIV_REQUIRES arduino ) project(WiFiManager) diff --git a/WiFiManager.cpp b/WiFiManager.cpp index 967ce9375..c946fcfb6 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -31,7 +31,7 @@ WiFiManagerParameter::WiFiManagerParameter() { WiFiManagerParameter::WiFiManagerParameter(const char *custom) { _id = NULL; _label = NULL; - _length = 1; + _length = 0; _value = nullptr; _labelPlacement = WFM_LABEL_DEFAULT; _customHTML = custom; @@ -58,7 +58,7 @@ void WiFiManagerParameter::init(const char *id, const char *label, const char *d _label = label; _labelPlacement = labelPlacement; _customHTML = custom; - _length = 1; + _length = 0; _value = nullptr; setValue(defaultValue,length); } @@ -137,7 +137,7 @@ bool WiFiManager::addParameter(WiFiManagerParameter *p) { for (size_t i = 0; i < strlen(p->getID()); i++){ if(!(isAlphaNumeric(p->getID()[i])) && !(p->getID()[i]=='_')){ #ifdef WM_DEBUG_LEVEL - DEBUG_WM(DEBUG_ERROR,F("[ERROR] parameter IDs can only contain alpha numeric chars")); + DEBUG_WM(WM_DEBUG_ERROR,F("[ERROR] parameter IDs can only contain alpha numeric chars")); #endif return false; } @@ -147,7 +147,7 @@ bool WiFiManager::addParameter(WiFiManagerParameter *p) { // init params if never malloc if(_params == NULL){ #ifdef WM_DEBUG_LEVEL - DEBUG_WM(DEBUG_DEV,F("allocating params bytes:"),_max_params * sizeof(WiFiManagerParameter*)); + DEBUG_WM(WM_DEBUG_DEV,F("allocating params bytes:"),_max_params * sizeof(WiFiManagerParameter*)); #endif _params = (WiFiManagerParameter**)malloc(_max_params * sizeof(WiFiManagerParameter*)); } @@ -156,8 +156,8 @@ bool WiFiManager::addParameter(WiFiManagerParameter *p) { if(_paramsCount == _max_params){ _max_params += WIFI_MANAGER_MAX_PARAMS; #ifdef WM_DEBUG_LEVEL - DEBUG_WM(DEBUG_DEV,F("Updated _max_params:"),_max_params); - DEBUG_WM(DEBUG_DEV,F("re-allocating params bytes:"),_max_params * sizeof(WiFiManagerParameter*)); + DEBUG_WM(WM_DEBUG_DEV,F("Updated _max_params:"),_max_params); + DEBUG_WM(WM_DEBUG_DEV,F("re-allocating params bytes:"),_max_params * sizeof(WiFiManagerParameter*)); #endif WiFiManagerParameter** new_params = (WiFiManagerParameter**)realloc(_params, _max_params * sizeof(WiFiManagerParameter*)); #ifdef WM_DEBUG_LEVEL @@ -169,7 +169,7 @@ bool WiFiManager::addParameter(WiFiManagerParameter *p) { _params = new_params; } else { #ifdef WM_DEBUG_LEVEL - DEBUG_WM(DEBUG_ERROR,F("[ERROR] failed to realloc params, size not increased!")); + DEBUG_WM(WM_DEBUG_ERROR,F("[ERROR] failed to realloc params, size not increased!")); #endif return false; } @@ -179,7 +179,7 @@ bool WiFiManager::addParameter(WiFiManagerParameter *p) { _paramsCount++; #ifdef WM_DEBUG_LEVEL - DEBUG_WM(DEBUG_VERBOSE,F("Added Parameter:"),p->getID()); + DEBUG_WM(WM_DEBUG_VERBOSE,F("Added Parameter:"),p->getID()); #endif return true; } @@ -217,7 +217,7 @@ WiFiManager::WiFiManager() { void WiFiManager::WiFiManagerInit(){ setMenu(_menuIdsDefault); - if(_debug && _debugLevel >= DEBUG_DEV) debugPlatformInfo(); + if(_debug && _debugLevel >= WM_DEBUG_DEV) debugPlatformInfo(); _max_params = WIFI_MANAGER_MAX_PARAMS; } @@ -228,7 +228,7 @@ WiFiManager::~WiFiManager() { // @todo below belongs to wifimanagerparameter if (_params != NULL){ #ifdef WM_DEBUG_LEVEL - DEBUG_WM(DEBUG_DEV,F("freeing allocated params!")); + DEBUG_WM(WM_DEBUG_DEV,F("freeing allocated params!")); #endif free(_params); _params = NULL; @@ -241,7 +241,7 @@ WiFiManager::~WiFiManager() { #endif #ifdef WM_DEBUG_LEVEL - DEBUG_WM(DEBUG_DEV,F("unloading")); + DEBUG_WM(WM_DEBUG_DEV,F("unloading")); #endif } @@ -308,7 +308,7 @@ boolean WiFiManager::autoConnect(char const *apName, char const *apPassword) { if(!WiFi.enableSTA(true)){ // handle failure mode Brownout detector etc. #ifdef WM_DEBUG_LEVEL - DEBUG_WM(DEBUG_ERROR,F("[FATAL] Unable to enable wifi!")); + DEBUG_WM(WM_DEBUG_ERROR,F("[FATAL] Unable to enable wifi!")); #endif return false; } @@ -350,7 +350,7 @@ boolean WiFiManager::autoConnect(char const *apName, char const *apPassword) { //connected #ifdef WM_DEBUG_LEVEL DEBUG_WM(F("AutoConnect: SUCCESS")); - DEBUG_WM(DEBUG_VERBOSE,F("Connected in"),(String)((millis()-_startconn)) + " ms"); + DEBUG_WM(WM_DEBUG_VERBOSE,F("Connected in"),(String)((millis()-_startconn)) + " ms"); DEBUG_WM(F("STA IP Address:"),WiFi.localIP()); #endif // Serial.println("Connected in " + (String)((millis()-_startconn)) + " ms"); @@ -358,14 +358,14 @@ boolean WiFiManager::autoConnect(char const *apName, char const *apPassword) { if(_hostname != ""){ #ifdef WM_DEBUG_LEVEL - DEBUG_WM(DEBUG_DEV,F("hostname: STA: "),getWiFiHostname()); + DEBUG_WM(WM_DEBUG_DEV,F("hostname: STA: "),getWiFiHostname()); #endif } return true; // connected success } #ifdef WM_DEBUG_LEVEL - DEBUG_WM(F("AutoConnect: FAILED")); + DEBUG_WM(F("AutoConnect: FAILED for "),(String)((millis()-_startconn)) + " ms"); #endif // } // else { @@ -377,7 +377,7 @@ boolean WiFiManager::autoConnect(char const *apName, char const *apPassword) { // possibly skip the config portal if (!_enableConfigPortal) { #ifdef WM_DEBUG_LEVEL - DEBUG_WM(DEBUG_VERBOSE,F("enableConfigPortal: FALSE, skipping ")); + DEBUG_WM(WM_DEBUG_VERBOSE,F("enableConfigPortal: FALSE, skipping ")); #endif return false; // not connected and not cp @@ -391,25 +391,25 @@ boolean WiFiManager::autoConnect(char const *apName, char const *apPassword) { bool WiFiManager::setupHostname(bool restart){ if(_hostname == "") { #ifdef WM_DEBUG_LEVEL - DEBUG_WM(DEBUG_DEV,F("No Hostname to set")); + DEBUG_WM(WM_DEBUG_DEV,F("No Hostname to set")); #endif return false; } else { #ifdef WM_DEBUG_LEVEL - DEBUG_WM(DEBUG_VERBOSE,F("Setting Hostnames: "),_hostname); + DEBUG_WM(WM_DEBUG_VERBOSE,F("Setting Hostnames: "),_hostname); #endif } bool res = true; #ifdef ESP8266 #ifdef WM_DEBUG_LEVEL - DEBUG_WM(DEBUG_VERBOSE,F("Setting WiFi hostname")); + DEBUG_WM(WM_DEBUG_VERBOSE,F("Setting WiFi hostname")); #endif res = WiFi.hostname(_hostname.c_str()); // #ifdef ESP8266MDNS_H #ifdef WM_MDNS #ifdef WM_DEBUG_LEVEL - DEBUG_WM(DEBUG_VERBOSE,F("Setting MDNS hostname, tcp 80")); + DEBUG_WM(WM_DEBUG_VERBOSE,F("Setting MDNS hostname, tcp 80")); #endif if(MDNS.begin(_hostname.c_str())){ MDNS.addService("http", "tcp", 80); @@ -421,7 +421,7 @@ bool WiFiManager::setupHostname(bool restart){ // same for S2, must set it before mode(STA) now #ifdef WM_DEBUG_LEVEL - DEBUG_WM(DEBUG_VERBOSE,F("Setting WiFi hostname")); + DEBUG_WM(WM_DEBUG_VERBOSE,F("Setting WiFi hostname")); #endif res = WiFi.setHostname(_hostname.c_str()); @@ -435,7 +435,7 @@ bool WiFiManager::setupHostname(bool restart){ // #ifdef ESP32MDNS_H #ifdef WM_MDNS #ifdef WM_DEBUG_LEVEL - DEBUG_WM(DEBUG_VERBOSE,F("Setting MDNS hostname, tcp 80")); + DEBUG_WM(WM_DEBUG_VERBOSE,F("Setting MDNS hostname, tcp 80")); #endif if(MDNS.begin(_hostname.c_str())){ MDNS.addService("http", "tcp", 80); @@ -444,12 +444,12 @@ bool WiFiManager::setupHostname(bool restart){ #endif #ifdef WM_DEBUG_LEVEL - if(!res)DEBUG_WM(DEBUG_ERROR,F("[ERROR] hostname: set failed!")); + if(!res)DEBUG_WM(WM_DEBUG_ERROR,F("[ERROR] hostname: set failed!")); #endif if(restart && (WiFi.status() == WL_CONNECTED)){ #ifdef WM_DEBUG_LEVEL - DEBUG_WM(DEBUG_VERBOSE,F("reconnecting to set new hostname")); + DEBUG_WM(WM_DEBUG_VERBOSE,F("reconnecting to set new hostname")); #endif // WiFi.reconnect(); // This does not reset dhcp WiFi_Disconnect(); @@ -470,7 +470,7 @@ bool WiFiManager::startAP(){ // @bug workaround for bug #4372 https://github.com/esp8266/Arduino/issues/4372 if(!WiFi.enableAP(true)) { #ifdef WM_DEBUG_LEVEL - DEBUG_WM(DEBUG_ERROR,F("[ERROR] enableAP failed!")); + DEBUG_WM(WM_DEBUG_ERROR,F("[ERROR] enableAP failed!")); #endif return false; } @@ -484,7 +484,7 @@ bool WiFiManager::startAP(){ #endif if(!WiFi.softAPConfig(_ap_static_ip, _ap_static_gw, _ap_static_sn)){ #ifdef WM_DEBUG_LEVEL - DEBUG_WM(DEBUG_ERROR,F("[ERROR] softAPConfig failed!")); + DEBUG_WM(WM_DEBUG_ERROR,F("[ERROR] softAPConfig failed!")); #endif } } @@ -498,7 +498,7 @@ bool WiFiManager::startAP(){ if(channel>0){ #ifdef WM_DEBUG_LEVEL - DEBUG_WM(DEBUG_VERBOSE,F("Starting AP on channel:"),channel); + DEBUG_WM(WM_DEBUG_VERBOSE,F("Starting AP on channel:"),channel); #endif } @@ -513,7 +513,7 @@ bool WiFiManager::startAP(){ } } else { #ifdef WM_DEBUG_LEVEL - DEBUG_WM(DEBUG_VERBOSE,F("AP has anonymous access!")); + DEBUG_WM(WM_DEBUG_VERBOSE,F("AP has anonymous access!")); #endif if(channel>0){ ret = WiFi.softAP(_apName.c_str(),"",channel,_apHidden); @@ -523,13 +523,13 @@ bool WiFiManager::startAP(){ } } - if(_debugLevel >= DEBUG_DEV) debugSoftAPConfig(); + if(_debugLevel >= WM_DEBUG_DEV) debugSoftAPConfig(); // @todo add softAP retry here to dela with unknown failures delay(500); // slight delay to make sure we get an AP IP #ifdef WM_DEBUG_LEVEL - if(!ret) DEBUG_WM(DEBUG_ERROR,F("[ERROR] There was a problem starting the AP")); + if(!ret) DEBUG_WM(WM_DEBUG_ERROR,F("[ERROR] There was a problem starting the AP")); DEBUG_WM(F("AP IP address:"),WiFi.softAPIP()); #endif @@ -538,9 +538,9 @@ bool WiFiManager::startAP(){ if(ret && _hostname != ""){ bool res = WiFi.softAPsetHostname(_hostname.c_str()); #ifdef WM_DEBUG_LEVEL - DEBUG_WM(DEBUG_VERBOSE,F("setting softAP Hostname:"),_hostname); - if(!res)DEBUG_WM(DEBUG_ERROR,F("[ERROR] hostname: AP set failed!")); - DEBUG_WM(DEBUG_DEV,F("hostname: AP: "),WiFi.softAPgetHostname()); + DEBUG_WM(WM_DEBUG_VERBOSE,F("setting softAP Hostname:"),_hostname); + if(!res)DEBUG_WM(WM_DEBUG_ERROR,F("[ERROR] hostname: AP set failed!")); + DEBUG_WM(WM_DEBUG_DEV,F("hostname: AP: "),WiFi.softAPgetHostname()); #endif } #endif @@ -568,7 +568,7 @@ void WiFiManager::startWebPortal() { void WiFiManager::stopWebPortal() { if(!configPortalActive && !webPortalActive) return; #ifdef WM_DEBUG_LEVEL - DEBUG_WM(DEBUG_VERBOSE,F("Stopping Web Portal")); + DEBUG_WM(WM_DEBUG_VERBOSE,F("Stopping Web Portal")); #endif webPortalActive = false; shutdownConfigPortal(); @@ -584,7 +584,7 @@ boolean WiFiManager::configPortalHasTimeout(){ if(millis() - timer > logintvl){ timer = millis(); #ifdef WM_DEBUG_LEVEL - DEBUG_WM(DEBUG_VERBOSE,F("NUM CLIENTS: "),(String)WiFi_softap_num_stations()); + DEBUG_WM(WM_DEBUG_VERBOSE,F("NUM CLIENTS: "),(String)WiFi_softap_num_stations()); #endif } _configPortalStart = millis(); // kludge, bump configportal start time to skew timeouts @@ -606,7 +606,7 @@ boolean WiFiManager::configPortalHasTimeout(){ if((millis() - timer) > logintvl){ timer = millis(); #ifdef WM_DEBUG_LEVEL - DEBUG_WM(DEBUG_VERBOSE,F("Portal Timeout In"),(String)((_configPortalStart + _configPortalTimeout-millis())/1000) + (String)F(" seconds")); + DEBUG_WM(WM_DEBUG_VERBOSE,F("Portal Timeout In"),(String)((_configPortalStart + _configPortalTimeout-millis())/1000) + (String)F(" seconds")); #endif } } @@ -622,7 +622,7 @@ void WiFiManager::setupHTTPServer(){ if(_httpPort != 80) { #ifdef WM_DEBUG_LEVEL - DEBUG_WM(DEBUG_VERBOSE,F("http server started with custom port: "),_httpPort); // @todo not showing ip + DEBUG_WM(WM_DEBUG_VERBOSE,F("http server started with custom port: "),_httpPort); // @todo not showing ip #endif } @@ -631,7 +631,7 @@ void WiFiManager::setupHTTPServer(){ if ( _webservercallback != NULL) { #ifdef WM_DEBUG_LEVEL - DEBUG_WM(DEBUG_VERBOSE,F("[CB] _webservercallback calling")); + DEBUG_WM(WM_DEBUG_VERBOSE,F("[CB] _webservercallback calling")); #endif _webservercallback(); // @CALLBACK } @@ -659,7 +659,7 @@ void WiFiManager::setupHTTPServer(){ server->begin(); // Web server start #ifdef WM_DEBUG_LEVEL - DEBUG_WM(DEBUG_VERBOSE,F("HTTP server started")); + DEBUG_WM(WM_DEBUG_VERBOSE,F("HTTP server started")); #endif } @@ -670,7 +670,7 @@ void WiFiManager::setupDNSD(){ dnsServer->setErrorReplyCode(DNSReplyCode::NoError); #ifdef WM_DEBUG_LEVEL // DEBUG_WM("dns server started port: ",DNS_PORT); - DEBUG_WM(DEBUG_DEV,F("dns server started with ip: "),WiFi.softAPIP()); // @todo not showing ip + DEBUG_WM(WM_DEBUG_DEV,F("dns server started with ip: "),WiFi.softAPIP()); // @todo not showing ip #endif dnsServer->start(DNS_PORT, F("*"), WiFi.softAPIP()); } @@ -698,7 +698,7 @@ boolean WiFiManager::startConfigPortal(char const *apName, char const *apPasswo if(configPortalActive){ #ifdef WM_DEBUG_LEVEL - DEBUG_WM(DEBUG_VERBOSE,F("Starting Config Portal FAILED, is already running")); + DEBUG_WM(WM_DEBUG_VERBOSE,F("Starting Config Portal FAILED, is already running")); #endif return false; } @@ -708,7 +708,7 @@ boolean WiFiManager::startConfigPortal(char const *apName, char const *apPasswo _apPassword = apPassword; #ifdef WM_DEBUG_LEVEL - DEBUG_WM(DEBUG_VERBOSE,F("Starting Config Portal")); + DEBUG_WM(WM_DEBUG_VERBOSE,F("Starting Config Portal")); #endif if(_apName == "") _apName = getDefaultAPName(); @@ -724,7 +724,7 @@ boolean WiFiManager::startConfigPortal(char const *apName, char const *apPasswo WiFi_Disconnect(); WiFi_enableSTA(false); #ifdef WM_DEBUG_LEVEL - DEBUG_WM(DEBUG_VERBOSE,F("Disabling STA")); + DEBUG_WM(WM_DEBUG_VERBOSE,F("Disabling STA")); #endif } else { @@ -740,7 +740,7 @@ boolean WiFiManager::startConfigPortal(char const *apName, char const *apPasswo // start access point #ifdef WM_DEBUG_LEVEL - DEBUG_WM(DEBUG_VERBOSE,F("Enabling AP")); + DEBUG_WM(WM_DEBUG_VERBOSE,F("Enabling AP")); #endif startAP(); WiFiSetCountry(); @@ -748,27 +748,27 @@ boolean WiFiManager::startConfigPortal(char const *apName, char const *apPasswo // do AP callback if set if ( _apcallback != NULL) { #ifdef WM_DEBUG_LEVEL - DEBUG_WM(DEBUG_VERBOSE,F("[CB] _apcallback calling")); + DEBUG_WM(WM_DEBUG_VERBOSE,F("[CB] _apcallback calling")); #endif _apcallback(this); } // init configportal #ifdef WM_DEBUG_LEVEL - DEBUG_WM(DEBUG_DEV,F("setupConfigPortal")); + DEBUG_WM(WM_DEBUG_DEV,F("setupConfigPortal")); #endif setupConfigPortal(); #ifdef WM_DEBUG_LEVEL - DEBUG_WM(DEBUG_DEV,F("setupDNSD")); + DEBUG_WM(WM_DEBUG_DEV,F("setupDNSD")); #endif setupDNSD(); if(!_configPortalIsBlocking){ #ifdef WM_DEBUG_LEVEL - DEBUG_WM(DEBUG_VERBOSE,F("Config Portal Running, non blocking (processing)")); - if(_configPortalTimeout > 0) DEBUG_WM(DEBUG_VERBOSE,F("Portal Timeout In"),(String)(_configPortalTimeout/1000) + (String)F(" seconds")); + DEBUG_WM(WM_DEBUG_VERBOSE,F("Config Portal Running, non blocking (processing)")); + if(_configPortalTimeout > 0) DEBUG_WM(WM_DEBUG_VERBOSE,F("Portal Timeout In"),(String)(_configPortalTimeout/1000) + (String)F(" seconds")); #endif return result; // skip blocking loop } @@ -776,8 +776,8 @@ boolean WiFiManager::startConfigPortal(char const *apName, char const *apPasswo // enter blocking loop, waiting for config #ifdef WM_DEBUG_LEVEL - DEBUG_WM(DEBUG_VERBOSE,F("Config Portal Running, blocking, waiting for clients...")); - if(_configPortalTimeout > 0) DEBUG_WM(DEBUG_VERBOSE,F("Portal Timeout In"),(String)(_configPortalTimeout/1000) + (String)F(" seconds")); + DEBUG_WM(WM_DEBUG_VERBOSE,F("Config Portal Running, blocking, waiting for clients...")); + if(_configPortalTimeout > 0) DEBUG_WM(WM_DEBUG_VERBOSE,F("Portal Timeout In"),(String)(_configPortalTimeout/1000) + (String)F(" seconds")); #endif while(1){ @@ -785,13 +785,13 @@ boolean WiFiManager::startConfigPortal(char const *apName, char const *apPasswo // if timed out or abort, break if(configPortalHasTimeout() || abort){ #ifdef WM_DEBUG_LEVEL - DEBUG_WM(DEBUG_DEV,F("configportal loop abort")); + DEBUG_WM(WM_DEBUG_DEV,F("configportal loop abort")); #endif shutdownConfigPortal(); result = abort ? portalAbortResult : portalTimeoutResult; // false, false if (_configportaltimeoutcallback != NULL) { #ifdef WM_DEBUG_LEVEL - DEBUG_WM(DEBUG_VERBOSE,F("[CB] config portal timeout callback")); + DEBUG_WM(WM_DEBUG_VERBOSE,F("[CB] config portal timeout callback")); #endif _configportaltimeoutcallback(); // @CALLBACK } @@ -805,7 +805,7 @@ boolean WiFiManager::startConfigPortal(char const *apName, char const *apPasswo // I think.. this is to detect autoconnect by esp in background, there are also many open issues about autoreconnect not working if(state != WL_IDLE_STATUS){ result = (state == WL_CONNECTED); // true if connected - DEBUG_WM(DEBUG_DEV,F("configportal loop break")); + DEBUG_WM(WM_DEBUG_DEV,F("configportal loop break")); break; } @@ -815,7 +815,7 @@ boolean WiFiManager::startConfigPortal(char const *apName, char const *apPasswo } #ifdef WM_DEBUG_LEVEL - DEBUG_WM(DEBUG_NOTIFY,F("config portal exiting")); + DEBUG_WM(WM_DEBUG_NOTIFY,F("config portal exiting")); #endif return result; } @@ -835,13 +835,13 @@ boolean WiFiManager::process(){ // if timed out or abort, break if(_allowExit && (configPortalHasTimeout() || abort)){ #ifdef WM_DEBUG_LEVEL - DEBUG_WM(DEBUG_DEV,F("process loop abort")); + DEBUG_WM(WM_DEBUG_DEV,F("process loop abort")); #endif webPortalActive = false; shutdownConfigPortal(); if (_configportaltimeoutcallback != NULL) { #ifdef WM_DEBUG_LEVEL - DEBUG_WM(DEBUG_VERBOSE,F("[CB] config portal timeout callback")); + DEBUG_WM(WM_DEBUG_VERBOSE,F("[CB] config portal timeout callback")); #endif _configportaltimeoutcallback(); // @CALLBACK } @@ -874,14 +874,14 @@ uint8_t WiFiManager::processConfigPortal(){ if(connect) { connect = false; #ifdef WM_DEBUG_LEVEL - DEBUG_WM(DEBUG_VERBOSE,F("processing save")); + DEBUG_WM(WM_DEBUG_VERBOSE,F("processing save")); #endif if(_enableCaptivePortal) delay(_cpclosedelay); // keeps the captiveportal from closing to fast. // skip wifi if no ssid if(_ssid == ""){ #ifdef WM_DEBUG_LEVEL - DEBUG_WM(DEBUG_VERBOSE,F("No ssid, skipping wifi save")); + DEBUG_WM(WM_DEBUG_VERBOSE,F("No ssid, skipping wifi save")); #endif } else{ @@ -900,7 +900,7 @@ uint8_t WiFiManager::processConfigPortal(){ if ( _savewificallback != NULL) { #ifdef WM_DEBUG_LEVEL - DEBUG_WM(DEBUG_VERBOSE,F("[CB] _savewificallback calling")); + DEBUG_WM(WM_DEBUG_VERBOSE,F("[CB] _savewificallback calling")); #endif _savewificallback(); // @CALLBACK } @@ -909,7 +909,7 @@ uint8_t WiFiManager::processConfigPortal(){ return WL_CONNECTED; // CONNECT SUCCESS } #ifdef WM_DEBUG_LEVEL - DEBUG_WM(DEBUG_ERROR,F("[ERROR] Connect to new AP Failed")); + DEBUG_WM(WM_DEBUG_ERROR,F("[ERROR] Connect to new AP Failed")); #endif } @@ -920,7 +920,7 @@ uint8_t WiFiManager::processConfigPortal(){ // confirm or verify data was saved to make this more accurate callback if ( _savewificallback != NULL) { #ifdef WM_DEBUG_LEVEL - DEBUG_WM(DEBUG_VERBOSE,F("[CB] WiFi/Param save callback")); + DEBUG_WM(WM_DEBUG_VERBOSE,F("[CB] WiFi/Param save callback")); #endif _savewificallback(); // @CALLBACK } @@ -935,12 +935,12 @@ uint8_t WiFiManager::processConfigPortal(){ WiFi_Disconnect(); WiFi_enableSTA(false); #ifdef WM_DEBUG_LEVEL - DEBUG_WM(DEBUG_VERBOSE,F("Processing - Disabling STA")); + DEBUG_WM(WM_DEBUG_VERBOSE,F("Processing - Disabling STA")); #endif } else{ #ifdef WM_DEBUG_LEVEL - DEBUG_WM(DEBUG_VERBOSE,F("Portal is non blocking - remaining open")); + DEBUG_WM(WM_DEBUG_VERBOSE,F("Portal is non blocking - remaining open")); #endif } } @@ -955,7 +955,7 @@ uint8_t WiFiManager::processConfigPortal(){ */ bool WiFiManager::shutdownConfigPortal(){ #ifdef WM_DEBUG_LEVEL - DEBUG_WM(DEBUG_VERBOSE,F("shutdownConfigPortal")); + DEBUG_WM(WM_DEBUG_VERBOSE,F("shutdownConfigPortal")); #endif if(webPortalActive) return false; @@ -990,23 +990,23 @@ bool WiFiManager::shutdownConfigPortal(){ ret = WiFi.softAPdisconnect(false); #ifdef WM_DEBUG_LEVEL - if(!ret)DEBUG_WM(DEBUG_ERROR,F("[ERROR] disconnect configportal - softAPdisconnect FAILED")); - DEBUG_WM(DEBUG_VERBOSE,F("restoring usermode"),getModeString(_usermode)); + if(!ret)DEBUG_WM(WM_DEBUG_ERROR,F("[ERROR] disconnect configportal - softAPdisconnect FAILED")); + DEBUG_WM(WM_DEBUG_VERBOSE,F("restoring usermode"),getModeString(_usermode)); #endif delay(1000); WiFi_Mode(_usermode); // restore users wifi mode, BUG https://github.com/esp8266/Arduino/issues/4372 if(WiFi.status()==WL_IDLE_STATUS){ WiFi.reconnect(); // restart wifi since we disconnected it in startconfigportal #ifdef WM_DEBUG_LEVEL - DEBUG_WM(DEBUG_VERBOSE,F("WiFi Reconnect, was idle")); + DEBUG_WM(WM_DEBUG_VERBOSE,F("WiFi Reconnect, was idle")); #endif } #ifdef WM_DEBUG_LEVEL - DEBUG_WM(DEBUG_VERBOSE,F("wifi status:"),getWLStatusString(WiFi.status())); - DEBUG_WM(DEBUG_VERBOSE,F("wifi mode:"),getModeString(WiFi.getMode())); + DEBUG_WM(WM_DEBUG_VERBOSE,F("wifi status:"),getWLStatusString(WiFi.status())); + DEBUG_WM(WM_DEBUG_VERBOSE,F("wifi mode:"),getModeString(WiFi.getMode())); #endif configPortalActive = false; - DEBUG_WM(DEBUG_VERBOSE,F("configportal closed")); + DEBUG_WM(WM_DEBUG_VERBOSE,F("configportal closed")); _end(); return ret; } @@ -1016,7 +1016,7 @@ bool WiFiManager::shutdownConfigPortal(){ // clean up, flow is convoluted, and causes bugs uint8_t WiFiManager::connectWifi(String ssid, String pass, bool connect) { #ifdef WM_DEBUG_LEVEL - DEBUG_WM(DEBUG_VERBOSE,F("Connecting as wifi client...")); + DEBUG_WM(WM_DEBUG_VERBOSE,F("Connecting as wifi client...")); #endif uint8_t retry = 1; uint8_t connRes = (uint8_t)WL_NO_SSID_AVAIL; @@ -1041,6 +1041,7 @@ uint8_t WiFiManager::connectWifi(String ssid, String pass, bool connect) { #endif } // if ssid argument provided connect to that + // NOTE: this also catches preload() _defaultssid @todo rework if (ssid != "") { wifiConnectNew(ssid,pass,connect); // @todo connect=false seems to disconnect sta in begin() so not sure if _connectonsave is useful at all @@ -1050,7 +1051,7 @@ uint8_t WiFiManager::connectWifi(String ssid, String pass, bool connect) { connRes = waitForConnectResult(_saveTimeout); // use default save timeout for saves to prevent bugs in esp->waitforconnectresult loop } else { - connRes = waitForConnectResult(0); + connRes = waitForConnectResult(); } // } } @@ -1068,7 +1069,7 @@ uint8_t WiFiManager::connectWifi(String ssid, String pass, bool connect) { } #ifdef WM_DEBUG_LEVEL - DEBUG_WM(DEBUG_VERBOSE,F("Connection result:"),getWLStatusString(connRes)); + DEBUG_WM(WM_DEBUG_VERBOSE,F("Connection result:"),getWLStatusString(connRes)); #endif retry++; } @@ -1102,9 +1103,9 @@ uint8_t WiFiManager::connectWifi(String ssid, String pass, bool connect) { bool WiFiManager::wifiConnectNew(String ssid, String pass,bool connect){ bool ret = false; #ifdef WM_DEBUG_LEVEL - // DEBUG_WM(DEBUG_DEV,F("CONNECTED: "),WiFi.status() == WL_CONNECTED ? "Y" : "NO"); + // DEBUG_WM(WM_DEBUG_DEV,F("CONNECTED: "),WiFi.status() == WL_CONNECTED ? "Y" : "NO"); DEBUG_WM(F("Connecting to NEW AP:"),ssid); - DEBUG_WM(DEBUG_DEV,F("Using Password:"),pass); + DEBUG_WM(WM_DEBUG_DEV,F("Using Password:"),pass); #endif WiFi_enableSTA(true,storeSTAmode); // storeSTAmode will also toggle STA on in default opmode (persistent) if true (default) WiFi.persistent(true); @@ -1119,7 +1120,7 @@ bool WiFiManager::wifiConnectNew(String ssid, String pass,bool connect){ } WiFi.persistent(false); #ifdef WM_DEBUG_LEVEL - if(!ret) DEBUG_WM(DEBUG_ERROR,F("[ERROR] WiFi Begin Failed")); + if(!ret) DEBUG_WM(WM_DEBUG_ERROR,F("[ERROR] wifi begin failed")); #endif return ret; } @@ -1133,15 +1134,15 @@ bool WiFiManager::wifiConnectDefault(){ bool ret = false; #ifdef WM_DEBUG_LEVEL DEBUG_WM(F("Connecting to SAVED AP:"),WiFi_SSID(true)); - DEBUG_WM(DEBUG_DEV,F("Using Password:"),WiFi_psk(true)); + DEBUG_WM(WM_DEBUG_DEV,F("Using Password:"),WiFi_psk(true)); #endif ret = WiFi_enableSTA(true,storeSTAmode); // delay(500); // enable sta race condition bugs exist #ifdef WM_DEBUG_LEVEL - DEBUG_WM(DEBUG_DEV,F("Mode after delay: "),getModeString(WiFi.getMode())); - if(!ret) DEBUG_WM(DEBUG_ERROR,F("[ERROR] wifi enableSta failed")); + DEBUG_WM(WM_DEBUG_DEV,F("Mode after delay: "),getModeString(WiFi.getMode())); + if(!ret) DEBUG_WM(WM_DEBUG_ERROR,F("[ERROR] wifi enableSta failed")); #endif ret = WiFi.begin(); @@ -1177,7 +1178,7 @@ bool WiFiManager::wifiConnectDefault(){ #ifdef WM_DEBUG_LEVEL - if(!ret) DEBUG_WM(DEBUG_ERROR,F("[ERROR] wifi begin failed")); + if(!ret) DEBUG_WM(WM_DEBUG_ERROR,F("[ERROR] wifi begin failed")); #endif return ret; @@ -1189,33 +1190,35 @@ bool WiFiManager::wifiConnectDefault(){ * @return bool success */ bool WiFiManager::setSTAConfig(){ + #ifdef WM_DEBUG_LEVEL + DEBUG_WM(WM_DEBUG_DEV,F("STA static IP:"),_sta_static_ip); + #endif bool ret = true; if (_sta_static_ip) { #ifdef WM_DEBUG_LEVEL - DEBUG_WM(DEBUG_DEV,F("STA static IP:"),_sta_static_ip); - DEBUG_WM(DEBUG_VERBOSE,F("Custom static IP/GW/Subnet/DNS")); + DEBUG_WM(WM_DEBUG_VERBOSE,F("Custom static IP/GW/Subnet/DNS")); #endif if(_sta_static_dns) { #ifdef WM_DEBUG_LEVEL - DEBUG_WM(DEBUG_VERBOSE,F("Custom static DNS")); + DEBUG_WM(WM_DEBUG_VERBOSE,F("Custom static DNS")); #endif ret = WiFi.config(_sta_static_ip, _sta_static_gw, _sta_static_sn, _sta_static_dns); } else { #ifdef WM_DEBUG_LEVEL - DEBUG_WM(DEBUG_VERBOSE,F("Custom STA IP/GW/Subnet")); + DEBUG_WM(WM_DEBUG_VERBOSE,F("Custom STA IP/GW/Subnet")); #endif ret = WiFi.config(_sta_static_ip, _sta_static_gw, _sta_static_sn); } #ifdef WM_DEBUG_LEVEL - if(!ret) DEBUG_WM(DEBUG_ERROR,F("[ERROR] wifi config failed")); + if(!ret) DEBUG_WM(WM_DEBUG_ERROR,F("[ERROR] wifi config failed")); else DEBUG_WM(F("STA IP set:"),WiFi.localIP()); #endif } else { #ifdef WM_DEBUG_LEVEL - DEBUG_WM(DEBUG_VERBOSE,F("setSTAConfig static ip not set, skipping")); + DEBUG_WM(WM_DEBUG_VERBOSE,F("setSTAConfig static ip not set, skipping")); #endif } return ret; @@ -1235,21 +1238,21 @@ void WiFiManager::updateConxResult(uint8_t status){ // if(_lastconxresult == WL_CONNECT_FAILED){ if(_lastconxresult == WL_CONNECT_FAILED || _lastconxresult == WL_DISCONNECTED){ #ifdef WM_DEBUG_LEVEL - DEBUG_WM(DEBUG_DEV,F("lastconxresulttmp:"),getWLStatusString(_lastconxresulttmp)); + DEBUG_WM(WM_DEBUG_DEV,F("lastconxresulttmp:"),getWLStatusString(_lastconxresulttmp)); #endif if(_lastconxresulttmp != WL_IDLE_STATUS){ _lastconxresult = _lastconxresulttmp; // _lastconxresulttmp = WL_IDLE_STATUS; } } - DEBUG_WM(DEBUG_DEV,F("lastconxresult:"),getWLStatusString(_lastconxresult)); + DEBUG_WM(WM_DEBUG_DEV,F("lastconxresult:"),getWLStatusString(_lastconxresult)); #endif } uint8_t WiFiManager::waitForConnectResult() { #ifdef WM_DEBUG_LEVEL - if(_connectTimeout > 0) DEBUG_WM(DEBUG_DEV,_connectTimeout,F("ms connectTimeout set")); + if(_connectTimeout > 0) DEBUG_WM(WM_DEBUG_DEV,_connectTimeout,F("ms connectTimeout set")); #endif return waitForConnectResult(_connectTimeout); } @@ -1269,7 +1272,7 @@ uint8_t WiFiManager::waitForConnectResult(uint32_t timeout) { unsigned long timeoutmillis = millis() + timeout; #ifdef WM_DEBUG_LEVEL - DEBUG_WM(DEBUG_VERBOSE,timeout,F("ms timeout, waiting for connect...")); + DEBUG_WM(WM_DEBUG_VERBOSE,timeout,F("ms timeout, waiting for connect...")); #endif uint8_t status = WiFi.status(); @@ -1280,7 +1283,7 @@ uint8_t WiFiManager::waitForConnectResult(uint32_t timeout) { return status; } #ifdef WM_DEBUG_LEVEL - DEBUG_WM (DEBUG_VERBOSE,F(".")); + DEBUG_WM (WM_DEBUG_VERBOSE,F(".")); #endif delay(100); } @@ -1324,7 +1327,7 @@ String WiFiManager::getHTTPHead(String title){ return page; } -void WiFiManager::HTTPSend(String content){ +void WiFiManager::HTTPSend(const String &content){ server->send(200, FPSTR(HTTP_HEAD_CT), content); } @@ -1345,13 +1348,13 @@ void WiFiManager::handleRequest() { bool testauth = false; if(!testauth) return; - DEBUG_WM(DEBUG_DEV,F("DOING AUTH")); + DEBUG_WM(WM_DEBUG_DEV,F("DOING AUTH")); bool res = server->authenticate("admin","12345"); if(!res){ #ifndef WM_NOAUTH server->requestAuthentication(HTTPAuthMethod::BASIC_AUTH); // DIGEST_AUTH #endif - DEBUG_WM(DEBUG_DEV,F("AUTH FAIL")); + DEBUG_WM(WM_DEBUG_DEV,F("AUTH FAIL")); } } @@ -1360,7 +1363,7 @@ void WiFiManager::handleRequest() { */ void WiFiManager::handleRoot() { #ifdef WM_DEBUG_LEVEL - DEBUG_WM(DEBUG_VERBOSE,F("<- HTTP Root")); + DEBUG_WM(WM_DEBUG_VERBOSE,F("<- HTTP Root")); #endif if (captivePortal()) return; // If captive portal redirect instead of displaying the page handleRequest(); @@ -1386,13 +1389,13 @@ void WiFiManager::handleRoot() { */ void WiFiManager::handleWifi(boolean scan) { #ifdef WM_DEBUG_LEVEL - DEBUG_WM(DEBUG_VERBOSE,F("<- HTTP Wifi")); + DEBUG_WM(WM_DEBUG_VERBOSE,F("<- HTTP Wifi")); #endif handleRequest(); String page = getHTTPHead(FPSTR(S_titlewifi)); // @token titlewifi if (scan) { #ifdef WM_DEBUG_LEVEL - // DEBUG_WM(DEBUG_DEV,"refresh flag:",server->hasArg(F("refresh"))); + // DEBUG_WM(WM_DEBUG_DEV,"refresh flag:",server->hasArg(F("refresh"))); #endif WiFi_scanNetworks(server->hasArg(F("refresh")),false); //wifiscan, force if arg refresh page += getScanItemOut(); @@ -1433,7 +1436,7 @@ void WiFiManager::handleWifi(boolean scan) { HTTPSend(page); #ifdef WM_DEBUG_LEVEL - DEBUG_WM(DEBUG_DEV,F("Sent config page")); + DEBUG_WM(WM_DEBUG_DEV,F("Sent config page")); #endif } @@ -1442,7 +1445,7 @@ void WiFiManager::handleWifi(boolean scan) { */ void WiFiManager::handleParam(){ #ifdef WM_DEBUG_LEVEL - DEBUG_WM(DEBUG_VERBOSE,F("<- HTTP Param")); + DEBUG_WM(WM_DEBUG_VERBOSE,F("<- HTTP Param")); #endif handleRequest(); String page = getHTTPHead(FPSTR(S_titleparam)); // @token titlewifi @@ -1462,7 +1465,7 @@ void WiFiManager::handleParam(){ HTTPSend(page); #ifdef WM_DEBUG_LEVEL - DEBUG_WM(DEBUG_DEV,F("Sent param page")); + DEBUG_WM(WM_DEBUG_DEV,F("Sent param page")); #endif } @@ -1477,6 +1480,7 @@ String WiFiManager::getMenuOut(){ continue; } page += HTTP_PORTAL_MENU[menuId]; + delay(0); } return page; @@ -1491,8 +1495,8 @@ void WiFiManager::WiFi_scanComplete(int networksFound){ _lastscan = millis(); _numNetworks = networksFound; #ifdef WM_DEBUG_LEVEL - DEBUG_WM(DEBUG_VERBOSE,F("WiFi Scan ASYNC completed"), "in "+(String)(_lastscan - _startscan)+" ms"); - DEBUG_WM(DEBUG_VERBOSE,F("WiFi Scan ASYNC found:"),_numNetworks); + DEBUG_WM(WM_DEBUG_VERBOSE,F("WiFi Scan ASYNC completed"), "in "+(String)(_lastscan - _startscan)+" ms"); + DEBUG_WM(WM_DEBUG_VERBOSE,F("WiFi Scan ASYNC found:"),_numNetworks); #endif } @@ -1508,15 +1512,15 @@ bool WiFiManager::WiFi_scanNetworks(unsigned int cachetime){ } bool WiFiManager::WiFi_scanNetworks(bool force,bool async){ #ifdef WM_DEBUG_LEVEL - // DEBUG_WM(DEBUG_DEV,"scanNetworks async:",async == true); - // DEBUG_WM(DEBUG_DEV,_numNetworks,(millis()-_lastscan )); - // DEBUG_WM(DEBUG_DEV,"scanNetworks force:",force == true); + // DEBUG_WM(WM_DEBUG_DEV,"scanNetworks async:",async == true); + // DEBUG_WM(WM_DEBUG_DEV,_numNetworks,(millis()-_lastscan )); + // DEBUG_WM(WM_DEBUG_DEV,"scanNetworks force:",force == true); #endif // if 0 networks, rescan @note this was a kludge, now disabling to test real cause ( maybe wifi not init etc) // enable only if preload failed? if(_numNetworks == 0 && _autoforcerescan){ - DEBUG_WM(DEBUG_DEV,"NO APs found forcing new scan"); + DEBUG_WM(WM_DEBUG_DEV,"NO APs found forcing new scan"); force = true; } @@ -1532,38 +1536,38 @@ bool WiFiManager::WiFi_scanNetworks(bool force,bool async){ #ifdef ESP8266 #ifndef WM_NOASYNC // no async available < 2.4.0 #ifdef WM_DEBUG_LEVEL - DEBUG_WM(DEBUG_VERBOSE,F("WiFi Scan ASYNC started")); + DEBUG_WM(WM_DEBUG_VERBOSE,F("WiFi Scan ASYNC started")); #endif using namespace std::placeholders; // for `_1` WiFi.scanNetworksAsync(std::bind(&WiFiManager::WiFi_scanComplete,this,_1)); #else - DEBUG_WM(DEBUG_VERBOSE,F("WiFi Scan SYNC started")); + DEBUG_WM(WM_DEBUG_VERBOSE,F("WiFi Scan SYNC started")); res = WiFi.scanNetworks(); #endif #else #ifdef WM_DEBUG_LEVEL - DEBUG_WM(DEBUG_VERBOSE,F("WiFi Scan ASYNC started")); + DEBUG_WM(WM_DEBUG_VERBOSE,F("WiFi Scan ASYNC started")); #endif res = WiFi.scanNetworks(true); #endif return false; } else{ - DEBUG_WM(DEBUG_VERBOSE,F("WiFi Scan SYNC started")); + DEBUG_WM(WM_DEBUG_VERBOSE,F("WiFi Scan SYNC started")); res = WiFi.scanNetworks(); } if(res == WIFI_SCAN_FAILED){ #ifdef WM_DEBUG_LEVEL - DEBUG_WM(DEBUG_ERROR,F("[ERROR] scan failed")); + DEBUG_WM(WM_DEBUG_ERROR,F("[ERROR] scan failed")); #endif } else if(res == WIFI_SCAN_RUNNING){ #ifdef WM_DEBUG_LEVEL - DEBUG_WM(DEBUG_ERROR,F("[ERROR] scan waiting")); + DEBUG_WM(WM_DEBUG_ERROR,F("[ERROR] scan waiting")); #endif while(WiFi.scanComplete() == WIFI_SCAN_RUNNING){ #ifdef WM_DEBUG_LEVEL - DEBUG_WM(DEBUG_ERROR,"."); + DEBUG_WM(WM_DEBUG_ERROR,"."); #endif delay(100); } @@ -1572,13 +1576,13 @@ bool WiFiManager::WiFi_scanNetworks(bool force,bool async){ else if(res >=0 ) _numNetworks = res; _lastscan = millis(); #ifdef WM_DEBUG_LEVEL - DEBUG_WM(DEBUG_VERBOSE,F("WiFi Scan completed"), "in "+(String)(_lastscan - _startscan)+" ms"); + DEBUG_WM(WM_DEBUG_VERBOSE,F("WiFi Scan completed"), "in "+(String)(_lastscan - _startscan)+" ms"); #endif return true; } else { #ifdef WM_DEBUG_LEVEL - DEBUG_WM(DEBUG_VERBOSE,F("Scan is cached"),(String)(millis()-_lastscan )+" ms ago"); + DEBUG_WM(WM_DEBUG_VERBOSE,F("Scan is cached"),(String)(millis()-_lastscan )+" ms ago"); #endif } return false; @@ -1632,7 +1636,7 @@ String WiFiManager::WiFiManager::getScanItemOut(){ for (int j = i + 1; j < n; j++) { if (cssid == WiFi.SSID(indices[j])) { #ifdef WM_DEBUG_LEVEL - DEBUG_WM(DEBUG_VERBOSE,F("DUP AP:"),WiFi.SSID(indices[j])); + DEBUG_WM(WM_DEBUG_VERBOSE,F("DUP AP:"),WiFi.SSID(indices[j])); #endif indices[j] = -1; // set dup aps to index -1 } @@ -1661,7 +1665,7 @@ String WiFiManager::WiFiManager::getScanItemOut(){ if (indices[i] == -1) continue; // skip dups #ifdef WM_DEBUG_LEVEL - DEBUG_WM(DEBUG_VERBOSE,F("AP: "),(String)WiFi.RSSI(indices[i]) + " " + (String)WiFi.SSID(indices[i])); + DEBUG_WM(WM_DEBUG_VERBOSE,F("AP: "),(String)WiFi.RSSI(indices[i]) + " " + (String)WiFi.SSID(indices[i])); #endif int rssiperc = getRSSIasQuality(WiFi.RSSI(indices[i])); @@ -1687,13 +1691,13 @@ String WiFiManager::WiFiManager::getScanItemOut(){ } } #ifdef WM_DEBUG_LEVEL - DEBUG_WM(DEBUG_DEV,item); + DEBUG_WM(WM_DEBUG_DEV,item); #endif page += item; delay(0); } else { #ifdef WM_DEBUG_LEVEL - DEBUG_WM(DEBUG_VERBOSE,F("Skipping , does not meet _minimumQuality")); + DEBUG_WM(WM_DEBUG_VERBOSE,F("Skipping , does not meet _minimumQuality")); #endif } @@ -1722,7 +1726,7 @@ String WiFiManager::getStaticOut(){ String page; if ((_staShowStaticFields || _sta_static_ip) && _staShowStaticFields>=0) { #ifdef WM_DEBUG_LEVEL - DEBUG_WM(DEBUG_DEV,F("_staShowStaticFields")); + DEBUG_WM(WM_DEBUG_DEV,F("_staShowStaticFields")); #endif page += FPSTR(HTTP_FORM_STATIC_HEAD); // @todo how can we get these accurate settings from memory , wifi_get_ip_info does not seem to reveal if struct ip_info is static or not @@ -1747,7 +1751,7 @@ String WiFiManager::getParamOut(){ String page; #ifdef WM_DEBUG_LEVEL - DEBUG_WM(DEBUG_DEV,F("getParamOut"),_paramsCount); + DEBUG_WM(WM_DEBUG_DEV,F("getParamOut"),_paramsCount); #endif if(_paramsCount > 0){ @@ -1767,10 +1771,10 @@ String WiFiManager::getParamOut(){ for (int i = 0; i < _paramsCount; i++) { //Serial.println((String)_params[i]->_length); - if (_params[i] == NULL || _params[i]->_length == 0 || _params[i]->_length > 99999) { + if (_params[i] == NULL || _params[i]->_length > 99999) { // try to detect param scope issues, doesnt always catch but works ok #ifdef WM_DEBUG_LEVEL - DEBUG_WM(DEBUG_ERROR,F("[ERROR] WiFiManagerParameter is out of scope")); + DEBUG_WM(WM_DEBUG_ERROR,F("[ERROR] WiFiManagerParameter is out of scope")); #endif return ""; } @@ -1821,7 +1825,7 @@ String WiFiManager::getParamOut(){ void WiFiManager::handleWiFiStatus(){ #ifdef WM_DEBUG_LEVEL - DEBUG_WM(DEBUG_VERBOSE,F("<- HTTP WiFi status ")); + DEBUG_WM(WM_DEBUG_VERBOSE,F("<- HTTP WiFi status ")); #endif handleRequest(); String page; @@ -1837,8 +1841,8 @@ void WiFiManager::handleWiFiStatus(){ */ void WiFiManager::handleWifiSave() { #ifdef WM_DEBUG_LEVEL - DEBUG_WM(DEBUG_VERBOSE,F("<- HTTP WiFi save ")); - DEBUG_WM(DEBUG_DEV,F("Method:"),server->method() == HTTP_GET ? (String)FPSTR(S_GET) : (String)FPSTR(S_POST)); + DEBUG_WM(WM_DEBUG_VERBOSE,F("<- HTTP WiFi save ")); + DEBUG_WM(WM_DEBUG_DEV,F("Method:"),server->method() == HTTP_GET ? (String)FPSTR(S_GET) : (String)FPSTR(S_POST)); #endif handleRequest(); @@ -1846,34 +1850,57 @@ void WiFiManager::handleWifiSave() { _ssid = server->arg(F("s")).c_str(); _pass = server->arg(F("p")).c_str(); + if(_ssid == "" && _pass != ""){ + _ssid = WiFi_SSID(true); // password change, placeholder ssid, @todo compare pass to old?, confirm ssid is clean + #ifdef WM_DEBUG_LEVEL + DEBUG_WM(WM_DEBUG_VERBOSE,F("Detected WiFi password change")); + #endif + } + + #ifdef WM_DEBUG_LEVEL + String requestinfo = "SERVER_REQUEST\n----------------\n"; + requestinfo += "URI: "; + requestinfo += server->uri(); + requestinfo += "\nMethod: "; + requestinfo += (server->method() == HTTP_GET) ? "GET" : "POST"; + requestinfo += "\nArguments: "; + requestinfo += server->args(); + requestinfo += "\n"; + for (uint8_t i = 0; i < server->args(); i++) { + requestinfo += " " + server->argName(i) + ": " + server->arg(i) + "\n"; + } + + DEBUG_WM(WM_DEBUG_MAX,requestinfo); + #endif + // set static ips from server args if (server->arg(FPSTR(S_ip)) != "") { //_sta_static_ip.fromString(server->arg(FPSTR(S_ip)); String ip = server->arg(FPSTR(S_ip)); optionalIPFromString(&_sta_static_ip, ip.c_str()); #ifdef WM_DEBUG_LEVEL - DEBUG_WM(DEBUG_DEV,F("static ip:"),ip); + DEBUG_WM(WM_DEBUG_DEV,F("static ip:"),ip); #endif } if (server->arg(FPSTR(S_gw)) != "") { String gw = server->arg(FPSTR(S_gw)); optionalIPFromString(&_sta_static_gw, gw.c_str()); #ifdef WM_DEBUG_LEVEL - DEBUG_WM(DEBUG_DEV,F("static gateway:"),gw); + DEBUG_WM(WM_DEBUG_DEV,F("static gateway:"),gw); #endif } if (server->arg(FPSTR(S_sn)) != "") { String sn = server->arg(FPSTR(S_sn)); optionalIPFromString(&_sta_static_sn, sn.c_str()); #ifdef WM_DEBUG_LEVEL - DEBUG_WM(DEBUG_DEV,F("static netmask:"),sn); + DEBUG_WM(WM_DEBUG_DEV,F("static netmask:"),sn); #endif } if (server->arg(FPSTR(S_dns)) != "") { String dns = server->arg(FPSTR(S_dns)); optionalIPFromString(&_sta_static_dns, dns.c_str()); #ifdef WM_DEBUG_LEVEL - DEBUG_WM(DEBUG_DEV,F("static DNS:"),dns); + DEBUG_WM(WM_DEBUG_DEV,F("static DNS:"),dns); #endif } @@ -1901,7 +1928,7 @@ void WiFiManager::handleWifiSave() { HTTPSend(page); #ifdef WM_DEBUG_LEVEL - DEBUG_WM(DEBUG_DEV,F("Sent wifi save page")); + DEBUG_WM(WM_DEBUG_DEV,F("Sent wifi save page")); #endif connect = true; //signal ready to connect/reset process in processConfigPortal @@ -1910,10 +1937,10 @@ void WiFiManager::handleWifiSave() { void WiFiManager::handleParamSave() { #ifdef WM_DEBUG_LEVEL - DEBUG_WM(DEBUG_VERBOSE,F("<- HTTP Param save ")); + DEBUG_WM(WM_DEBUG_VERBOSE,F("<- HTTP Param save ")); #endif #ifdef WM_DEBUG_LEVEL - DEBUG_WM(DEBUG_DEV,F("Method:"),server->method() == HTTP_GET ? (String)FPSTR(S_GET) : (String)FPSTR(S_POST)); + DEBUG_WM(WM_DEBUG_DEV,F("Method:"),server->method() == HTTP_GET ? (String)FPSTR(S_GET) : (String)FPSTR(S_POST)); #endif handleRequest(); @@ -1927,7 +1954,7 @@ void WiFiManager::handleParamSave() { HTTPSend(page); #ifdef WM_DEBUG_LEVEL - DEBUG_WM(DEBUG_DEV,F("Sent param save page")); + DEBUG_WM(WM_DEBUG_DEV,F("Sent param save page")); #endif } @@ -1940,14 +1967,14 @@ void WiFiManager::doParamSave(){ //parameters if(_paramsCount > 0){ #ifdef WM_DEBUG_LEVEL - DEBUG_WM(DEBUG_VERBOSE,F("Parameters")); - DEBUG_WM(DEBUG_VERBOSE,FPSTR(D_HR)); + DEBUG_WM(WM_DEBUG_VERBOSE,F("Parameters")); + DEBUG_WM(WM_DEBUG_VERBOSE,FPSTR(D_HR)); #endif for (int i = 0; i < _paramsCount; i++) { - if (_params[i] == NULL || _params[i]->_length == 0) { + if (_params[i] == NULL || _params[i]->_length > 99999) { #ifdef WM_DEBUG_LEVEL - DEBUG_WM(DEBUG_ERROR,F("[ERROR] WiFiManagerParameter is out of scope")); + DEBUG_WM(WM_DEBUG_ERROR,F("[ERROR] WiFiManagerParameter is out of scope")); #endif break; // @todo might not be needed anymore } @@ -1963,11 +1990,11 @@ void WiFiManager::doParamSave(){ //store it in params array value.toCharArray(_params[i]->_value, _params[i]->_length+1); // length+1 null terminated #ifdef WM_DEBUG_LEVEL - DEBUG_WM(DEBUG_VERBOSE,(String)_params[i]->getID() + ":",value); + DEBUG_WM(WM_DEBUG_VERBOSE,(String)_params[i]->getID() + ":",value); #endif } #ifdef WM_DEBUG_LEVEL - DEBUG_WM(DEBUG_VERBOSE,FPSTR(D_HR)); + DEBUG_WM(WM_DEBUG_VERBOSE,FPSTR(D_HR)); #endif } @@ -1982,7 +2009,7 @@ void WiFiManager::doParamSave(){ */ void WiFiManager::handleInfo() { #ifdef WM_DEBUG_LEVEL - DEBUG_WM(DEBUG_VERBOSE,F("<- HTTP Info")); + DEBUG_WM(WM_DEBUG_VERBOSE,F("<- HTTP Info")); #endif handleRequest(); String page = getHTTPHead(FPSTR(S_titleinfo)); // @token titleinfo @@ -2084,7 +2111,7 @@ void WiFiManager::handleInfo() { HTTPSend(page); #ifdef WM_DEBUG_LEVEL - DEBUG_WM(DEBUG_DEV,F("Sent info page")); + DEBUG_WM(WM_DEBUG_DEV,F("Sent info page")); #endif } @@ -2283,7 +2310,7 @@ String WiFiManager::getInfoData(String id){ // temperature is not calibrated, varying large offsets are present, use for relative temp changes only p = FPSTR(HTTP_INFO_temp); p.replace(FPSTR(T_1),(String)temperatureRead()); - p.replace(FPSTR(T_2),(String)((temperatureRead()+32)*1.8)); + p.replace(FPSTR(T_2),(String)((temperatureRead()+32)*1.8f)); } // else if(id==F("hall")){ // p = FPSTR(HTTP_INFO_hall); @@ -2327,7 +2354,7 @@ String WiFiManager::getInfoData(String id){ */ void WiFiManager::handleExit() { #ifdef WM_DEBUG_LEVEL - DEBUG_WM(DEBUG_VERBOSE,F("<- HTTP Exit")); + DEBUG_WM(WM_DEBUG_VERBOSE,F("<- HTTP Exit")); #endif handleRequest(); String page = getHTTPHead(FPSTR(S_titleexit)); // @token titleexit @@ -2344,7 +2371,7 @@ void WiFiManager::handleExit() { */ void WiFiManager::handleReset() { #ifdef WM_DEBUG_LEVEL - DEBUG_WM(DEBUG_VERBOSE,F("<- HTTP Reset")); + DEBUG_WM(WM_DEBUG_VERBOSE,F("<- HTTP Reset")); #endif handleRequest(); String page = getHTTPHead(FPSTR(S_titlereset)); //@token titlereset @@ -2369,7 +2396,7 @@ void WiFiManager::handleReset() { // } void WiFiManager::handleErase(boolean opt) { #ifdef WM_DEBUG_LEVEL - DEBUG_WM(DEBUG_NOTIFY,F("<- HTTP Erase")); + DEBUG_WM(WM_DEBUG_NOTIFY,F("<- HTTP Erase")); #endif handleRequest(); String page = getHTTPHead(FPSTR(S_titleerase)); // @token titleerase @@ -2380,7 +2407,7 @@ void WiFiManager::handleErase(boolean opt) { else { page += FPSTR(S_error); // @token erroroccur #ifdef WM_DEBUG_LEVEL - DEBUG_WM(DEBUG_ERROR,F("[ERROR] WiFi EraseConfig failed")); + DEBUG_WM(WM_DEBUG_ERROR,F("[ERROR] WiFi EraseConfig failed")); #endif } @@ -2403,16 +2430,20 @@ void WiFiManager::handleNotFound() { if (captivePortal()) return; // If captive portal redirect instead of displaying the page handleRequest(); String message = FPSTR(S_notfound); // @token notfound - message += FPSTR(S_uri); // @token uri - message += server->uri(); - message += FPSTR(S_method); // @token method - message += ( server->method() == HTTP_GET ) ? FPSTR(S_GET) : FPSTR(S_POST); - message += FPSTR(S_args); // @token args - message += server->args(); - message += F("\n"); - for ( uint8_t i = 0; i < server->args(); i++ ) { - message += " " + server->argName ( i ) + ": " + server->arg ( i ) + "\n"; + bool verbose404 = false; // show info in 404 body, uri,method, args + if(verbose404){ + message += FPSTR(S_uri); // @token uri + message += server->uri(); + message += FPSTR(S_method); // @token method + message += ( server->method() == HTTP_GET ) ? FPSTR(S_GET) : FPSTR(S_POST); + message += FPSTR(S_args); // @token args + message += server->args(); + message += F("\n"); + + for ( uint8_t i = 0; i < server->args(); i++ ) { + message += " " + server->argName ( i ) + ": " + server->arg ( i ) + "\n"; + } } server->sendHeader(F("Cache-Control"), F("no-cache, no-store, must-revalidate")); // @HTTPHEAD send cache server->sendHeader(F("Pragma"), F("no-cache")); @@ -2426,20 +2457,31 @@ void WiFiManager::handleNotFound() { * Return true in that case so the page handler do not try to handle the request again. */ boolean WiFiManager::captivePortal() { - #ifdef WM_DEBUG_LEVEL - DEBUG_WM(DEBUG_MAX,"-> " + server->hostHeader()); - #endif - if(!_enableCaptivePortal) return false; // skip redirections, @todo maybe allow redirection even when no cp ? might be useful + if(!_enableCaptivePortal || !configPortalActive) return false; // skip redirections if cp not enabled or not in ap mode String serverLoc = toStringIp(server->client().localIP()); + + #ifdef WM_DEBUG_LEVEL + DEBUG_WM(WM_DEBUG_DEV,"-> " + server->hostHeader()); + DEBUG_WM(WM_DEBUG_DEV,"serverLoc " + serverLoc); + #endif + + // fallback for ipv6 bug + if(serverLoc == "0.0.0.0"){ + if ((WiFi.status()) != WL_CONNECTED) + serverLoc = toStringIp(WiFi.softAPIP()); + else + serverLoc = toStringIp(WiFi.localIP()); + } + if(_httpPort != 80) serverLoc += ":" + (String)_httpPort; // add port if not default bool doredirect = serverLoc != server->hostHeader(); // redirect if hostheader not server ip, prevent redirect loops - // doredirect = !isIp(server->hostHeader()) // old check if (doredirect) { #ifdef WM_DEBUG_LEVEL - DEBUG_WM(DEBUG_VERBOSE,F("<- Request redirected to captive portal")); + DEBUG_WM(WM_DEBUG_VERBOSE,F("<- Request redirected to captive portal")); + DEBUG_WM(WM_DEBUG_DEV,"serverLoc " + serverLoc); #endif server->sendHeader(F("Location"), (String)F("http://") + serverLoc, true); // @HTTPHEAD send redirect server->send ( 302, FPSTR(HTTP_HEAD_CT2), ""); // Empty content inhibits Content-length header so we have to close the socket ourselves. @@ -2456,10 +2498,10 @@ void WiFiManager::stopCaptivePortal(){ // HTTPD CALLBACK, handle close, stop captive portal, if not enabled undefined void WiFiManager::handleClose(){ - DEBUG_WM(DEBUG_VERBOSE,F("Disabling Captive Portal")); + DEBUG_WM(WM_DEBUG_VERBOSE,F("Disabling Captive Portal")); stopCaptivePortal(); #ifdef WM_DEBUG_LEVEL - DEBUG_WM(DEBUG_VERBOSE,F("<- HTTP close")); + DEBUG_WM(WM_DEBUG_VERBOSE,F("<- HTTP close")); #endif handleRequest(); String page = getHTTPHead(FPSTR(S_titleclose)); // @token titleclose @@ -2469,8 +2511,8 @@ void WiFiManager::handleClose(){ void WiFiManager::reportStatus(String &page){ // updateConxResult(WiFi.status()); // @todo: this defeats the purpose of last result, update elsewhere or add logic here - DEBUG_WM(DEBUG_DEV,F("[WIFI] reportStatus prev:"),getWLStatusString(_lastconxresult)); - DEBUG_WM(DEBUG_DEV,F("[WIFI] reportStatus current:"),getWLStatusString(WiFi.status())); + DEBUG_WM(WM_DEBUG_DEV,F("[WIFI] reportStatus prev:"),getWLStatusString(_lastconxresult)); + DEBUG_WM(WM_DEBUG_DEV,F("[WIFI] reportStatus current:"),getWLStatusString(WiFi.status())); String str; if (WiFi_SSID() != ""){ if (WiFi.status()==WL_CONNECTED){ @@ -2537,7 +2579,7 @@ bool WiFiManager::stopConfigPortal(){ bool WiFiManager::disconnect(){ if(WiFi.status() != WL_CONNECTED){ #ifdef WM_DEBUG_LEVEL - DEBUG_WM(DEBUG_VERBOSE,F("Disconnecting: Not connected")); + DEBUG_WM(WM_DEBUG_VERBOSE,F("Disconnecting: Not connected")); #endif return false; } @@ -2580,11 +2622,11 @@ bool WiFiManager::erase(bool opt){ esp_err_t err; err = nvs_flash_init(); #ifdef WM_DEBUG_LEVEL - DEBUG_WM(DEBUG_VERBOSE,F("nvs_flash_init: "),err!=ESP_OK ? (String)err : "Success"); + DEBUG_WM(WM_DEBUG_VERBOSE,F("nvs_flash_init: "),err!=ESP_OK ? (String)err : "Success"); #endif err = nvs_flash_erase(); #ifdef WM_DEBUG_LEVEL - DEBUG_WM(DEBUG_VERBOSE,F("nvs_flash_erase: "), err!=ESP_OK ? (String)err : "Success"); + DEBUG_WM(WM_DEBUG_VERBOSE,F("nvs_flash_erase: "), err!=ESP_OK ? (String)err : "Success"); #endif return err == ESP_OK; } @@ -2597,7 +2639,7 @@ bool WiFiManager::erase(bool opt){ #endif bool ret = SPIFFS.format(); #ifdef WM_DEBUG_LEVEL - DEBUG_WM(DEBUG_VERBOSE,F("spiffs erase: "),ret ? "Success" : "ERROR"); + DEBUG_WM(WM_DEBUG_VERBOSE,F("spiffs erase: "),ret ? "Success" : "ERROR"); #endif } else{ #ifdef WM_DEBUG_LEVEL @@ -2715,7 +2757,8 @@ void WiFiManager::setSaveConnect(bool connect) { */ void WiFiManager::setDebugOutput(boolean debug) { _debug = debug; - if(_debug && _debugLevel == DEBUG_DEV) debugPlatformInfo(); + if(_debug && _debugLevel == WM_DEBUG_DEV) debugPlatformInfo(); + if(_debug && _debugLevel >= WM_DEBUG_NOTIFY)DEBUG_WM((__FlashStringHelper *)WM_VERSION_STR," D:"+String(_debugLevel)); } void WiFiManager::setDebugOutput(boolean debug, String prefix) { @@ -2723,6 +2766,13 @@ void WiFiManager::setDebugOutput(boolean debug, String prefix) { setDebugOutput(debug); } +void WiFiManager::setDebugOutput(boolean debug, wm_debuglevel_t level) { + _debugLevel = level; + // _debugPrefix = prefix; + setDebugOutput(debug); +} + + /** * [setAPStaticIPConfig description] * @access public @@ -3148,16 +3198,18 @@ void WiFiManager::setTitle(String title){ */ void WiFiManager::setMenu(const char * menu[], uint8_t size){ #ifdef WM_DEBUG_LEVEL - // DEBUG_WM(DEBUG_DEV,"setmenu array"); + // DEBUG_WM(WM_DEBUG_DEV,"setmenu array"); #endif _menuIds.clear(); for(size_t i = 0; i < size; i++){ for(size_t j = 0; j < _nummenutokens; j++){ - if(menu[i] == _menutokens[j]){ + if((String)menu[i] == (__FlashStringHelper *)(_menutokens[j])){ if((String)menu[i] == "param") _paramsInWifi = false; // param auto flag _menuIds.push_back(j); } + delay(0); } + delay(0); } #ifdef WM_DEBUG_LEVEL // DEBUG_WM(getMenuOut()); @@ -3175,19 +3227,19 @@ void WiFiManager::setMenu(const char * menu[], uint8_t size){ */ void WiFiManager::setMenu(std::vector& menu){ #ifdef WM_DEBUG_LEVEL - // DEBUG_WM(DEBUG_DEV,"setmenu vector"); + // DEBUG_WM(WM_DEBUG_DEV,"setmenu vector"); #endif _menuIds.clear(); for(auto menuitem : menu ){ for(size_t j = 0; j < _nummenutokens; j++){ - if(menuitem == _menutokens[j]){ + if((String)menuitem == (__FlashStringHelper *)(_menutokens[j])){ if((String)menuitem == "param") _paramsInWifi = false; // param auto flag _menuIds.push_back(j); } } } #ifdef WM_DEBUG_LEVEL - // DEBUG_WM(DEBUG_DEV,getMenuOut()); + // DEBUG_WM(WM_DEBUG_DEV,getMenuOut()); #endif } @@ -3317,7 +3369,7 @@ String WiFiManager::getWiFiPass(bool persistent){ // @todo fix DEBUG_WM(0,0); template void WiFiManager::DEBUG_WM(Generic text) { - DEBUG_WM(DEBUG_NOTIFY,text,""); + DEBUG_WM(WM_DEBUG_NOTIFY,text,""); } template @@ -3327,14 +3379,14 @@ void WiFiManager::DEBUG_WM(wm_debuglevel_t level,Generic text) { template void WiFiManager::DEBUG_WM(Generic text,Genericb textb) { - DEBUG_WM(DEBUG_NOTIFY,text,textb); + DEBUG_WM(WM_DEBUG_NOTIFY,text,textb); } template void WiFiManager::DEBUG_WM(wm_debuglevel_t level,Generic text,Genericb textb) { if(!_debug || _debugLevel < level) return; - if(_debugLevel >= DEBUG_MAX){ + if(_debugLevel >= WM_DEBUG_MAX){ #ifdef ESP8266 // uint32_t free; // uint16_t max; @@ -3357,6 +3409,7 @@ void WiFiManager::DEBUG_WM(wm_debuglevel_t level,Generic text,Genericb textb) { _debugPort.printf("[MEM] free: %5d | max: %5d | frag: %3d%% \n", free, max, frag); #endif } + _debugPort.print(_debugPrefix); if(_debugLevel >= debugLvlShow) _debugPort.print("["+(String)level+"] "); _debugPort.print(text); @@ -3486,8 +3539,8 @@ boolean WiFiManager::validApPassword(){ return false; // @todo FATAL or fallback to empty , currently fatal, fail secure. } #ifdef WM_DEBUG_LEVEL - DEBUG_WM(DEBUG_VERBOSE,F("AccessPoint set password is VALID")); - DEBUG_WM(DEBUG_DEV,"ap pass",_apPassword); + DEBUG_WM(WM_DEBUG_VERBOSE,F("AccessPoint set password is VALID")); + DEBUG_WM(WM_DEBUG_DEV,"ap pass",_apPassword); #endif } return true; @@ -3546,7 +3599,7 @@ bool WiFiManager::WiFiSetCountry(){ if(_wificountry == "") return false; // skip not set #ifdef WM_DEBUG_LEVEL - DEBUG_WM(DEBUG_VERBOSE,F("WiFiSetCountry to"),_wificountry); + DEBUG_WM(WM_DEBUG_VERBOSE,F("WiFiSetCountry to"),_wificountry); #endif /* @@ -3565,7 +3618,7 @@ bool WiFiManager::WiFiSetCountry(){ esp_err_t err = ESP_OK; // @todo check if wifi is init, no idea how, doesnt seem to be exposed atm ( check again it might be now! ) if(WiFi.getMode() == WIFI_MODE_NULL){ - DEBUG_WM(DEBUG_ERROR,"[ERROR] cannot set country, wifi not init"); + DEBUG_WM(WM_DEBUG_ERROR,"[ERROR] cannot set country, wifi not init"); } // exception if wifi not init! // Assumes that _wificountry is set to one of the supported country codes : "01"(world safe mode) "AT","AU","BE","BG","BR", // "CA","CH","CN","CY","CZ","DE","DK","EE","ES","FI","FR","GB","GR","HK","HR","HU", @@ -3578,15 +3631,15 @@ bool WiFiManager::WiFiSetCountry(){ #ifndef WM_NOCOUNTRY err = esp_wifi_set_country_code(_wificountry.c_str(), true); #else - DEBUG_WM(DEBUG_ERROR,"[ERROR] esp wifi set country is not available"); + DEBUG_WM(WM_DEBUG_ERROR,"[ERROR] esp wifi set country is not available"); err = true; #endif } #ifdef WM_DEBUG_LEVEL if(err){ - if(err == ESP_ERR_WIFI_NOT_INIT) DEBUG_WM(DEBUG_ERROR,"[ERROR] ESP_ERR_WIFI_NOT_INIT"); - else if(err == ESP_ERR_INVALID_ARG) DEBUG_WM(DEBUG_ERROR,"[ERROR] ESP_ERR_WIFI_ARG (invalid country code)"); - else if(err != ESP_OK)DEBUG_WM(DEBUG_ERROR,"[ERROR] unknown error",(String)err); + if(err == ESP_ERR_WIFI_NOT_INIT) DEBUG_WM(WM_DEBUG_ERROR,"[ERROR] ESP_ERR_WIFI_NOT_INIT"); + else if(err == ESP_ERR_INVALID_ARG) DEBUG_WM(WM_DEBUG_ERROR,"[ERROR] ESP_ERR_WIFI_ARG (invalid country code)"); + else if(err != ESP_OK)DEBUG_WM(WM_DEBUG_ERROR,"[ERROR] unknown error",(String)err); } #endif ret = err == ESP_OK; @@ -3597,13 +3650,13 @@ bool WiFiManager::WiFiSetCountry(){ else if(_wificountry == "JP") ret = wifi_set_country((wifi_country_t*)&WM_COUNTRY_JP); else if(_wificountry == "CN") ret = wifi_set_country((wifi_country_t*)&WM_COUNTRY_CN); #ifdef WM_DEBUG_LEVEL - else DEBUG_WM(DEBUG_ERROR,F("[ERROR] country code not found")); + else DEBUG_WM(WM_DEBUG_ERROR,F("[ERROR] country code not found")); #endif #endif #ifdef WM_DEBUG_LEVEL - if(ret) DEBUG_WM(DEBUG_VERBOSE,F("esp_wifi_set_country SUCCESS: "),_wificountry); - else DEBUG_WM(DEBUG_ERROR,F("[ERROR] esp_wifi_set_country FAILED")); + if(ret) DEBUG_WM(WM_DEBUG_VERBOSE,F("[OK] esp_wifi_set_country: "),_wificountry); + else DEBUG_WM(WM_DEBUG_ERROR,F("[ERROR] esp_wifi_set_country failed")); #endif return ret; } @@ -3637,7 +3690,7 @@ bool WiFiManager::WiFi_Disconnect() { if((WiFi.getMode() & WIFI_STA) != 0) { bool ret; #ifdef WM_DEBUG_LEVEL - DEBUG_WM(DEBUG_DEV,F("WiFi station disconnect")); + DEBUG_WM(WM_DEBUG_DEV,F("WiFi station disconnect")); #endif ETS_UART_INTR_DISABLE(); // @todo possibly not needed ret = wifi_station_disconnect(); @@ -3646,7 +3699,7 @@ bool WiFiManager::WiFi_Disconnect() { } #elif defined(ESP32) #ifdef WM_DEBUG_LEVEL - DEBUG_WM(DEBUG_DEV,F("WiFi station disconnect")); + DEBUG_WM(WM_DEBUG_DEV,F("WiFi station disconnect")); #endif return WiFi.disconnect(); // not persistent atm #endif @@ -3656,7 +3709,7 @@ bool WiFiManager::WiFi_Disconnect() { // toggle STA without persistent bool WiFiManager::WiFi_enableSTA(bool enable,bool persistent) { #ifdef WM_DEBUG_LEVEL - DEBUG_WM(DEBUG_DEV,F("WiFi_enableSTA"),(String) enable? "enable" : "disable"); + DEBUG_WM(WM_DEBUG_DEV,F("WiFi_enableSTA"),(String) enable? "enable" : "disable"); #endif #ifdef ESP8266 WiFiMode_t newMode; @@ -3668,7 +3721,7 @@ bool WiFiManager::WiFi_enableSTA(bool enable,bool persistent) { if((isEnabled != enable) || persistent) { if(enable) { #ifdef WM_DEBUG_LEVEL - if(persistent) DEBUG_WM(DEBUG_DEV,F("enableSTA PERSISTENT ON")); + if(persistent) DEBUG_WM(WM_DEBUG_DEV,F("enableSTA PERSISTENT ON")); #endif return WiFi_Mode(newMode,persistent); } @@ -3693,7 +3746,7 @@ bool WiFiManager::WiFi_enableSTA(bool enable) { bool WiFiManager::WiFi_eraseConfig() { #ifdef WM_DEBUG_LEVEL - DEBUG_WM(DEBUG_DEV,F("WiFi_eraseConfig")); + DEBUG_WM(WM_DEBUG_DEV,F("WiFi_eraseConfig")); #endif #ifdef ESP8266 @@ -3801,7 +3854,7 @@ String WiFiManager::WiFi_psk(bool persistent) const { #endif if(!_hasBegun){ #ifdef WM_DEBUG_LEVEL - // DEBUG_WM(DEBUG_VERBOSE,"[ERROR] WiFiEvent, not ready"); + // DEBUG_WM(WM_DEBUG_VERBOSE,"[ERROR] WiFiEvent, not ready"); #endif // Serial.println(F("\n[EVENT] WiFiEvent logging (wm debug not available)")); // Serial.print(F("[EVENT] ID: ")); @@ -3809,25 +3862,25 @@ String WiFiManager::WiFi_psk(bool persistent) const { return; } #ifdef WM_DEBUG_LEVEL - // DEBUG_WM(DEBUG_VERBOSE,"[EVENT]",event); + // DEBUG_WM(WM_DEBUG_VERBOSE,"[EVENT]",event); #endif if(event == ARDUINO_EVENT_WIFI_STA_DISCONNECTED){ #ifdef WM_DEBUG_LEVEL - DEBUG_WM(DEBUG_VERBOSE,F("[EVENT] WIFI_REASON: "),info.wifi_sta_disconnected.reason); + DEBUG_WM(WM_DEBUG_VERBOSE,F("[EVENT] WIFI_REASON: "),info.wifi_sta_disconnected.reason); #endif if(info.wifi_sta_disconnected.reason == WIFI_REASON_AUTH_EXPIRE || info.wifi_sta_disconnected.reason == WIFI_REASON_AUTH_FAIL){ _lastconxresulttmp = 7; // hack in wrong password internally, sdk emit WIFI_REASON_AUTH_EXPIRE on some routers on auth_fail } else _lastconxresulttmp = WiFi.status(); #ifdef WM_DEBUG_LEVEL - if(info.wifi_sta_disconnected.reason == WIFI_REASON_NO_AP_FOUND) DEBUG_WM(DEBUG_VERBOSE,F("[EVENT] WIFI_REASON: NO_AP_FOUND")); + if(info.wifi_sta_disconnected.reason == WIFI_REASON_NO_AP_FOUND) DEBUG_WM(WM_DEBUG_VERBOSE,F("[EVENT] WIFI_REASON: NO_AP_FOUND")); if(info.wifi_sta_disconnected.reason == WIFI_REASON_ASSOC_FAIL){ if(_aggresiveReconn) _connectRetries+=4; - DEBUG_WM(DEBUG_VERBOSE,F("[EVENT] WIFI_REASON: AUTH FAIL")); + DEBUG_WM(WM_DEBUG_VERBOSE,F("[EVENT] WIFI_REASON: AUTH FAIL")); } #endif #ifdef esp32autoreconnect #ifdef WM_DEBUG_LEVEL - DEBUG_WM(DEBUG_VERBOSE,F("[Event] SYSTEM_EVENT_STA_DISCONNECTED, reconnecting")); + DEBUG_WM(WM_DEBUG_VERBOSE,F("[Event] SYSTEM_EVENT_STA_DISCONNECTED, reconnecting")); #endif WiFi.reconnect(); #endif @@ -3846,7 +3899,7 @@ void WiFiManager::WiFi_autoReconnect(){ // if(_wifiAutoReconnect){ // @todo move to seperate method, used for event listener now #ifdef WM_DEBUG_LEVEL - DEBUG_WM(DEBUG_VERBOSE,F("ESP32 event handler enabled")); + DEBUG_WM(WM_DEBUG_VERBOSE,F("ESP32 event handler enabled")); #endif using namespace std::placeholders; if(wm_event_id == 0) wm_event_id = WiFi.onEvent(std::bind(&WiFiManager::WiFiEvent,this,_1,_2)); @@ -3905,7 +3958,7 @@ bool WiFiManager::getFastConConfig(String ssid){ // Called when /update is requested void WiFiManager::handleUpdate() { #ifdef WM_DEBUG_LEVEL - DEBUG_WM(DEBUG_VERBOSE,F("<- Handle update")); + DEBUG_WM(WM_DEBUG_VERBOSE,F("<- Handle update")); #endif if (captivePortal()) return; // If captive portal redirect instead of displaying the page String page = getHTTPHead(_title); // @token options @@ -3963,7 +4016,7 @@ void WiFiManager::handleUpdating(){ #endif #ifdef WM_DEBUG_LEVEL - DEBUG_WM(DEBUG_VERBOSE,"[OTA] Update file: ", upload.filename.c_str()); + DEBUG_WM(WM_DEBUG_VERBOSE,"[OTA] Update file: ", upload.filename.c_str()); #endif // Update.onProgress(THandlerFunction_Progress fn); @@ -3973,7 +4026,7 @@ void WiFiManager::handleUpdating(){ if (!Update.begin(maxSketchSpace)) { // start with max available size #ifdef WM_DEBUG_LEVEL - DEBUG_WM(DEBUG_ERROR,F("[ERROR] OTA Update ERROR"), Update.getError()); + DEBUG_WM(WM_DEBUG_ERROR,F("[ERROR] OTA Update ERROR"), Update.getError()); #endif error = true; Update.end(); // Not sure the best way to abort, I think client will keep sending.. @@ -3984,7 +4037,7 @@ void WiFiManager::handleUpdating(){ // Serial.print("."); if (Update.write(upload.buf, upload.currentSize) != upload.currentSize) { #ifdef WM_DEBUG_LEVEL - DEBUG_WM(DEBUG_ERROR,F("[ERROR] OTA Update WRITE ERROR"), Update.getError()); + DEBUG_WM(WM_DEBUG_ERROR,F("[ERROR] OTA Update WRITE ERROR"), Update.getError()); //Update.printError(Serial); // write failure #endif error = true; @@ -3994,7 +4047,7 @@ void WiFiManager::handleUpdating(){ else if (upload.status == UPLOAD_FILE_END) { if (Update.end(true)) { // true to set the size to the current progress #ifdef WM_DEBUG_LEVEL - DEBUG_WM(DEBUG_VERBOSE,F("\n\n[OTA] OTA FILE END bytes: "), upload.totalSize); + DEBUG_WM(WM_DEBUG_VERBOSE,F("\n\n[OTA] OTA FILE END bytes: "), upload.totalSize); // Serial.printf("Updated: %u bytes\r\nRebooting...\r\n", upload.totalSize); #endif } @@ -4015,7 +4068,7 @@ void WiFiManager::handleUpdating(){ // upload and ota done, show status void WiFiManager::handleUpdateDone() { - DEBUG_WM(DEBUG_VERBOSE, F("<- Handle update done")); + DEBUG_WM(WM_DEBUG_VERBOSE, F("<- Handle update done")); // if (captivePortal()) return; // If captive portal redirect instead of displaying the page String page = getHTTPHead(FPSTR(S_options)); // @token options diff --git a/WiFiManager.h b/WiFiManager.h index afda5a275..c4c8be55d 100644 --- a/WiFiManager.h +++ b/WiFiManager.h @@ -235,6 +235,16 @@ class WiFiManagerParameter { }; + // debugging + typedef enum { + WM_DEBUG_SILENT = 0, // debug OFF but still compiled for runtime + WM_DEBUG_ERROR = 1, // error only + WM_DEBUG_NOTIFY = 2, // default stable,INFO + WM_DEBUG_VERBOSE = 3, // move verbose info + WM_DEBUG_DEV = 4, // development useful debugging info + WM_DEBUG_MAX = 5 // MAX extra dev auditing, var dumps etc (MAX+1 will print timing,mem and frag info) + } wm_debuglevel_t; + class WiFiManager { public: @@ -339,6 +349,7 @@ class WiFiManager // toggle debug output void setDebugOutput(boolean debug); void setDebugOutput(boolean debug, String prefix); // log line prefix, default "*wm:" + void setDebugOutput(boolean debug, wm_debuglevel_t level ); // log line prefix, default "*wm:" //set min quality percentage to include in scan, defaults to 8% if not specified void setMinimumSignalQuality(int quality = 8); @@ -425,9 +436,6 @@ class WiFiManager // see _menutokens for ids void setMenu(std::vector& menu); void setMenu(const char* menu[], uint8_t size); - - // if true enable Fast connect mode - void setFastConnectMode(bool enabled); // set the webapp title, default WiFiManager void setTitle(String title); @@ -541,7 +549,6 @@ class WiFiManager WiFiMode_t _usermode = WIFI_STA; // Default user mode String _wifissidprefix = FPSTR(S_ssidpre); // auto apname prefix prefix+chipid - int _cpclosedelay = 2000; // delay before wifisave, prevents captive portal from closing to fast. bool _cleanConnect = false; // disconnect before connect in connectwifi, increases stability on connects bool _connectonsave = true; // connect to wifi when saving creds @@ -611,20 +618,21 @@ class WiFiManager // but not limited to, we could run continuous background scans on various page hits, or xhr hits // which would be better coupled with asyncscan // atm preload is only done on root hit and startcp - boolean _preloadwifiscan = true; // preload wifiscan if true + // + // preload scanning causes AP to delay showing for users, but also caches and lets the cp load faster once its open + // my scan takes 7-10 seconds + public: + boolean _preloadwifiscan = false; // preload wifiscan if true unsigned int _scancachetime = 30000; // ms cache time for preload scans - boolean _asyncScan = true; // perform wifi network scan async + boolean _asyncScan = false; // perform wifi network scan async + + private: boolean _autoforcerescan = false; // automatically force rescan if scan networks is 0, ignoring cache boolean _disableIpFields = false; // modify function of setShow_X_Fields(false), forces ip fields off instead of default show if set, eg. _staShowStaticFields=-1 String _wificountry = ""; // country code, @todo define in strings lang - - //fast mode to set mac address and channel during begin - boolean _fastConnectMode = false; - uint8_t* _fastConnectBSSID; - uint32_t _fastConnectChannel = 0; // wrapper functions for handling setting and unsetting persistent for now. bool esp32persistent = false; @@ -653,16 +661,18 @@ class WiFiManager uint8_t waitForConnectResult(); uint8_t waitForConnectResult(uint32_t timeout); void updateConxResult(uint8_t status); - bool getFastConConfig(String ssid); // webserver handlers - void HTTPSend(String content); +public: + void handleNotFound(); +private: + void HTTPSend(const String &content); void handleRoot(); void handleWifi(boolean scan); void handleWifiSave(); void handleInfo(); void handleReset(); - void handleNotFound(); + void handleExit(); void handleClose(); // void handleErase(); @@ -757,8 +767,15 @@ class WiFiManager boolean abort = false; boolean reset = false; boolean configPortalActive = false; + + + // these are state flags for portal mode, we are either in webportal mode(STA) or configportal mode(AP) + // these are mutually exclusive as STA+AP mode is not supported due to channel restrictions and stability + // if we decide to support this, these checks will need to be replaced with something client aware to check if client origin is ap or web + // These state checks are critical and used for internal function checks boolean webPortalActive = false; boolean portalTimeoutResult = false; + boolean portalAbortResult = false; boolean storeSTAmode = true; // option store persistent STA mode in connectwifi int timer = 0; // timer for debug throttle for numclients, and portal timeout messages @@ -768,27 +785,17 @@ class WiFiManager int _max_params; WiFiManagerParameter** _params = NULL; - // debugging - typedef enum { - DEBUG_ERROR = 0, - DEBUG_NOTIFY = 1, // alias - DEBUG_INFO = 1, // default stable - DEBUG_VERBOSE = 2, - DEBUG_DEV = 3, // default dev - DEBUG_MAX = 4 - } wm_debuglevel_t; - boolean _debug = true; String _debugPrefix = FPSTR(S_debugPrefix); - wm_debuglevel_t debugLvlShow = DEBUG_VERBOSE; // at which level start showing [n] level tags + wm_debuglevel_t debugLvlShow = WM_DEBUG_VERBOSE; // at which level start showing [n] level tags // build debuglevel support // @todo use DEBUG_ESP_x? // Set default debug level #ifndef WM_DEBUG_LEVEL - #define WM_DEBUG_LEVEL DEBUG_NOTIFY + #define WM_DEBUG_LEVEL WM_DEBUG_NOTIFY #endif // override debug level OFF @@ -799,7 +806,7 @@ class WiFiManager #ifdef WM_DEBUG_LEVEL uint8_t _debugLevel = (uint8_t)WM_DEBUG_LEVEL; #else - uint8_t _debugLevel = DEBUG_INFO; // default debug level + uint8_t _debugLevel = 0; // default debug level #endif // @todo use DEBUG_ESP_PORT ? diff --git a/examples/Super/OnDemandConfigPortal/OnDemandConfigPortal.ino b/examples/Super/OnDemandConfigPortal/OnDemandConfigPortal.ino index 41cdaaffa..0662a23a5 100644 --- a/examples/Super/OnDemandConfigPortal/OnDemandConfigPortal.ino +++ b/examples/Super/OnDemandConfigPortal/OnDemandConfigPortal.ino @@ -20,7 +20,6 @@ unsigned long mtime = 0; WiFiManager wm; -// WiFiManager wm(Serial); // pass in debug out io stream/print // TEST OPTION FLAGS @@ -32,6 +31,8 @@ bool ALLOWONDEMAND = true; // enable on demand int ONDDEMANDPIN = 0; // gpio for button bool WMISBLOCKING = true; // use blocking or non blocking mode, non global params wont work in non blocking +uint8_t BUTTONFUNC = 1; // 0 resetsettings, 1 configportal, 2 autoconnect + // char ssid[] = "*************"; // your network SSID (name) // char pass[] = "********"; // your network password @@ -73,15 +74,24 @@ void saveParamCallback(){ } void bindServerCallback(){ - wm.server->on("/custom",handleRoute); // this is now crashing esp32 for some reason - // wm.server->on("/info",handleRoute); // you can override wm! + wm.server->on("/custom",handleRoute); + + // you can override wm route endpoints, I have not found a way to remove handlers, but this would let you disable them or add auth etc. + // wm.server->on("/info",handleNotFound); + // wm.server->on("/update",handleNotFound); + wm.server->on("/erase",handleNotFound); // disable erase } void handleRoute(){ - Serial.println("[HTTP] handle route"); + Serial.println("[HTTP] handle custom route"); wm.server->send(200, "text/plain", "hello from user code"); } +void handleNotFound(){ + Serial.println("[HTTP] override handle route"); + wm.handleNotFound(); +} + void handlePreOtaUpdateCallback(){ Update.onProgress([](unsigned int progress, unsigned int total) { Serial.printf("CUSTOM Progress: %u%%\r", (progress / (total / 100))); @@ -93,9 +103,11 @@ void setup() { // put your setup code here, to run once: Serial.begin(115200); - + delay(3000); // Serial.setDebugOutput(true); + // WiFi.setTxPower(WIFI_POWER_8_5dBm); + Serial.println("\n Starting"); // WiFi.setSleepMode(WIFI_NONE_SLEEP); // disable sleep, can improve ap stability @@ -105,13 +117,13 @@ void setup() { Serial.println("[ERROR] TEST"); Serial.println("[INFORMATION] TEST"); - wm.debugPlatformInfo(); // debug info about eso platform - // wm.setDebugOutput(true, "[WM] "); // enable debugging, optional custom log prefix // WiFi.setScanMethod(WIFI_ALL_CHANNEL_SCAN); // wifi_scan_method_t scanMethod // WiFi.setSortMethod(WIFI_CONNECT_AP_BY_SIGNAL); // wifi_sort_method_t sortMethod - WIFI_CONNECT_AP_BY_SIGNAL,WIFI_CONNECT_AP_BY_SECURITY // WiFi.setMinSecurity(WIFI_AUTH_WPA2_PSK); + wm.setDebugOutput(true, WM_DEBUG_DEV); + wm.debugPlatformInfo(); //reset settings - for testing // wm.resetSettings(); @@ -128,7 +140,7 @@ void setup() { WiFiManagerParameter custom_input_type("input_pwd", "input pass", "", 15,"type='password'"); // custom input attrs (ip mask) const char _customHtml_checkbox[] = "type=\"checkbox\""; - WiFiManagerParameter custom_checkbox("my_checkbox", "My Checkbox", "T", 2, _customHtml_checkbox,WFM_LABEL_AFTER); + WiFiManagerParameter custom_checkbox("my_checkbox", "My Checkbox", "T", 2, _customHtml_checkbox, WFM_LABEL_AFTER); const char *bufferStr = R"( @@ -206,7 +218,7 @@ void setup() { */ std::vector menu = {"wifi","wifinoscan","info","param","custom","close","sep","erase","update","restart","exit"}; - wm.setMenu(menu); // custom menu, pass vector + // wm.setMenu(menu); // custom menu, pass vector // wm.setParamsPage(true); // move params to seperate page, not wifi, do not combine with setmenu! @@ -221,14 +233,13 @@ void setup() { // set country // setting wifi country seems to improve OSX soft ap connectivity, - // setting country also seems to improve sta connection times for some reason // may help others as well, default is CN which has different channels // wm.setCountry("US"); // crashing on esp32 2.0 // set Hostname - wm.setHostname(("WM_"+wm.getDefaultAPName()).c_str()); + // wm.setHostname(("WM_"+wm.getDefaultAPName()).c_str()); // wm.setHostname("WM_RANDO_1234"); // set custom channel @@ -249,7 +260,7 @@ void setup() { //sets timeout until configuration portal gets turned off //useful to make it all retry or go to sleep in seconds - wm.setConfigPortalTimeout(120); + wm.setConfigPortalTimeout(TESP_CP_TIMEOUT); // set min quality to show in web list, default 8% // wm.setMinimumSignalQuality(50); @@ -284,9 +295,6 @@ void setup() { // use autoconnect, but prevent configportal from auto starting // wm.setEnableConfigPortal(false); - // force esp to store channel and bssid for faster connections (theoretically 2-3x faster connections) - wm.setFastConnectMode(true); - wifiInfo(); // to preload autoconnect with credentials @@ -318,12 +326,12 @@ void setup() { void wifiInfo(){ // can contain gargbage on esp32 if wifi is not ready yet - Serial.println("[WIFI] WIFI INFO DEBUG"); + Serial.println("[WIFI] WIFI_INFO DEBUG"); // WiFi.printDiag(Serial); Serial.println("[WIFI] SAVED: " + (String)(wm.getWiFiIsSaved() ? "YES" : "NO")); Serial.println("[WIFI] SSID: " + (String)wm.getWiFiSSID()); Serial.println("[WIFI] PASS: " + (String)wm.getWiFiPass()); - Serial.println("[WIFI] HOSTNAME: " + (String)WiFi.getHostname()); + // Serial.println("[WIFI] HOSTNAME: " + (String)WiFi.getHostname()); } void loop() { @@ -332,31 +340,40 @@ void loop() { wm.process(); } + #ifdef USEOTA ArduinoOTA.handle(); #endif // is configuration portal requested? if (ALLOWONDEMAND && digitalRead(ONDDEMANDPIN) == LOW ) { delay(100); - if ( digitalRead(ONDDEMANDPIN) == LOW ){ + if ( digitalRead(ONDDEMANDPIN) == LOW || BUTTONFUNC == 2){ Serial.println("BUTTON PRESSED"); // button reset/reboot - // wm.resetSettings(); - // wm.reboot(); - // delay(200); - // return; + if(BUTTONFUNC == 0){ + wm.resetSettings(); + wm.reboot(); + delay(200); + return; + } - wm.setConfigPortalTimeout(140); - wm.setParamsPage(false); // move params to seperate page, not wifi, do not combine with setmenu! + // start configportal + if(BUTTONFUNC == 1){ + if (!wm.startConfigPortal("OnDemandAP","12345678")) { + Serial.println("failed to connect and hit timeout"); + delay(3000); + } + return; + } - // disable captive portal redirection - // wm.setCaptivePortalEnable(false); - - if (!wm.startConfigPortal("OnDemandAP","12345678")) { - Serial.println("failed to connect and hit timeout"); - delay(3000); + //test autoconnect as reconnect etc. + if(BUTTONFUNC == 2){ + wm.setConfigPortalTimeout(TESP_CP_TIMEOUT); + wm.autoConnect(); + return; } + } else { //if you get here you have connected to the WiFi @@ -366,7 +383,7 @@ void loop() { } // every 10 seconds - if(millis()-mtime > 30000 ){ + if(millis()-mtime > 10000 ){ if(WiFi.status() == WL_CONNECTED){ getTime(); } diff --git a/extras/WiFiManager.template.html b/extras/WiFiManager.template.html index 20787e139..934c03394 100644 --- a/extras/WiFiManager.template.html +++ b/extras/WiFiManager.template.html @@ -227,6 +227,7 @@

/





+


@@ -251,7 +252,7 @@

/wifi


-


Show Password
+


custom parameter


diff --git a/library.json b/library.json index 6b92d24a6..417cf64c8 100644 --- a/library.json +++ b/library.json @@ -1,6 +1,6 @@ { "name": "WiFiManager", - "version": "2.0.15-rc.1", + "version": "2.0.16-rc.2", "keywords": "wifi,wi-fi,esp,esp8266,esp32,espressif8266,espressif32,nodemcu,wemos,arduino", "description": "WiFi Configuration manager with web configuration portal for ESP boards", "authors": diff --git a/library.properties b/library.properties index d35882361..784f07217 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=WiFiManager -version=2.0.15-rc.1 +version=2.0.16-rc.2 author=tzapu maintainer=tablatronix sentence=WiFi Configuration manager with web configuration portal for Espressif ESPx boards, by tzapu diff --git a/wm_consts_en.h b/wm_consts_en.h index fc21b42ff..b1c615f46 100644 --- a/wm_consts_en.h +++ b/wm_consts_en.h @@ -19,20 +19,32 @@ const char WM_VERSION_STR[] PROGMEM = "v2.0.15-rc.1"; -const uint8_t _nummenutokens = 11; -const char * const _menutokens[_nummenutokens] PROGMEM = { - "wifi", - "wifinoscan", - "info", - "param", - "close", - "restart", - "exit", - "erase", - "update", - "sep", - "custom" +static const char _wifi_token[] PROGMEM = "wifi"; +static const char _wifinoscan_token[] PROGMEM = "wifinoscan"; +static const char _info_token[] PROGMEM = "info"; +static const char _param_token[] PROGMEM = "param"; +static const char _close_token[] PROGMEM = "close"; +static const char _restart_token[] PROGMEM = "restart"; +static const char _exit_token[] PROGMEM = "exit"; +static const char _erase_token[] PROGMEM = "erase"; +static const char _update_token[] PROGMEM = "update"; +static const char _sep_token[] PROGMEM = "sep"; +static const char _custom_token[] PROGMEM = "custom"; +static PGM_P _menutokens[] PROGMEM = { + _wifi_token, + _wifinoscan_token, + _info_token, + _param_token, + _close_token, + _restart_token, + _exit_token, + _erase_token, + _update_token, + _sep_token, + _custom_token }; +const uint8_t _nummenutokens = (sizeof(_menutokens) / sizeof(PGM_P)); + const char R_root[] PROGMEM = "/"; const char R_wifi[] PROGMEM = "/wifi"; diff --git a/wm_strings_es.h b/wm_strings_es.h new file mode 100644 index 000000000..781d0553c --- /dev/null +++ b/wm_strings_es.h @@ -0,0 +1,282 @@ +/** + * SAMPLE SAMPLE SAMPLE + * + * wm_strings_es.h + * spanish strings for + * WiFiManager, a library for the ESPX/Arduino platform + * for configuration of WiFi credentials using a Captive Portal + * + * @author Creator tzapu + * @author tablatronix + * @version 0.0.0 + * @license MIT + */ + +#ifndef _WM_STRINGS_EN_H_ +#define _WM_STRINGS_EN_H_ + + +/** + * ADD TO BUILD FLAGS + * -DWM_STRINGS_FILE="\"wm_strings_es.h\"" + */ + +#ifndef WIFI_MANAGER_OVERRIDE_STRINGS +// !!! ABOVE WILL NOT WORK if you define in your sketch, must be build flag, if anyone one knows how to order includes to be able to do this it would be neat.. I have seen it done.. + +// strings files must include a consts file! +// Copy and change to custom locale tokens if necessary, but strings should be good enough +#include "wm_consts_en.h" // include constants, tokens, routes + +const char WM_LANGUAGE[] PROGMEM = "es-ES"; // i18n lang code + +const char HTTP_HEAD_START[] PROGMEM = "" +"" +"" +"" +"" +"{v}"; + +const char HTTP_SCRIPT[] PROGMEM = ""; // @todo add button states, disable on click , show ack , spinner etc + +const char HTTP_HEAD_END[] PROGMEM = "
"; // {c} = _bodyclass +// example of embedded logo, base64 encoded inline, No styling here +// const char HTTP_ROOT_MAIN[] PROGMEM = "

{v}

WiFiManager

"; +const char HTTP_ROOT_MAIN[] PROGMEM = "

{t}

{v}

"; + +const char * const HTTP_PORTAL_MENU[] PROGMEM = { +"
\n", // MENU_WIFI +"

\n", // MENU_WIFINOSCAN +"

\n", // MENU_INFO +"

\n",//MENU_PARAM +"

\n", // MENU_CLOSE +"

\n",// MENU_RESTART +"

\n", // MENU_EXIT +"

\n", // MENU_ERASE +"

\n",// MENU_UPDATE +"

" // MENU_SEP +}; + +// const char HTTP_PORTAL_OPTIONS[] PROGMEM = strcat(HTTP_PORTAL_MENU[0] , HTTP_PORTAL_MENU[3] , HTTP_PORTAL_MENU[7]); +const char HTTP_PORTAL_OPTIONS[] PROGMEM = ""; +const char HTTP_ITEM_QI[] PROGMEM = ""; // rssi icons +const char HTTP_ITEM_QP[] PROGMEM = "
{r}%
"; // rssi percentage {h} = hidden showperc pref +const char HTTP_ITEM[] PROGMEM = "
{v}{qi}{qp}
"; // {q} = HTTP_ITEM_QI, {r} = HTTP_ITEM_QP +// const char HTTP_ITEM[] PROGMEM = "
{v} {R} {r}% {q} {e}
"; // test all tokens + +const char HTTP_FORM_START[] PROGMEM = "
"; +const char HTTP_FORM_WIFI[] PROGMEM = "
Mostrar contraseña"; +const char HTTP_FORM_WIFI_END[] PROGMEM = ""; +const char HTTP_FORM_STATIC_HEAD[] PROGMEM = "

"; +const char HTTP_FORM_END[] PROGMEM = "

"; +const char HTTP_FORM_LABEL[] PROGMEM = ""; +const char HTTP_FORM_PARAM_HEAD[] PROGMEM = "

"; +const char HTTP_FORM_PARAM[] PROGMEM = "
\n"; // do not remove newline! + +const char HTTP_SCAN_LINK[] PROGMEM = "
"; +const char HTTP_SAVED[] PROGMEM = "
Saving Credentials
Trying to connect ESP to network.
If it fails reconnect to AP to try again
"; +const char HTTP_PARAMSAVED[] PROGMEM = "
Saved
"; +const char HTTP_END[] PROGMEM = "
"; +const char HTTP_ERASEBTN[] PROGMEM = "
"; +const char HTTP_UPDATEBTN[] PROGMEM = "
"; +const char HTTP_BACKBTN[] PROGMEM = "

"; + +const char HTTP_STATUS_ON[] PROGMEM = "
Conectado a {v}
con IP {i}
"; +const char HTTP_STATUS_OFF[] PROGMEM = "
No conectado a {v}{r}
"; // {c=class} {v=ssid} {r=status_off} +const char HTTP_STATUS_OFFPW[] PROGMEM = "
Authentication Failure"; // STATION_WRONG_PASSWORD, no eps32 +const char HTTP_STATUS_OFFNOAP[] PROGMEM = "
No Encontrado"; // WL_NO_SSID_AVAIL +const char HTTP_STATUS_OFFFAIL[] PROGMEM = "
No se pudo conectar"; // WL_CONNECT_FAILED +const char HTTP_STATUS_NONE[] PROGMEM = "
Sin AP establecido
"; +const char HTTP_BR[] PROGMEM = "
"; + +const char HTTP_STYLE[] PROGMEM = ""; + +#ifndef WM_NOHELP +const char HTTP_HELP[] PROGMEM = + "

Available Pages


" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "
PageFunction
/Menu page.
/wifiShow WiFi scan results and enter WiFi configuration.(/0wifi noscan)
/wifisaveSave WiFi configuration information and configure device. Needs variables supplied.
/paramParameter page
/infoInformation page
/uOTA Update
/closeClose the captiveportal popup,configportal will remain active
/exitExit Config Portal, configportal will close
/restartReboot the device
/eraseErase WiFi configuration and reboot Device. Device will not reconnect to a network until new WiFi configuration data is entered.
" + "

Github https://github.com/tzapu/WiFiManager."; +#else +const char HTTP_HELP[] PROGMEM = ""; +#endif + +const char HTTP_UPDATE[] PROGMEM = "Upload New Firmware

* May not function inside captive portal, Open in browser http://192.168.4.1"; +const char HTTP_UPDATE_FAIL[] PROGMEM = "
Update Failed!
Reboot device and try again
"; +const char HTTP_UPDATE_SUCCESS[] PROGMEM = "
Update Successful.
Device Rebooting now...
"; + +#ifdef WM_JSTEST +const char HTTP_JS[] PROGMEM = +""; +#endif + +// Info html +// @todo remove html elements from progmem, repetetive strings +#ifdef ESP32 + const char HTTP_INFO_esphead[] PROGMEM = "

esp32


"; + const char HTTP_INFO_chiprev[] PROGMEM = "
Chip Rev
{1}
"; + const char HTTP_INFO_lastreset[] PROGMEM = "
Last reset reason
CPU0: {1}
CPU1: {2}
"; + const char HTTP_INFO_aphost[] PROGMEM = "
Access Point Hostname
{1}
"; + const char HTTP_INFO_psrsize[] PROGMEM = "
PSRAM Size
{1} bytes
"; + const char HTTP_INFO_temp[] PROGMEM = "
Temperature
{1} C° / {2} F°
Hall
{3}
"; +#else + const char HTTP_INFO_esphead[] PROGMEM = "

esp8266


"; + const char HTTP_INFO_fchipid[] PROGMEM = "
Flash Chip ID
{1}
"; + const char HTTP_INFO_corever[] PROGMEM = "
Core Version
{1}
"; + const char HTTP_INFO_bootver[] PROGMEM = "
Boot Version
{1}
"; + const char HTTP_INFO_lastreset[] PROGMEM = "
Last reset reason
{1}
"; + const char HTTP_INFO_flashsize[] PROGMEM = "
Real Flash Size
{1} bytes
"; +#endif + +const char HTTP_INFO_memsmeter[] PROGMEM = "
"; +const char HTTP_INFO_memsketch[] PROGMEM = "
Memory - Sketch Size
Used / Total bytes
{1} / {2}"; +const char HTTP_INFO_freeheap[] PROGMEM = "
Memory - Free Heap
{1} bytes available
"; +const char HTTP_INFO_wifihead[] PROGMEM = "

WiFi


"; +const char HTTP_INFO_uptime[] PROGMEM = "
Uptime
{1} Mins {2} Secs
"; +const char HTTP_INFO_chipid[] PROGMEM = "
Chip ID
{1}
"; +const char HTTP_INFO_idesize[] PROGMEM = "
Flash Size
{1} bytes
"; +const char HTTP_INFO_sdkver[] PROGMEM = "
SDK Version
{1}
"; +const char HTTP_INFO_cpufreq[] PROGMEM = "
CPU Frequency
{1}MHz
"; +const char HTTP_INFO_apip[] PROGMEM = "
Access Point IP
{1}
"; +const char HTTP_INFO_apmac[] PROGMEM = "
Access Point MAC
{1}
"; +const char HTTP_INFO_apssid[] PROGMEM = "
Access Point SSID
{1}
"; +const char HTTP_INFO_apbssid[] PROGMEM = "
BSSID
{1}
"; +const char HTTP_INFO_stassid[] PROGMEM = "
Station SSID
{1}
"; +const char HTTP_INFO_staip[] PROGMEM = "
Station IP
{1}
"; +const char HTTP_INFO_stagw[] PROGMEM = "
Station Gateway
{1}
"; +const char HTTP_INFO_stasub[] PROGMEM = "
Station Subnet
{1}
"; +const char HTTP_INFO_dnss[] PROGMEM = "
DNS Server
{1}
"; +const char HTTP_INFO_host[] PROGMEM = "
Hostname
{1}
"; +const char HTTP_INFO_stamac[] PROGMEM = "
Station MAC
{1}
"; +const char HTTP_INFO_conx[] PROGMEM = "
Connected
{1}
"; +const char HTTP_INFO_autoconx[] PROGMEM = "
Autoconnect
{1}
"; + +const char HTTP_INFO_aboutver[] PROGMEM = "
WiFiManager
{1}
"; +const char HTTP_INFO_aboutarduino[] PROGMEM = "
Arduino
{1}
"; +const char HTTP_INFO_aboutsdk[] PROGMEM = "
ESP-SDK/IDF
{1}
"; +const char HTTP_INFO_aboutdate[] PROGMEM = "
Build Date
{1}
"; + +const char S_brand[] PROGMEM = "WiFiManager"; +const char S_debugPrefix[] PROGMEM = "*wm:"; +const char S_y[] PROGMEM = "Yes"; +const char S_n[] PROGMEM = "No"; +const char S_enable[] PROGMEM = "Enabled"; +const char S_disable[] PROGMEM = "Disabled"; +const char S_GET[] PROGMEM = "GET"; +const char S_POST[] PROGMEM = "POST"; +const char S_NA[] PROGMEM = "Unknown"; +const char S_passph[] PROGMEM = "********"; +const char S_titlewifisaved[] PROGMEM = "Credentials Saved"; +const char S_titlewifisettings[] PROGMEM = "Settings Saved"; +const char S_titlewifi[] PROGMEM = "Config ESP"; +const char S_titleinfo[] PROGMEM = "Info"; +const char S_titleparam[] PROGMEM = "Setup"; +const char S_titleparamsaved[] PROGMEM = "Setup Saved"; +const char S_titleexit[] PROGMEM = "Exit"; +const char S_titlereset[] PROGMEM = "Reset"; +const char S_titleerase[] PROGMEM = "Erase"; +const char S_titleclose[] PROGMEM = "Close"; +const char S_options[] PROGMEM = "options"; +const char S_nonetworks[] PROGMEM = "No networks found. Refresh to scan again."; +const char S_staticip[] PROGMEM = "Static IP"; +const char S_staticgw[] PROGMEM = "Static Gateway"; +const char S_staticdns[] PROGMEM = "Static DNS"; +const char S_subnet[] PROGMEM = "Subnet"; +const char S_exiting[] PROGMEM = "Exiting"; +const char S_resetting[] PROGMEM = "Module will reset in a few seconds."; +const char S_closing[] PROGMEM = "You can close the page, portal will continue to run"; +const char S_error[] PROGMEM = "An Error Occured"; +const char S_notfound[] PROGMEM = "File Not Found\n\n"; +const char S_uri[] PROGMEM = "URI: "; +const char S_method[] PROGMEM = "\nMethod: "; +const char S_args[] PROGMEM = "\nArguments: "; +const char S_parampre[] PROGMEM = "param_"; + +// debug strings +const char D_HR[] PROGMEM = "--------------------"; + + +// softap ssid default prefix +#ifdef ESP8266 + const char S_ssidpre[] PROGMEM = "ESP"; +#elif defined(ESP32) + const char S_ssidpre[] PROGMEM = "ESP32"; +#else + const char S_ssidpre[] PROGMEM = "WM"; +#endif + +// END WIFI_MANAGER_OVERRIDE_STRINGS +#endif + +#endif