diff --git a/WiFiManager.cpp b/WiFiManager.cpp index c36f46d8..cc83e19b 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -136,9 +136,7 @@ bool WiFiManager::addParameter(WiFiManagerParameter *p) { if(p->getID()){ for (size_t i = 0; i < strlen(p->getID()); i++){ if(!(isAlphaNumeric(p->getID()[i])) && !(p->getID()[i]=='_')){ - #ifdef WM_DEBUG_LEVEL DEBUG_WM(WM_DEBUG_ERROR,F("[ERROR] parameter IDs can only contain alpha numeric chars")); - #endif return false; } } @@ -146,31 +144,23 @@ bool WiFiManager::addParameter(WiFiManagerParameter *p) { // init params if never malloc if(_params == NULL){ - #ifdef WM_DEBUG_LEVEL DEBUG_WM(WM_DEBUG_DEV,F("allocating params bytes:"),_max_params * sizeof(WiFiManagerParameter*)); - #endif _params = (WiFiManagerParameter**)malloc(_max_params * sizeof(WiFiManagerParameter*)); } // resize the params array by increment of WIFI_MANAGER_MAX_PARAMS if(_paramsCount == _max_params){ _max_params += WIFI_MANAGER_MAX_PARAMS; - #ifdef WM_DEBUG_LEVEL 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 // DEBUG_WM(WIFI_MANAGER_MAX_PARAMS); // DEBUG_WM(_paramsCount); // DEBUG_WM(_max_params); - #endif if (new_params != NULL) { _params = new_params; } else { - #ifdef WM_DEBUG_LEVEL DEBUG_WM(WM_DEBUG_ERROR,F("[ERROR] failed to realloc params, size not increased!")); - #endif return false; } } @@ -178,9 +168,7 @@ bool WiFiManager::addParameter(WiFiManagerParameter *p) { _params[_paramsCount] = p; _paramsCount++; - #ifdef WM_DEBUG_LEVEL DEBUG_WM(WM_DEBUG_VERBOSE,F("Added Parameter:"),p->getID()); - #endif return true; } @@ -227,9 +215,7 @@ WiFiManager::~WiFiManager() { // parameters // @todo below belongs to wifimanagerparameter if (_params != NULL){ - #ifdef WM_DEBUG_LEVEL DEBUG_WM(WM_DEBUG_DEV,F("freeing allocated params!")); - #endif free(_params); _params = NULL; } @@ -240,9 +226,7 @@ WiFiManager::~WiFiManager() { WiFi.removeEvent(wm_event_id); #endif - #ifdef WM_DEBUG_LEVEL DEBUG_WM(WM_DEBUG_DEV,F("unloading")); - #endif } void WiFiManager::_begin(){ @@ -276,9 +260,7 @@ boolean WiFiManager::autoConnect() { * @return {[type]} [description] */ boolean WiFiManager::autoConnect(char const *apName, char const *apPassword) { - #ifdef WM_DEBUG_LEVEL DEBUG_WM(F("AutoConnect")); - #endif // bool wifiIsSaved = getWiFiIsSaved(); bool wifiIsSaved = true; // workaround until I can check esp32 wifiisinit and has nvs @@ -308,9 +290,7 @@ boolean WiFiManager::autoConnect(char const *apName, char const *apPassword) { // attempt to connect using saved settings, on fail fallback to AP config portal if(!WiFi.enableSTA(true)){ // handle failure mode Brownout detector etc. - #ifdef WM_DEBUG_LEVEL DEBUG_WM(WM_DEBUG_ERROR,F("[FATAL] Unable to enable wifi!")); - #endif return false; } @@ -339,9 +319,7 @@ boolean WiFiManager::autoConnect(char const *apName, char const *apPassword) { bool connected = false; if (WiFi.status() == WL_CONNECTED){ connected = true; - #ifdef WM_DEBUG_LEVEL DEBUG_WM(F("AutoConnect: ESP Already Connected")); - #endif setSTAConfig(); // @todo not sure if this is safe, causes dup setSTAConfig in connectwifi, // and we have no idea WHAT we are connected to @@ -349,37 +327,27 @@ boolean WiFiManager::autoConnect(char const *apName, char const *apPassword) { if(connected || connectWifi(_defaultssid, _defaultpass) == WL_CONNECTED){ //connected - #ifdef WM_DEBUG_LEVEL DEBUG_WM(F("AutoConnect: SUCCESS")); 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"); _lastconxresult = WL_CONNECTED; if(_hostname != ""){ - #ifdef WM_DEBUG_LEVEL DEBUG_WM(WM_DEBUG_DEV,F("hostname: STA: "),getWiFiHostname()); - #endif } return true; // connected success } - #ifdef WM_DEBUG_LEVEL DEBUG_WM(F("AutoConnect: FAILED for "),(String)((millis()-_startconn)) + " ms"); - #endif } else { - #ifdef WM_DEBUG_LEVEL DEBUG_WM(F("No Credentials are Saved, skipping connect")); - #endif } // possibly skip the config portal if (!_enableConfigPortal) { - #ifdef WM_DEBUG_LEVEL DEBUG_WM(WM_DEBUG_VERBOSE,F("enableConfigPortal: FALSE, skipping ")); - #endif return false; // not connected and not cp } @@ -391,27 +359,19 @@ boolean WiFiManager::autoConnect(char const *apName, char const *apPassword) { bool WiFiManager::setupHostname(bool restart){ if(_hostname == "") { - #ifdef WM_DEBUG_LEVEL DEBUG_WM(WM_DEBUG_DEV,F("No Hostname to set")); - #endif return false; } else { - #ifdef WM_DEBUG_LEVEL DEBUG_WM(WM_DEBUG_VERBOSE,F("Setting Hostnames: "),_hostname); - #endif } bool res = true; #ifdef ESP8266 - #ifdef WM_DEBUG_LEVEL 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(WM_DEBUG_VERBOSE,F("Setting MDNS hostname, tcp 80")); - #endif if(MDNS.begin(_hostname.c_str())){ MDNS.addService("http", "tcp", 80); } @@ -421,9 +381,7 @@ bool WiFiManager::setupHostname(bool restart){ // @note, this may have changed at some point, now it wont work, I have to set it before. // same for S2, must set it before mode(STA) now - #ifdef WM_DEBUG_LEVEL DEBUG_WM(WM_DEBUG_VERBOSE,F("Setting WiFi hostname")); - #endif res = WiFi.setHostname(_hostname.c_str()); // esp_err_t err; @@ -435,9 +393,7 @@ bool WiFiManager::setupHostname(bool restart){ // } // #ifdef ESP32MDNS_H #ifdef WM_MDNS - #ifdef WM_DEBUG_LEVEL DEBUG_WM(WM_DEBUG_VERBOSE,F("Setting MDNS hostname, tcp 80")); - #endif if(MDNS.begin(_hostname.c_str())){ MDNS.addService("http", "tcp", 80); } @@ -449,9 +405,7 @@ bool WiFiManager::setupHostname(bool restart){ #endif if(restart && (WiFi.status() == WL_CONNECTED)){ - #ifdef WM_DEBUG_LEVEL DEBUG_WM(WM_DEBUG_VERBOSE,F("reconnecting to set new hostname")); - #endif // WiFi.reconnect(); // This does not reset dhcp WiFi_Disconnect(); delay(200); // do not remove, need a delay for disconnect to change status() @@ -463,16 +417,12 @@ bool WiFiManager::setupHostname(bool restart){ // CONFIG PORTAL bool WiFiManager::startAP(){ bool ret = true; - #ifdef WM_DEBUG_LEVEL DEBUG_WM(F("StartAP with SSID: "),_apName); - #endif #ifdef ESP8266 // @bug workaround for bug #4372 https://github.com/esp8266/Arduino/issues/4372 if(!WiFi.enableAP(true)) { - #ifdef WM_DEBUG_LEVEL DEBUG_WM(WM_DEBUG_ERROR,F("[ERROR] enableAP failed!")); - #endif return false; } delay(500); // workaround delay @@ -480,13 +430,9 @@ bool WiFiManager::startAP(){ // setup optional soft AP static ip config if (_ap_static_ip) { - #ifdef WM_DEBUG_LEVEL DEBUG_WM(F("Custom AP IP/GW/Subnet:")); - #endif if(!WiFi.softAPConfig(_ap_static_ip, _ap_static_gw, _ap_static_sn)){ - #ifdef WM_DEBUG_LEVEL DEBUG_WM(WM_DEBUG_ERROR,F("[ERROR] softAPConfig failed!")); - #endif } } @@ -498,9 +444,7 @@ bool WiFiManager::startAP(){ else channel = _apChannel; if(channel>0){ - #ifdef WM_DEBUG_LEVEL DEBUG_WM(WM_DEBUG_VERBOSE,F("Starting AP on channel:"),channel); - #endif } // start soft AP with password or anonymous @@ -513,9 +457,7 @@ bool WiFiManager::startAP(){ ret = WiFi.softAP(_apName.c_str(), _apPassword.c_str(),1,_apHidden);//password option } } else { - #ifdef WM_DEBUG_LEVEL DEBUG_WM(WM_DEBUG_VERBOSE,F("AP has anonymous access!")); - #endif if(channel>0){ ret = WiFi.softAP(_apName.c_str(),"",channel,_apHidden); } @@ -568,9 +510,7 @@ void WiFiManager::startWebPortal() { */ void WiFiManager::stopWebPortal() { if(!configPortalActive && !webPortalActive) return; - #ifdef WM_DEBUG_LEVEL DEBUG_WM(WM_DEBUG_VERBOSE,F("Stopping Web Portal")); - #endif webPortalActive = false; shutdownConfigPortal(); } @@ -584,9 +524,7 @@ boolean WiFiManager::configPortalHasTimeout(){ // debug num clients every 30s if(millis() - timer > logintvl){ timer = millis(); - #ifdef WM_DEBUG_LEVEL DEBUG_WM(WM_DEBUG_VERBOSE,F("NUM CLIENTS: "),(String)WiFi_softap_num_stations()); - #endif } _configPortalStart = millis(); // kludge, bump configportal start time to skew timeouts return false; @@ -597,18 +535,14 @@ boolean WiFiManager::configPortalHasTimeout(){ // handle timed out if(millis() > _configPortalStart + _configPortalTimeout){ - #ifdef WM_DEBUG_LEVEL DEBUG_WM(F("config portal has timed out")); - #endif return true; // timeout bail, else do debug logging } else if(_debug && _debugLevel > 0) { // log timeout time remaining every 30s if((millis() - timer) > logintvl){ timer = millis(); - #ifdef WM_DEBUG_LEVEL DEBUG_WM(WM_DEBUG_VERBOSE,F("Portal Timeout In"),(String)((_configPortalStart + _configPortalTimeout-millis())/1000) + (String)F(" seconds")); - #endif } } @@ -617,23 +551,17 @@ boolean WiFiManager::configPortalHasTimeout(){ void WiFiManager::setupHTTPServer(){ - #ifdef WM_DEBUG_LEVEL DEBUG_WM(F("Starting Web Portal")); - #endif if(_httpPort != 80) { - #ifdef WM_DEBUG_LEVEL DEBUG_WM(WM_DEBUG_VERBOSE,F("http server started with custom port: "),_httpPort); // @todo not showing ip - #endif } server.reset(new WM_WebServer(_httpPort)); // This is not the safest way to reset the webserver, it can cause crashes on callbacks initilized before this and since its a shared pointer... if ( _webservercallback != NULL) { - #ifdef WM_DEBUG_LEVEL DEBUG_WM(WM_DEBUG_VERBOSE,F("[CB] _webservercallback calling")); - #endif _webservercallback(); // @CALLBACK } // @todo add a new callback maybe, after webserver started, callback cannot override handlers, but can grab them first @@ -659,9 +587,7 @@ void WiFiManager::setupHTTPServer(){ server->on(WM_G(R_updatedone), HTTP_POST, std::bind(&WiFiManager::handleUpdateDone, this), std::bind(&WiFiManager::handleUpdating, this)); server->begin(); // Web server start - #ifdef WM_DEBUG_LEVEL DEBUG_WM(WM_DEBUG_VERBOSE,F("HTTP server started")); - #endif } void WiFiManager::setupDNSD(){ @@ -669,10 +595,8 @@ void WiFiManager::setupDNSD(){ /* Setup the DNS server redirecting all the domains to the apIP */ dnsServer->setErrorReplyCode(DNSReplyCode::NoError); - #ifdef WM_DEBUG_LEVEL // DEBUG_WM("dns server started port: ",DNS_PORT); 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,9 +622,7 @@ boolean WiFiManager::startConfigPortal(char const *apName, char const *apPasswo _begin(); if(configPortalActive){ - #ifdef WM_DEBUG_LEVEL DEBUG_WM(WM_DEBUG_VERBOSE,F("Starting Config Portal FAILED, is already running")); - #endif return false; } @@ -708,9 +630,7 @@ boolean WiFiManager::startConfigPortal(char const *apName, char const *apPasswo _apName = apName; // @todo check valid apname ? _apPassword = apPassword; - #ifdef WM_DEBUG_LEVEL DEBUG_WM(WM_DEBUG_VERBOSE,F("Starting Config Portal")); - #endif if(_apName == "") _apName = getDefaultAPName(); @@ -724,9 +644,7 @@ boolean WiFiManager::startConfigPortal(char const *apName, char const *apPasswo #endif WiFi_Disconnect(); WiFi_enableSTA(false); - #ifdef WM_DEBUG_LEVEL DEBUG_WM(WM_DEBUG_VERBOSE,F("Disabling STA")); - #endif } else { // WiFi_enableSTA(true); @@ -740,29 +658,21 @@ boolean WiFiManager::startConfigPortal(char const *apName, char const *apPasswo _configPortalStart = millis(); // start access point - #ifdef WM_DEBUG_LEVEL DEBUG_WM(WM_DEBUG_VERBOSE,F("Enabling AP")); - #endif startAP(); WiFiSetCountry(); // do AP callback if set if ( _apcallback != NULL) { - #ifdef WM_DEBUG_LEVEL DEBUG_WM(WM_DEBUG_VERBOSE,F("[CB] _apcallback calling")); - #endif _apcallback(this); } // init configportal - #ifdef WM_DEBUG_LEVEL DEBUG_WM(WM_DEBUG_DEV,F("setupConfigPortal")); - #endif setupConfigPortal(); - #ifdef WM_DEBUG_LEVEL DEBUG_WM(WM_DEBUG_DEV,F("setupDNSD")); - #endif setupDNSD(); @@ -785,15 +695,11 @@ boolean WiFiManager::startConfigPortal(char const *apName, char const *apPasswo // if timed out or abort, break if(configPortalHasTimeout() || abort){ - #ifdef WM_DEBUG_LEVEL 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(WM_DEBUG_VERBOSE,F("[CB] config portal timeout callback")); - #endif _configportaltimeoutcallback(); // @CALLBACK } break; @@ -815,9 +721,7 @@ boolean WiFiManager::startConfigPortal(char const *apName, char const *apPasswo yield(); // watchdog } - #ifdef WM_DEBUG_LEVEL DEBUG_WM(WM_DEBUG_NOTIFY,F("config portal exiting")); - #endif return result; } @@ -835,15 +739,11 @@ boolean WiFiManager::process(){ if(webPortalActive || (configPortalActive && !_configPortalIsBlocking)){ // if timed out or abort, break if(_allowExit && (configPortalHasTimeout() || abort)){ - #ifdef WM_DEBUG_LEVEL DEBUG_WM(WM_DEBUG_DEV,F("process loop abort")); - #endif webPortalActive = false; shutdownConfigPortal(); if (_configportaltimeoutcallback != NULL) { - #ifdef WM_DEBUG_LEVEL DEBUG_WM(WM_DEBUG_VERBOSE,F("[CB] config portal timeout callback")); - #endif _configportaltimeoutcallback(); // @CALLBACK } return false; @@ -874,16 +774,12 @@ uint8_t WiFiManager::processConfigPortal(){ // Waiting for save... if(connect) { connect = false; - #ifdef WM_DEBUG_LEVEL 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(WM_DEBUG_VERBOSE,F("No ssid, skipping wifi save")); - #endif } else{ // attempt sta connection to submitted _ssid, _pass @@ -900,18 +796,14 @@ uint8_t WiFiManager::processConfigPortal(){ #endif if ( _savewificallback != NULL) { - #ifdef WM_DEBUG_LEVEL DEBUG_WM(WM_DEBUG_VERBOSE,F("[CB] _savewificallback calling")); - #endif _savewificallback(); // @CALLBACK } if(!_connectonsave) return WL_IDLE_STATUS; if(_disableConfigPortal) shutdownConfigPortal(); return WL_CONNECTED; // CONNECT SUCCESS } - #ifdef WM_DEBUG_LEVEL DEBUG_WM(WM_DEBUG_ERROR,F("[ERROR] Connect to new AP Failed")); - #endif } if (_shouldBreakAfterConfig) { @@ -920,9 +812,7 @@ uint8_t WiFiManager::processConfigPortal(){ // @todo this is more of an exiting callback than a save, clarify when this should actually occur // confirm or verify data was saved to make this more accurate callback if ( _savewificallback != NULL) { - #ifdef WM_DEBUG_LEVEL DEBUG_WM(WM_DEBUG_VERBOSE,F("[CB] WiFi/Param save callback")); - #endif _savewificallback(); // @CALLBACK } if(_disableConfigPortal) shutdownConfigPortal(); @@ -935,14 +825,10 @@ uint8_t WiFiManager::processConfigPortal(){ // if connect fails, turn sta off to stabilize AP WiFi_Disconnect(); WiFi_enableSTA(false); - #ifdef WM_DEBUG_LEVEL DEBUG_WM(WM_DEBUG_VERBOSE,F("Processing - Disabling STA")); - #endif } else{ - #ifdef WM_DEBUG_LEVEL DEBUG_WM(WM_DEBUG_VERBOSE,F("Portal is non blocking - remaining open")); - #endif } } @@ -955,9 +841,7 @@ uint8_t WiFiManager::processConfigPortal(){ * @return bool success (softapdisconnect) */ bool WiFiManager::shutdownConfigPortal(){ - #ifdef WM_DEBUG_LEVEL DEBUG_WM(WM_DEBUG_VERBOSE,F("shutdownConfigPortal")); - #endif if(webPortalActive) return false; @@ -998,14 +882,10 @@ bool WiFiManager::shutdownConfigPortal(){ 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(WM_DEBUG_VERBOSE,F("WiFi Reconnect, was idle")); - #endif } - #ifdef WM_DEBUG_LEVEL 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(WM_DEBUG_VERBOSE,F("configportal closed")); _end(); @@ -1016,9 +896,7 @@ bool WiFiManager::shutdownConfigPortal(){ // one for connecting to flash , one for new client // clean up, flow is convoluted, and causes bugs uint8_t WiFiManager::connectWifi(String ssid, String pass, bool connect) { - #ifdef WM_DEBUG_LEVEL DEBUG_WM(WM_DEBUG_VERBOSE,F("Connecting as wifi client...")); - #endif uint8_t retry = 1; uint8_t connRes = (uint8_t)WL_NO_SSID_AVAIL; @@ -1037,9 +915,7 @@ uint8_t WiFiManager::connectWifi(String ssid, String pass, bool connect) { while(retry <= _connectRetries && (connRes!=WL_CONNECTED)){ if(_connectRetries > 1){ if(_aggresiveReconn) delay(1000); // add idle time before recon - #ifdef WM_DEBUG_LEVEL DEBUG_WM(F("Connect Wifi, ATTEMPT #"),(String)retry+" of "+(String)_connectRetries); - #endif } // if ssid argument provided connect to that // NOTE: this also catches preload() _defaultssid @todo rework @@ -1063,15 +939,11 @@ uint8_t WiFiManager::connectWifi(String ssid, String pass, bool connect) { connRes = waitForConnectResult(); } else { - #ifdef WM_DEBUG_LEVEL DEBUG_WM(F("No wifi saved, skipping")); - #endif } } - #ifdef WM_DEBUG_LEVEL DEBUG_WM(WM_DEBUG_VERBOSE,F("Connection result:"),getWLStatusString(connRes)); - #endif retry++; } @@ -1103,11 +975,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(WM_DEBUG_DEV,F("CONNECTED: "),WiFi.status() == WL_CONNECTED ? "Y" : "NO"); DEBUG_WM(F("Connecting to NEW AP:"),ssid); 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); ret = WiFi.begin(ssid.c_str(), pass.c_str(), 0, NULL, connect); @@ -1126,10 +996,8 @@ bool WiFiManager::wifiConnectNew(String ssid, String pass,bool connect){ bool WiFiManager::wifiConnectDefault(){ bool ret = false; - #ifdef WM_DEBUG_LEVEL DEBUG_WM(F("Connecting to SAVED AP:"),WiFi_SSID(true)); DEBUG_WM(WM_DEBUG_DEV,F("Using Password:"),WiFi_psk(true)); - #endif ret = WiFi_enableSTA(true,storeSTAmode); delay(500); // THIS DELAY ? @@ -1155,24 +1023,16 @@ 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(WM_DEBUG_VERBOSE,F("Custom static IP/GW/Subnet/DNS")); - #endif if(_sta_static_dns) { - #ifdef WM_DEBUG_LEVEL 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(WM_DEBUG_VERBOSE,F("Custom STA IP/GW/Subnet")); - #endif ret = WiFi.config(_sta_static_ip, _sta_static_gw, _sta_static_sn); } @@ -1182,9 +1042,7 @@ bool WiFiManager::setSTAConfig(){ #endif } else { - #ifdef WM_DEBUG_LEVEL DEBUG_WM(WM_DEBUG_VERBOSE,F("setSTAConfig static ip not set, skipping")); - #endif } return ret; } @@ -1202,9 +1060,7 @@ void WiFiManager::updateConxResult(uint8_t status){ #elif defined(ESP32) // if(_lastconxresult == WL_CONNECT_FAILED){ if(_lastconxresult == WL_CONNECT_FAILED || _lastconxresult == WL_DISCONNECTED){ - #ifdef WM_DEBUG_LEVEL DEBUG_WM(WM_DEBUG_DEV,F("lastconxresulttmp:"),getWLStatusString(_lastconxresulttmp)); - #endif if(_lastconxresulttmp != WL_IDLE_STATUS){ _lastconxresult = _lastconxresulttmp; // _lastconxresulttmp = WL_IDLE_STATUS; @@ -1229,16 +1085,12 @@ uint8_t WiFiManager::waitForConnectResult() { */ uint8_t WiFiManager::waitForConnectResult(uint32_t timeout) { if (timeout == 0){ - #ifdef WM_DEBUG_LEVEL DEBUG_WM(F("connectTimeout not set, ESP waitForConnectResult...")); - #endif return WiFi.waitForConnectResult(); } unsigned long timeoutmillis = millis() + timeout; - #ifdef WM_DEBUG_LEVEL DEBUG_WM(WM_DEBUG_VERBOSE,timeout,F("ms timeout, waiting for connect...")); - #endif uint8_t status = WiFi.status(); while(millis() < timeoutmillis) { @@ -1247,9 +1099,7 @@ uint8_t WiFiManager::waitForConnectResult(uint32_t timeout) { if (status == WL_CONNECTED || status == WL_CONNECT_FAILED) { return status; } - #ifdef WM_DEBUG_LEVEL DEBUG_WM (WM_DEBUG_VERBOSE,F(".")); - #endif delay(100); } return status; @@ -1258,17 +1108,13 @@ uint8_t WiFiManager::waitForConnectResult(uint32_t timeout) { // WPS enabled? https://github.com/esp8266/Arduino/pull/4889 #ifdef NO_EXTRA_4K_HEAP void WiFiManager::startWPS() { - #ifdef WM_DEBUG_LEVEL DEBUG_WM(F("START WPS")); - #endif #ifdef ESP8266 WiFi.beginWPSConfig(); #else // @todo #endif - #ifdef WM_DEBUG_LEVEL DEBUG_WM(F("END WPS")); - #endif } #endif @@ -1327,9 +1173,7 @@ void WiFiManager::handleRequest() { * HTTPD CALLBACK root or redirect to captive portal */ void WiFiManager::handleRoot() { - #ifdef WM_DEBUG_LEVEL DEBUG_WM(WM_DEBUG_VERBOSE,F("<- HTTP Root")); - #endif if (captivePortal()) return; // If captive portal redirect instead of displaying the page handleRequest(); String page = getHTTPHead(_title); // @token options @todo replace options with title @@ -1353,15 +1197,11 @@ void WiFiManager::handleRoot() { * HTTPD CALLBACK Wifi config page handler */ void WiFiManager::handleWifi(boolean scan) { - #ifdef WM_DEBUG_LEVEL 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(WM_DEBUG_DEV,"refresh flag:",server->hasArg(F("refresh"))); - #endif WiFi_scanNetworks(server->hasArg(F("refresh")),false); //wifiscan, force if arg refresh page += getScanItemOut(); } @@ -1400,18 +1240,14 @@ void WiFiManager::handleWifi(boolean scan) { HTTPSend(page); - #ifdef WM_DEBUG_LEVEL DEBUG_WM(WM_DEBUG_DEV,F("Sent config page")); - #endif } /** * HTTPD CALLBACK Wifi param page handler */ void WiFiManager::handleParam(){ - #ifdef WM_DEBUG_LEVEL DEBUG_WM(WM_DEBUG_VERBOSE,F("<- HTTP Param")); - #endif handleRequest(); String page = getHTTPHead(FPSTR(S_titleparam)); // @token titlewifi @@ -1429,9 +1265,7 @@ void WiFiManager::handleParam(){ HTTPSend(page); - #ifdef WM_DEBUG_LEVEL DEBUG_WM(WM_DEBUG_DEV,F("Sent param page")); - #endif } @@ -1459,10 +1293,8 @@ String WiFiManager::getMenuOut(){ void WiFiManager::WiFi_scanComplete(int networksFound){ _lastscan = millis(); _numNetworks = networksFound; - #ifdef WM_DEBUG_LEVEL 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 } bool WiFiManager::WiFi_scanNetworks(){ @@ -1476,11 +1308,9 @@ bool WiFiManager::WiFi_scanNetworks(unsigned int cachetime){ return WiFi_scanNetworks(millis()-_lastscan > cachetime,false); } bool WiFiManager::WiFi_scanNetworks(bool force,bool async){ - #ifdef WM_DEBUG_LEVEL // 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? @@ -1500,9 +1330,7 @@ bool WiFiManager::WiFi_scanNetworks(bool force,bool async){ if(async && _asyncScan){ #ifdef ESP8266 #ifndef WM_NOASYNC // no async available < 2.4.0 - #ifdef WM_DEBUG_LEVEL 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 @@ -1510,9 +1338,7 @@ bool WiFiManager::WiFi_scanNetworks(bool force,bool async){ res = WiFi.scanNetworks(); #endif #else - #ifdef WM_DEBUG_LEVEL DEBUG_WM(WM_DEBUG_VERBOSE,F("WiFi Scan ASYNC started")); - #endif res = WiFi.scanNetworks(true); #endif return false; @@ -1522,33 +1348,23 @@ bool WiFiManager::WiFi_scanNetworks(bool force,bool async){ res = WiFi.scanNetworks(); } if(res == WIFI_SCAN_FAILED){ - #ifdef WM_DEBUG_LEVEL DEBUG_WM(WM_DEBUG_ERROR,F("[ERROR] scan failed")); - #endif } else if(res == WIFI_SCAN_RUNNING){ - #ifdef WM_DEBUG_LEVEL DEBUG_WM(WM_DEBUG_ERROR,F("[ERROR] scan waiting")); - #endif while(WiFi.scanComplete() == WIFI_SCAN_RUNNING){ - #ifdef WM_DEBUG_LEVEL DEBUG_WM(WM_DEBUG_ERROR,"."); - #endif delay(100); } _numNetworks = WiFi.scanComplete(); } else if(res >=0 ) _numNetworks = res; _lastscan = millis(); - #ifdef WM_DEBUG_LEVEL DEBUG_WM(WM_DEBUG_VERBOSE,F("WiFi Scan completed"), "in "+(String)(_lastscan - _startscan)+" ms"); - #endif return true; } else { - #ifdef WM_DEBUG_LEVEL DEBUG_WM(WM_DEBUG_VERBOSE,F("Scan is cached"),(String)(millis()-_lastscan )+" ms ago"); - #endif } return false; } @@ -1560,16 +1376,12 @@ String WiFiManager::WiFiManager::getScanItemOut(){ int n = _numNetworks; if (n == 0) { - #ifdef WM_DEBUG_LEVEL DEBUG_WM(F("No networks found")); - #endif page += FPSTR(S_nonetworks); // @token nonetworks page += F("

"); } else { - #ifdef WM_DEBUG_LEVEL DEBUG_WM(n,F("networks found")); - #endif //sort networks int indices[n]; for (int i = 0; i < n; i++) { @@ -1600,9 +1412,7 @@ String WiFiManager::WiFiManager::getScanItemOut(){ cssid = WiFi.SSID(indices[i]); for (int j = i + 1; j < n; j++) { if (cssid == WiFi.SSID(indices[j])) { - #ifdef WM_DEBUG_LEVEL DEBUG_WM(WM_DEBUG_VERBOSE,F("DUP AP:"),WiFi.SSID(indices[j])); - #endif indices[j] = -1; // set dup aps to index -1 } } @@ -1629,9 +1439,7 @@ String WiFiManager::WiFiManager::getScanItemOut(){ for (int i = 0; i < n; i++) { if (indices[i] == -1) continue; // skip dups - #ifdef WM_DEBUG_LEVEL 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])); uint8_t enc_type = WiFi.encryptionType(indices[i]); @@ -1655,15 +1463,11 @@ String WiFiManager::WiFiManager::getScanItemOut(){ item.replace(FPSTR(T_i), ""); } } - #ifdef WM_DEBUG_LEVEL DEBUG_WM(WM_DEBUG_DEV,item); - #endif page += item; delay(0); } else { - #ifdef WM_DEBUG_LEVEL DEBUG_WM(WM_DEBUG_VERBOSE,F("Skipping , does not meet _minimumQuality")); - #endif } } @@ -1690,9 +1494,7 @@ String WiFiManager::getIpForm(String id, String title, String value){ String WiFiManager::getStaticOut(){ String page; if ((_staShowStaticFields || _sta_static_ip) && _staShowStaticFields>=0) { - #ifdef WM_DEBUG_LEVEL 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 page += getIpForm(FPSTR(S_ip),FPSTR(S_staticip),(_sta_static_ip ? _sta_static_ip.toString() : "")); // @token staticip @@ -1715,9 +1517,7 @@ String WiFiManager::getStaticOut(){ String WiFiManager::getParamOut(){ String page; - #ifdef WM_DEBUG_LEVEL DEBUG_WM(WM_DEBUG_DEV,F("getParamOut"),_paramsCount); - #endif if(_paramsCount > 0){ @@ -1738,9 +1538,7 @@ String WiFiManager::getParamOut(){ //Serial.println((String)_params[i]->_length); 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(WM_DEBUG_ERROR,F("[ERROR] WiFiManagerParameter is out of scope")); - #endif return ""; } } @@ -1789,9 +1587,7 @@ String WiFiManager::getParamOut(){ } void WiFiManager::handleWiFiStatus(){ - #ifdef WM_DEBUG_LEVEL DEBUG_WM(WM_DEBUG_VERBOSE,F("<- HTTP WiFi status ")); - #endif handleRequest(); String page; // String page = "{\"result\":true,\"count\":1}"; @@ -1805,10 +1601,8 @@ void WiFiManager::handleWiFiStatus(){ * HTTPD CALLBACK save form and redirect to WLAN config page again */ void WiFiManager::handleWifiSave() { - #ifdef WM_DEBUG_LEVEL 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(); //SAVE/connect here @@ -1817,9 +1611,7 @@ void WiFiManager::handleWifiSave() { 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 @@ -1843,30 +1635,22 @@ void WiFiManager::handleWifiSave() { //_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(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(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(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(WM_DEBUG_DEV,F("static DNS:"),dns); - #endif } if (_presavewificallback != NULL) { @@ -1892,21 +1676,15 @@ void WiFiManager::handleWifiSave() { server->sendHeader(FPSTR(HTTP_HEAD_CORS), FPSTR(HTTP_HEAD_CORS_ALLOW_ALL)); // @HTTPHEAD send cors HTTPSend(page); - #ifdef WM_DEBUG_LEVEL DEBUG_WM(WM_DEBUG_DEV,F("Sent wifi save page")); - #endif connect = true; //signal ready to connect/reset process in processConfigPortal } void WiFiManager::handleParamSave() { - #ifdef WM_DEBUG_LEVEL DEBUG_WM(WM_DEBUG_VERBOSE,F("<- HTTP Param save ")); - #endif - #ifdef WM_DEBUG_LEVEL DEBUG_WM(WM_DEBUG_DEV,F("Method:"),server->method() == HTTP_GET ? (String)FPSTR(S_GET) : (String)FPSTR(S_POST)); - #endif handleRequest(); doParamSave(); @@ -1918,9 +1696,7 @@ void WiFiManager::handleParamSave() { HTTPSend(page); - #ifdef WM_DEBUG_LEVEL DEBUG_WM(WM_DEBUG_DEV,F("Sent param save page")); - #endif } void WiFiManager::doParamSave(){ @@ -1931,16 +1707,12 @@ void WiFiManager::doParamSave(){ //parameters if(_paramsCount > 0){ - #ifdef WM_DEBUG_LEVEL 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 > 99999) { - #ifdef WM_DEBUG_LEVEL DEBUG_WM(WM_DEBUG_ERROR,F("[ERROR] WiFiManagerParameter is out of scope")); - #endif break; // @todo might not be needed anymore } //read parameter from server @@ -1954,13 +1726,9 @@ 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(WM_DEBUG_VERBOSE,(String)_params[i]->getID() + ":",value); - #endif } - #ifdef WM_DEBUG_LEVEL DEBUG_WM(WM_DEBUG_VERBOSE,FPSTR(D_HR)); - #endif } if ( _saveparamscallback != NULL) { @@ -1973,9 +1741,7 @@ void WiFiManager::doParamSave(){ * HTTPD CALLBACK info page */ void WiFiManager::handleInfo() { - #ifdef WM_DEBUG_LEVEL DEBUG_WM(WM_DEBUG_VERBOSE,F("<- HTTP Info")); - #endif handleRequest(); String page = getHTTPHead(FPSTR(S_titleinfo)); // @token titleinfo reportStatus(page); @@ -2075,9 +1841,7 @@ void WiFiManager::handleInfo() { HTTPSend(page); - #ifdef WM_DEBUG_LEVEL DEBUG_WM(WM_DEBUG_DEV,F("Sent info page")); - #endif } String WiFiManager::getInfoData(String id){ @@ -2318,9 +2082,7 @@ String WiFiManager::getInfoData(String id){ * HTTPD CALLBACK exit, closes configportal if blocking, if non blocking undefined */ void WiFiManager::handleExit() { - #ifdef WM_DEBUG_LEVEL DEBUG_WM(WM_DEBUG_VERBOSE,F("<- HTTP Exit")); - #endif handleRequest(); String page = getHTTPHead(FPSTR(S_titleexit)); // @token titleexit page += FPSTR(S_exiting); // @token exiting @@ -2335,9 +2097,7 @@ void WiFiManager::handleExit() { * HTTPD CALLBACK reset page */ void WiFiManager::handleReset() { - #ifdef WM_DEBUG_LEVEL DEBUG_WM(WM_DEBUG_VERBOSE,F("<- HTTP Reset")); - #endif handleRequest(); String page = getHTTPHead(FPSTR(S_titlereset)); //@token titlereset page += FPSTR(S_resetting); //@token resetting @@ -2345,9 +2105,7 @@ void WiFiManager::handleReset() { HTTPSend(page); - #ifdef WM_DEBUG_LEVEL DEBUG_WM(F("RESETTING ESP")); - #endif delay(1000); reboot(); } @@ -2360,9 +2118,7 @@ void WiFiManager::handleReset() { // handleErase(false); // } void WiFiManager::handleErase(boolean opt) { - #ifdef WM_DEBUG_LEVEL DEBUG_WM(WM_DEBUG_NOTIFY,F("<- HTTP Erase")); - #endif handleRequest(); String page = getHTTPHead(FPSTR(S_titleerase)); // @token titleerase @@ -2371,9 +2127,7 @@ void WiFiManager::handleErase(boolean opt) { if(ret) page += FPSTR(S_resetting); // @token resetting else { page += FPSTR(S_error); // @token erroroccur - #ifdef WM_DEBUG_LEVEL DEBUG_WM(WM_DEBUG_ERROR,F("[ERROR] WiFi EraseConfig failed")); - #endif } page += FPSTR(HTTP_END); @@ -2381,9 +2135,7 @@ void WiFiManager::handleErase(boolean opt) { if(ret){ delay(2000); - #ifdef WM_DEBUG_LEVEL DEBUG_WM(F("RESETTING ESP")); - #endif reboot(); } } @@ -2427,10 +2179,8 @@ boolean WiFiManager::captivePortal() { 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"){ @@ -2444,10 +2194,8 @@ boolean WiFiManager::captivePortal() { bool doredirect = serverLoc != server->hostHeader(); // redirect if hostheader not server ip, prevent redirect loops if (doredirect) { - #ifdef WM_DEBUG_LEVEL 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. server->client().stop(); // Stop is needed because we sent no content length @@ -2465,9 +2213,7 @@ void WiFiManager::stopCaptivePortal(){ void WiFiManager::handleClose(){ DEBUG_WM(WM_DEBUG_VERBOSE,F("Disabling Captive Portal")); stopCaptivePortal(); - #ifdef WM_DEBUG_LEVEL DEBUG_WM(WM_DEBUG_VERBOSE,F("<- HTTP close")); - #endif handleRequest(); String page = getHTTPHead(FPSTR(S_titleclose)); // @token titleclose page += FPSTR(S_closing); // @token closing @@ -2548,14 +2294,10 @@ bool WiFiManager::stopConfigPortal(){ */ bool WiFiManager::disconnect(){ if(WiFi.status() != WL_CONNECTED){ - #ifdef WM_DEBUG_LEVEL DEBUG_WM(WM_DEBUG_VERBOSE,F("Disconnecting: Not connected")); - #endif return false; } - #ifdef WM_DEBUG_LEVEL DEBUG_WM(F("Disconnecting")); - #endif return WiFi_Disconnect(); } @@ -2564,9 +2306,7 @@ bool WiFiManager::disconnect(){ * @access public */ void WiFiManager::reboot(){ - #ifdef WM_DEBUG_LEVEL DEBUG_WM(F("Restarting")); - #endif ESP.restart(); } @@ -2579,42 +2319,28 @@ bool WiFiManager::erase(){ } bool WiFiManager::erase(bool opt){ - #ifdef WM_DEBUG_LEVEL DEBUG_WM("Erasing"); - #endif #if defined(ESP32) && ((defined(WM_ERASE_NVS) || defined(nvs_flash_h))) // if opt true, do nvs erase if(opt){ - #ifdef WM_DEBUG_LEVEL DEBUG_WM(F("Erasing NVS")); - #endif esp_err_t err; err = nvs_flash_init(); - #ifdef WM_DEBUG_LEVEL 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(WM_DEBUG_VERBOSE,F("nvs_flash_erase: "), err!=ESP_OK ? (String)err : "Success"); - #endif return err == ESP_OK; } #elif defined(ESP8266) && defined(spiffs_api_h) if(opt){ bool ret = false; if(SPIFFS.begin()){ - #ifdef WM_DEBUG_LEVEL DEBUG_WM(F("Erasing SPIFFS")); - #endif bool ret = SPIFFS.format(); - #ifdef WM_DEBUG_LEVEL DEBUG_WM(WM_DEBUG_VERBOSE,F("spiffs erase: "),ret ? "Success" : "ERROR"); - #endif } else{ - #ifdef WM_DEBUG_LEVEL DEBUG_WM(F("[ERROR] Could not start SPIFFS")); - #endif } return ret; } @@ -2622,9 +2348,7 @@ bool WiFiManager::erase(bool opt){ (void)opt; #endif - #ifdef WM_DEBUG_LEVEL DEBUG_WM(F("Erasing WiFi Config")); - #endif return WiFi_eraseConfig(); } @@ -2634,9 +2358,7 @@ bool WiFiManager::erase(bool opt){ * @access public */ void WiFiManager::resetSettings() { -#ifdef WM_DEBUG_LEVEL DEBUG_WM(F("resetSettings")); - #endif WiFi_enableSTA(true,true); // must be sta to disconnect erase delay(500); // ensure sta is enabled if (_resetcallback != NULL){ @@ -2650,9 +2372,7 @@ void WiFiManager::resetSettings() { WiFi.disconnect(true); WiFi.persistent(false); #endif - #ifdef WM_DEBUG_LEVEL DEBUG_WM(F("SETTINGS ERASED")); - #endif } // SETTERS @@ -2938,9 +2658,7 @@ void WiFiManager::setConfigPortalBlocking(boolean shouldBlock) { void WiFiManager::setRestorePersistent(boolean persistent) { _userpersistent = persistent; if(!persistent){ - #ifdef WM_DEBUG_LEVEL DEBUG_WM(F("persistent is off")); - #endif } } @@ -3156,9 +2874,7 @@ void WiFiManager::setTitle(String title){ * @param uint8_t menu[] array of menu ids */ void WiFiManager::setMenu(const char * menu[], uint8_t size){ -#ifdef WM_DEBUG_LEVEL // 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++){ @@ -3170,9 +2886,7 @@ void WiFiManager::setMenu(const char * menu[], uint8_t size){ } delay(0); } - #ifdef WM_DEBUG_LEVEL // DEBUG_WM(getMenuOut()); - #endif } /** @@ -3185,9 +2899,7 @@ void WiFiManager::setMenu(const char * menu[], uint8_t size){ * @param {[type]} std::vector& menu [description] */ void WiFiManager::setMenu(std::vector& menu){ -#ifdef WM_DEBUG_LEVEL // DEBUG_WM(WM_DEBUG_DEV,"setmenu vector"); - #endif _menuIds.clear(); for(auto menuitem : menu ){ for(size_t j = 0; j < _nummenutokens; j++){ @@ -3197,9 +2909,7 @@ void WiFiManager::setMenu(std::vector& menu){ } } } - #ifdef WM_DEBUG_LEVEL // DEBUG_WM(WM_DEBUG_DEV,getMenuOut()); - #endif } @@ -3326,6 +3036,7 @@ String WiFiManager::getWiFiPass(bool persistent){ // DEBUG // @todo fix DEBUG_WM(0,0); +#ifdef WM_DEBUG_LEVEL template void WiFiManager::DEBUG_WM(Generic text) { DEBUG_WM(WM_DEBUG_NOTIFY,text,""); @@ -3378,6 +3089,19 @@ void WiFiManager::DEBUG_WM(wm_debuglevel_t level,Generic text,Genericb textb) { } _debugPort.println(); } +#else + template + void WiFiManager::DEBUG_WM(Generic text) {} + + template + void WiFiManager::DEBUG_WM(wm_debuglevel_t level,Generic text) {} + + template + void WiFiManager::DEBUG_WM(Generic text,Genericb textb) {} + + template + void WiFiManager::DEBUG_WM(wm_debuglevel_t level,Generic text,Genericb textb) {} +#endif /** * [debugSoftAPConfig description] @@ -3401,7 +3125,6 @@ void WiFiManager::debugSoftAPConfig(){ esp_wifi_get_country(&country); #endif - #ifdef WM_DEBUG_LEVEL DEBUG_WM(F("SoftAP Configuration")); DEBUG_WM(FPSTR(D_HR)); DEBUG_WM(F("ssid: "),(char *) config.ssid); @@ -3411,13 +3134,10 @@ void WiFiManager::debugSoftAPConfig(){ DEBUG_WM(F("authmode: "),config.authmode); DEBUG_WM(F("ssid_hidden: "),config.ssid_hidden); DEBUG_WM(F("max_connection: "),config.max_connection); - #endif #if !defined(WM_NOCOUNTRY) - #ifdef WM_DEBUG_LEVEL DEBUG_WM(F("country: "),(String)country.cc); - #endif - DEBUG_WM(F("beacon_interval: "),(String)config.beacon_interval + "(ms)"); - DEBUG_WM(FPSTR(D_HR)); + DEBUG_WM(F("beacon_interval: "),(String)config.beacon_interval + "(ms)"); + DEBUG_WM(FPSTR(D_HR)); #endif } @@ -3429,26 +3149,20 @@ void WiFiManager::debugSoftAPConfig(){ void WiFiManager::debugPlatformInfo(){ #ifdef ESP8266 system_print_meminfo(); - #ifdef WM_DEBUG_LEVEL DEBUG_WM(F("[SYS] getCoreVersion(): "),ESP.getCoreVersion()); DEBUG_WM(F("[SYS] system_get_sdk_version(): "),system_get_sdk_version()); DEBUG_WM(F("[SYS] system_get_boot_version():"),system_get_boot_version()); DEBUG_WM(F("[SYS] getFreeHeap(): "),(String)ESP.getFreeHeap()); - #endif #elif defined(ESP32) - #ifdef WM_DEBUG_LEVEL DEBUG_WM(F("[SYS] WM version: "), String((__FlashStringHelper *)WM_VERSION_STR) +" D:"+String(_debugLevel)); DEBUG_WM(F("[SYS] Arduino version: "), VER_ARDUINO_STR); DEBUG_WM(F("[SYS] ESP SDK version: "), ESP.getSdkVersion()); DEBUG_WM(F("[SYS] Free heap: "), ESP.getFreeHeap()); - #endif - #ifdef WM_DEBUG_LEVEL DEBUG_WM(F("[SYS] Chip ID:"),WIFI_getChipId()); DEBUG_WM(F("[SYS] Chip Model:"), ESP.getChipModel()); DEBUG_WM(F("[SYS] Chip Cores:"), ESP.getChipCores()); DEBUG_WM(F("[SYS] Chip Rev:"), ESP.getChipRevision()); - #endif #endif } @@ -3491,16 +3205,12 @@ boolean WiFiManager::validApPassword(){ if (_apPassword == NULL) _apPassword = ""; if (_apPassword != "") { if (_apPassword.length() < 8 || _apPassword.length() > 63) { - #ifdef WM_DEBUG_LEVEL DEBUG_WM(F("AccessPoint set password is INVALID or <8 chars")); - #endif _apPassword = ""; return false; // @todo FATAL or fallback to empty , currently fatal, fail secure. } - #ifdef WM_DEBUG_LEVEL DEBUG_WM(WM_DEBUG_VERBOSE,F("AccessPoint set password is VALID")); DEBUG_WM(WM_DEBUG_DEV,"ap pass",_apPassword); - #endif } return true; } @@ -3543,9 +3253,7 @@ String WiFiManager::getWLStatusString(){ } String WiFiManager::encryptionTypeStr(uint8_t authmode) { -#ifdef WM_DEBUG_LEVEL // DEBUG_WM("enc_tye: ",authmode); - #endif return AUTH_MODE_NAMES[authmode]; } @@ -3557,9 +3265,7 @@ String WiFiManager::getModeString(uint8_t mode){ bool WiFiManager::WiFiSetCountry(){ if(_wificountry == "") return false; // skip not set - #ifdef WM_DEBUG_LEVEL DEBUG_WM(WM_DEBUG_VERBOSE,F("WiFiSetCountry to"),_wificountry); - #endif /* * @return @@ -3648,18 +3354,14 @@ bool WiFiManager::WiFi_Disconnect() { #ifdef ESP8266 if((WiFi.getMode() & WIFI_STA) != 0) { bool ret; - #ifdef WM_DEBUG_LEVEL DEBUG_WM(WM_DEBUG_DEV,F("WiFi station disconnect")); - #endif ETS_UART_INTR_DISABLE(); // @todo possibly not needed ret = wifi_station_disconnect(); ETS_UART_INTR_ENABLE(); return ret; } #elif defined(ESP32) - #ifdef WM_DEBUG_LEVEL DEBUG_WM(WM_DEBUG_DEV,F("WiFi station disconnect")); - #endif return WiFi.disconnect(); // not persistent atm #endif return false; @@ -3667,9 +3369,7 @@ bool WiFiManager::WiFi_Disconnect() { // toggle STA without persistent bool WiFiManager::WiFi_enableSTA(bool enable,bool persistent) { -#ifdef WM_DEBUG_LEVEL DEBUG_WM(WM_DEBUG_DEV,F("WiFi_enableSTA"),(String) enable? "enable" : "disable"); - #endif #ifdef ESP8266 WiFiMode_t newMode; WiFiMode_t currentMode = WiFi.getMode(); @@ -3704,9 +3404,7 @@ bool WiFiManager::WiFi_enableSTA(bool enable) { } bool WiFiManager::WiFi_eraseConfig() { - #ifdef WM_DEBUG_LEVEL DEBUG_WM(WM_DEBUG_DEV,F("WiFi_eraseConfig")); - #endif #ifdef ESP8266 #ifndef WM_FIXERASECONFIG @@ -3814,21 +3512,15 @@ String WiFiManager::WiFi_psk(bool persistent) const { #define ARDUINO_EVENT_WIFI_SCAN_DONE SYSTEM_EVENT_SCAN_DONE #endif if(!_hasBegun){ - #ifdef WM_DEBUG_LEVEL - // DEBUG_WM(WM_DEBUG_VERBOSE,"[ERROR] WiFiEvent, not ready"); - #endif + // DEBUG_WM(WM_DEBUG_VERBOSE,"[ERROR] WiFiEvent, not ready"); // Serial.println(F("\n[EVENT] WiFiEvent logging (wm debug not available)")); // Serial.print(F("[EVENT] ID: ")); // Serial.println(event); return; } - #ifdef WM_DEBUG_LEVEL // DEBUG_WM(WM_DEBUG_VERBOSE,"[EVENT]",event); - #endif if(event == ARDUINO_EVENT_WIFI_STA_DISCONNECTED){ - #ifdef WM_DEBUG_LEVEL 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(); @@ -3840,9 +3532,7 @@ String WiFiManager::WiFi_psk(bool persistent) const { } #endif #ifdef esp32autoreconnect - #ifdef WM_DEBUG_LEVEL DEBUG_WM(WM_DEBUG_VERBOSE,F("[Event] SYSTEM_EVENT_STA_DISCONNECTED, reconnecting")); - #endif WiFi.reconnect(); #endif } @@ -3859,9 +3549,7 @@ void WiFiManager::WiFi_autoReconnect(){ #elif defined(ESP32) // if(_wifiAutoReconnect){ // @todo move to seperate method, used for event listener now - #ifdef WM_DEBUG_LEVEL 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)); // } @@ -3870,9 +3558,7 @@ void WiFiManager::WiFi_autoReconnect(){ // Called when /update is requested void WiFiManager::handleUpdate() { - #ifdef WM_DEBUG_LEVEL 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 String str = FPSTR(HTTP_ROOT_MAIN); @@ -3928,9 +3614,7 @@ void WiFiManager::handleUpdating(){ maxSketchSpace = UPDATE_SIZE_UNKNOWN; #endif - #ifdef WM_DEBUG_LEVEL DEBUG_WM(WM_DEBUG_VERBOSE,"[OTA] Update file: ", upload.filename.c_str()); - #endif // Update.onProgress(THandlerFunction_Progress fn); // Update.onProgress([](unsigned int progress, unsigned int total) { @@ -3938,9 +3622,7 @@ void WiFiManager::handleUpdating(){ // }); if (!Update.begin(maxSketchSpace)) { // start with max available size - #ifdef WM_DEBUG_LEVEL 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.. } @@ -3949,20 +3631,16 @@ void WiFiManager::handleUpdating(){ else if (upload.status == UPLOAD_FILE_WRITE) { // Serial.print("."); if (Update.write(upload.buf, upload.currentSize) != upload.currentSize) { - #ifdef WM_DEBUG_LEVEL DEBUG_WM(WM_DEBUG_ERROR,F("[ERROR] OTA Update WRITE ERROR"), Update.getError()); //Update.printError(Serial); // write failure - #endif error = true; } } // UPLOAD FILE END 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(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 } else { // Update.printError(Serial); diff --git a/WiFiManager.h b/WiFiManager.h index f911beb0..ce7927d9 100644 --- a/WiFiManager.h +++ b/WiFiManager.h @@ -14,6 +14,7 @@ #ifndef WiFiManager_h #define WiFiManager_h + #if defined(ESP8266) || defined(ESP32) #ifdef ESP8266