mirror of
https://github.com/alexhopeoconnor/WiFiManager.git
synced 2026-10-13 14:51:21 +10:00
added debug levels
This commit is contained in:
+113
-93
@@ -97,26 +97,27 @@ const char* WiFiManagerParameter::getCustomHTML() {
|
||||
*/
|
||||
bool WiFiManager::addParameter(WiFiManagerParameter *p) {
|
||||
|
||||
// check param id is valid
|
||||
// check param id is valid, unless null
|
||||
if(p->getID()){
|
||||
for (int i = 0; i < strlen(p->getID()); i++){
|
||||
if(!isAlphaNumeric(p->getID()[i])){
|
||||
DEBUG_WM("[ERROR] parameter IDs can only contain alpha numeric chars");
|
||||
DEBUG_WM(DEBUG_ERROR,"[ERROR] parameter IDs can only contain alpha numeric chars");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// init params if never malloc
|
||||
if(_params == NULL){
|
||||
DEBUG_WM("allocating params bytes:",_max_params * sizeof(WiFiManagerParameter*));
|
||||
DEBUG_WM(DEBUG_DEV,"allocating params bytes:",_max_params * sizeof(WiFiManagerParameter*));
|
||||
_params = (WiFiManagerParameter**)malloc(_max_params * sizeof(WiFiManagerParameter*));
|
||||
}
|
||||
|
||||
// resize the params array by increment of WIFI_MANAGER_MAX_PARAMS
|
||||
if(_paramsCount == _max_params){
|
||||
// resize the params array by increment of WIFI_MANAGER_MAX_PARAMS
|
||||
_max_params += WIFI_MANAGER_MAX_PARAMS;
|
||||
DEBUG_WM(F("Updated _max_params:"),_max_params);
|
||||
DEBUG_WM("re-allocating params bytes:",_max_params * sizeof(WiFiManagerParameter*));
|
||||
DEBUG_WM(DEBUG_DEV,F("Updated _max_params:"),_max_params);
|
||||
DEBUG_WM(DEBUG_DEV,"re-allocating params bytes:",_max_params * sizeof(WiFiManagerParameter*));
|
||||
WiFiManagerParameter** new_params = (WiFiManagerParameter**)realloc(_params, _max_params * sizeof(WiFiManagerParameter*));
|
||||
// DEBUG_WM(WIFI_MANAGER_MAX_PARAMS);
|
||||
// DEBUG_WM(_paramsCount);
|
||||
@@ -124,12 +125,14 @@ bool WiFiManager::addParameter(WiFiManagerParameter *p) {
|
||||
if (new_params != NULL) {
|
||||
_params = new_params;
|
||||
} else {
|
||||
DEBUG_WM("[ERROR] failed to realloc params, size not increased!");
|
||||
DEBUG_WM(DEBUG_ERROR,"[ERROR] failed to realloc params, size not increased!");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
_params[_paramsCount] = p;
|
||||
_paramsCount++;
|
||||
|
||||
DEBUG_WM("Added Parameter:",p->getID());
|
||||
return true;
|
||||
}
|
||||
@@ -149,7 +152,7 @@ WiFiManager::WiFiManager():WiFiManager(Serial) {
|
||||
}
|
||||
|
||||
void WiFiManager::WiFiManagerInit(){
|
||||
// if(_debug && _debugLevel > 2) debugPlatformInfo();
|
||||
if(_debug && _debugLevel > DEBUG_DEV) debugPlatformInfo();
|
||||
_usermode = WiFi.getMode();
|
||||
WiFi.persistent(false); // disable persistent so scannetworks and mode switching do not cause overwrites
|
||||
|
||||
@@ -165,11 +168,11 @@ WiFiManager::~WiFiManager() {
|
||||
// parameters
|
||||
// @todo belongs to wifimanagerparameter
|
||||
if (_params != NULL){
|
||||
DEBUG_WM(F("freeing allocated params!"));
|
||||
DEBUG_WM(DEBUG_DEV,F("freeing allocated params!"));
|
||||
free(_params);
|
||||
}
|
||||
|
||||
DEBUG_WM(F("unloading"));
|
||||
DEBUG_WM(DEBUG_DEV,F("unloading"));
|
||||
}
|
||||
|
||||
// AUTOCONNECT
|
||||
@@ -192,7 +195,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.
|
||||
DEBUG_WM("[FATAL] Unable to enable wifi!");
|
||||
DEBUG_WM(DEBUG_ERROR,"[FATAL] Unable to enable wifi!");
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -207,12 +210,12 @@ boolean WiFiManager::autoConnect(char const *apName, char const *apPassword) {
|
||||
|
||||
// set hostname before stating
|
||||
if((String)_hostname != ""){
|
||||
DEBUG_WM("Setting hostname:",_hostname);
|
||||
DEBUG_WM(DEBUG_VERBOSE,"Setting hostname:",_hostname);
|
||||
bool res = true;
|
||||
#ifdef ESP8266
|
||||
res = WiFi.hostname(_hostname);
|
||||
#ifdef ESP8266MDNS_H
|
||||
DEBUG_WM("Setting MDNS hostname");
|
||||
DEBUG_WM(DEBUG_VERBOSE,"Setting MDNS hostname");
|
||||
if(MDNS.begin(_hostname)){
|
||||
MDNS.addService("http", "tcp", 80);
|
||||
}
|
||||
@@ -222,17 +225,17 @@ boolean WiFiManager::autoConnect(char const *apName, char const *apPassword) {
|
||||
delay(200); // do not remove, give time for STA_START
|
||||
res = WiFi.setHostname(_hostname);
|
||||
#ifdef ESP32MDNS_H
|
||||
DEBUG_WM("Setting MDNS hostname");
|
||||
DEBUG_WM(DEBUG_VERBOSE,"Setting MDNS hostname");
|
||||
if(MDNS.begin(_hostname)){
|
||||
MDNS.addService("http", "tcp", 80);
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
if(!res)DEBUG_WM(F("hostname: set failed!"));
|
||||
if(!res)DEBUG_WM(DEBUG_ERROR,F("[ERROR] hostname: set failed!"));
|
||||
|
||||
if(WiFi.status() == WL_CONNECTED){
|
||||
DEBUG_WM(F("reconnecting to set new hostname"));
|
||||
DEBUG_WM(DEBUG_VERBOSE,F("reconnecting to set new hostname"));
|
||||
// WiFi.reconnect(); // This does not reset dhcp
|
||||
WiFi_Disconnect();
|
||||
delay(200); // do not remove, need a delay for disconnect to change status()
|
||||
@@ -248,9 +251,9 @@ boolean WiFiManager::autoConnect(char const *apName, char const *apPassword) {
|
||||
|
||||
if((String)_hostname != ""){
|
||||
#ifdef ESP8266
|
||||
DEBUG_WM("hostname: STA",WiFi.hostname());
|
||||
DEBUG_WM(DEBUG_DEV,"hostname: STA",WiFi.hostname());
|
||||
#elif defined(ESP32)
|
||||
DEBUG_WM("hostname: STA",WiFi.getHostname());
|
||||
DEBUG_WM(DEBUG_DEV,"hostname: STA",WiFi.getHostname());
|
||||
#endif
|
||||
}
|
||||
return true;
|
||||
@@ -274,13 +277,13 @@ bool WiFiManager::startAP(){
|
||||
if (_apPassword != "") {
|
||||
ret = WiFi.softAP(_apName.c_str(), _apPassword.c_str());//password option
|
||||
} else {
|
||||
DEBUG_WM(F("AP has anonymous access!"));
|
||||
DEBUG_WM(DEBUG_VERBOSE,F("AP has anonymous access!"));
|
||||
ret = WiFi.softAP(_apName.c_str());
|
||||
}
|
||||
|
||||
if(_debugLevel > 1) debugSoftAPConfig();
|
||||
if(_debugLevel > DEBUG_DEV) debugSoftAPConfig();
|
||||
|
||||
if(!ret) DEBUG_WM("[ERROR] There was a problem starting the AP");
|
||||
if(!ret) DEBUG_WM(DEBUG_ERROR,"[ERROR] There was a problem starting the AP");
|
||||
|
||||
delay(500); // slight delay to make sure we get an AP IP
|
||||
DEBUG_WM(F("AP IP address:"),WiFi.softAPIP());
|
||||
@@ -288,9 +291,10 @@ bool WiFiManager::startAP(){
|
||||
// set ap hostname
|
||||
#ifdef ESP32
|
||||
if(ret && (String)_hostname != ""){
|
||||
DEBUG_WM(DEBUG_VERBOSE,"setting softAP Hostname:",_hostname);
|
||||
bool res = WiFi.softAPsetHostname(_hostname);
|
||||
if(!res)DEBUG_WM(F("hostname: AP set failed!"));
|
||||
DEBUG_WM(F("hostname: AP"),WiFi.softAPgetHostname());
|
||||
DEBUG_WM(DEBUG_DEV,F("hostname: AP"),WiFi.softAPgetHostname());
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -320,7 +324,7 @@ void WiFiManager::startWebPortal() {
|
||||
*/
|
||||
void WiFiManager::stopWebPortal() {
|
||||
if(!configPortalActive && !webPortalActive) return;
|
||||
DEBUG_WM(F("Stopping Web Portal"));
|
||||
DEBUG_WM(DEBUG_VERBOSE,F("Stopping Web Portal"));
|
||||
webPortalActive = false;
|
||||
stopConfigPortal();
|
||||
}
|
||||
@@ -330,7 +334,7 @@ boolean WiFiManager::configPortalHasTimeout(){
|
||||
if(_configPortalTimeout == 0 || (_cpClientCheck && (WiFi_softap_num_stations() > 0))){
|
||||
if(millis() - timer > 30000){
|
||||
timer = millis();
|
||||
if(_debugLevel > 0) DEBUG_WM("NUM CLIENTS: " + (String)WiFi_softap_num_stations());
|
||||
DEBUG_WM(DEBUG_VERBOSE,"NUM CLIENTS: " + (String)WiFi_softap_num_stations());
|
||||
}
|
||||
_configPortalStart = millis(); // kludge, bump configportal start time to skew timeouts
|
||||
return false;
|
||||
@@ -347,7 +351,7 @@ boolean WiFiManager::configPortalHasTimeout(){
|
||||
uint16_t logintvl = 30000; // how often to emit timeing out counter logging
|
||||
if((millis() - timer) > logintvl){
|
||||
timer = millis();
|
||||
DEBUG_WM(F("Portal Timeout In"),(String)((_configPortalStart + _configPortalTimeout-millis())/1000) + (String)F(" seconds"));
|
||||
DEBUG_WM(DEBUG_VERBOSE,F("Portal Timeout In"),(String)((_configPortalStart + _configPortalTimeout-millis())/1000) + (String)F(" seconds"));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -366,7 +370,7 @@ void WiFiManager::setupConfigPortal() {
|
||||
/* Setup the DNS server redirecting all the domains to the apIP */
|
||||
dnsServer->setErrorReplyCode(DNSReplyCode::NoError);
|
||||
// DEBUG_WM("dns server started port: ",DNS_PORT);
|
||||
DEBUG_WM("dns server started with ip: ",WiFi.softAPIP());
|
||||
DEBUG_WM(DEBUG_DEV,"dns server started with ip: ",WiFi.softAPIP());
|
||||
dnsServer->start(DNS_PORT, F("*"), WiFi.softAPIP());
|
||||
|
||||
/* Setup httpd callbacks, web pages: root, wifi config pages, SO captive portal detectors and not found. */
|
||||
@@ -386,7 +390,7 @@ void WiFiManager::setupConfigPortal() {
|
||||
server->onNotFound (std::bind(&WiFiManager::handleNotFound, this));
|
||||
|
||||
server->begin(); // Web server start
|
||||
DEBUG_WM(F("HTTP server started"));
|
||||
DEBUG_WM(DEBUG_VERBOSE,F("HTTP server started"));
|
||||
|
||||
if(_preloadwifiscan) WiFi_scanNetworks(); // preload wifiscan
|
||||
}
|
||||
@@ -419,7 +423,7 @@ boolean WiFiManager::startConfigPortal(char const *apName, char const *apPasswo
|
||||
// this fixes most ap problems, however, simply doing mode(WIFI_AP) does not work if sta connection is hanging, must `wifi_station_disconnect`
|
||||
WiFi_Disconnect();
|
||||
WiFi_enableSTA(false);
|
||||
DEBUG_WM(F("Disabling STA"));
|
||||
DEBUG_WM(DEBUG_VERBOSE,F("Disabling STA"));
|
||||
}
|
||||
else {
|
||||
// @todo even if sta is connected, it is possible that softap connections will fail, IOS says "invalid password", windows says "cannot connect to this network" researching
|
||||
@@ -434,25 +438,25 @@ boolean WiFiManager::startConfigPortal(char const *apName, char const *apPasswo
|
||||
_configPortalStart = millis();
|
||||
|
||||
// start access point
|
||||
DEBUG_WM(F("Enabling AP"));
|
||||
DEBUG_WM(DEBUG_VERBOSE,F("Enabling AP"));
|
||||
startAP();
|
||||
|
||||
// init configportal
|
||||
DEBUG_WM(F("setupConfigPortal"));
|
||||
DEBUG_WM(DEBUG_VERBOSE,F("setupConfigPortal"));
|
||||
setupConfigPortal();
|
||||
|
||||
if(!_configPortalIsBlocking){
|
||||
DEBUG_WM(F("Config Portal Running, non blocking/processing"));
|
||||
DEBUG_WM(DEBUG_VERBOSE,F("Config Portal Running, non blocking/processing"));
|
||||
return result;
|
||||
}
|
||||
|
||||
DEBUG_WM(F("Config Portal Running, blocking, waiting for clients..."));
|
||||
DEBUG_WM(DEBUG_VERBOSE,F("Config Portal Running, blocking, waiting for clients..."));
|
||||
// blocking loop waiting for config
|
||||
while(1){
|
||||
|
||||
// if timed out or abort, break
|
||||
if(configPortalHasTimeout() || abort){
|
||||
DEBUG_WM(F("configportal abort"));
|
||||
DEBUG_WM(DEBUG_DEV,F("configportal abort"));
|
||||
stopConfigPortal();
|
||||
result = abort ? portalAbortResult : portalTimeoutResult; // false, false
|
||||
break;
|
||||
@@ -469,7 +473,7 @@ boolean WiFiManager::startConfigPortal(char const *apName, char const *apPasswo
|
||||
yield(); // watchdog
|
||||
}
|
||||
|
||||
DEBUG_WM(F("config portal exiting"));
|
||||
DEBUG_WM(DEBUG_NOTIFY,F("config portal exiting"));
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -511,7 +515,7 @@ uint8_t WiFiManager::processConfigPortal(){
|
||||
return WL_CONNECTED; // CONNECT SUCCESS
|
||||
}
|
||||
|
||||
DEBUG_WM(F("Connect to new AP [FAILED]"));
|
||||
DEBUG_WM(DEBUG_ERROR,F("[ERROR] Connect to new AP Failed"));
|
||||
|
||||
if (_shouldBreakAfterConfig) {
|
||||
// do save callback
|
||||
@@ -527,7 +531,7 @@ uint8_t WiFiManager::processConfigPortal(){
|
||||
// if connect fails, turn sta off to stabilize AP
|
||||
WiFi_Disconnect();
|
||||
WiFi_enableSTA(false);
|
||||
DEBUG_WM(F("Disabling STA"));
|
||||
DEBUG_WM(DEBUG_VERBOSE,F("Disabling STA"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -560,7 +564,7 @@ boolean WiFiManager::stopConfigPortal(){
|
||||
// [APdisconnect] set_config failed!
|
||||
// *WM: disconnect configportal - softAPdisconnect failed
|
||||
// still no way to reproduce reliably
|
||||
DEBUG_WM(F("disconnect configportal"));
|
||||
DEBUG_WM(DEBUG_VERBOSE,F("disconnect configportal"));
|
||||
bool ret = false;
|
||||
ret = WiFi.softAPdisconnect(false);
|
||||
if(!ret)DEBUG_WM(F("disconnect configportal - softAPdisconnect FAILED"));
|
||||
@@ -576,14 +580,14 @@ boolean WiFiManager::stopConfigPortal(){
|
||||
// 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) {
|
||||
DEBUG_WM(F("Connecting as wifi client..."));
|
||||
DEBUG_WM(DEBUG_VERBOSE,F("Connecting as wifi client..."));
|
||||
|
||||
bool waitforconx = true;
|
||||
|
||||
// Setup static IP config if provided
|
||||
if (_sta_static_ip) {
|
||||
WiFi.config(_sta_static_ip, _sta_static_gw, _sta_static_sn);
|
||||
DEBUG_WM(F("Custom STA IP/GW/Subnet:"),WiFi.localIP());
|
||||
DEBUG_WM(DEBUG_VERBOSE,F("Custom STA IP/GW/Subnet:"),WiFi.localIP());
|
||||
}
|
||||
|
||||
// make sure sta is on before `begin` so it does not call enablesta->mode while persistent is ON ( which would save WM AP state to eeprom !)
|
||||
@@ -610,7 +614,7 @@ uint8_t WiFiManager::connectWifi(String ssid, String pass) {
|
||||
}
|
||||
|
||||
uint8_t connRes = waitforconx ? waitForConnectResult() : (uint8_t)WL_NO_SSID_AVAIL;
|
||||
DEBUG_WM (F("Connection result:"),getWLStatusString(connRes));
|
||||
DEBUG_WM(DEBUG_VERBOSE,F("Connection result:"),getWLStatusString(connRes));
|
||||
|
||||
// do WPS, if WPS options enabled and not connected and no password was supplied
|
||||
// @todo this seems like wrong place for this, is it a fallback or option?
|
||||
@@ -640,14 +644,14 @@ void WiFiManager::updateConxResult(uint8_t status){
|
||||
#elif defined(ESP32)
|
||||
// if(_lastconxresult == WL_CONNECT_FAILED){
|
||||
if(_lastconxresult == WL_CONNECT_FAILED || _lastconxresult == WL_DISCONNECTED){
|
||||
DEBUG_WM("lastconxresulttmp:",getWLStatusString(_lastconxresulttmp));
|
||||
DEBUG_WM(DEBUG_DEV,"lastconxresulttmp:",getWLStatusString(_lastconxresulttmp));
|
||||
if(_lastconxresulttmp != WL_IDLE_STATUS){
|
||||
_lastconxresult = _lastconxresulttmp;
|
||||
// _lastconxresulttmp = WL_IDLE_STATUS;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
DEBUG_WM("lastconxresult:",getWLStatusString(_lastconxresult));
|
||||
DEBUG_WM(DEBUG_DEV,"lastconxresult:",getWLStatusString(_lastconxresult));
|
||||
}
|
||||
|
||||
// @todo uses _connectTimeout for wifi save also, add timeout argument to bypass?
|
||||
@@ -672,7 +676,7 @@ uint8_t WiFiManager::waitForConnectResult() {
|
||||
if (status == WL_CONNECTED || status == WL_CONNECT_FAILED) {
|
||||
return status;
|
||||
}
|
||||
DEBUG_WM (F("."));
|
||||
DEBUG_WM (2,F("."));
|
||||
delay(100);
|
||||
}
|
||||
return status;
|
||||
@@ -711,7 +715,7 @@ void WiFiManager::handleRequest() {
|
||||
* HTTPD CALLBACK root or redirect to captive portal
|
||||
*/
|
||||
void WiFiManager::handleRoot() {
|
||||
DEBUG_WM(F("<- HTTP Root"));
|
||||
DEBUG_WM(DEBUG_VERBOSE,F("<- HTTP Root"));
|
||||
if (captivePortal()) return; // If captive portal redirect instead of displaying the page
|
||||
handleRequest();
|
||||
String page = getHTTPHead(FPSTR(S_options)); // @token options
|
||||
@@ -733,7 +737,7 @@ void WiFiManager::handleRoot() {
|
||||
* HTTPD CALLBACK Wifi config page handler
|
||||
*/
|
||||
void WiFiManager::handleWifi(boolean scan) {
|
||||
DEBUG_WM(F("<- HTTP Wifi"));
|
||||
DEBUG_WM(DEBUG_VERBOSE,F("<- HTTP Wifi"));
|
||||
handleRequest();
|
||||
String page = getHTTPHead(FPSTR(S_titlewifi)); // @token titlewifi
|
||||
if (scan) {
|
||||
@@ -744,7 +748,7 @@ void WiFiManager::handleWifi(boolean scan) {
|
||||
String pitem = "";
|
||||
|
||||
pitem = FPSTR(HTTP_FORM_START);
|
||||
pitem.replace(FPSTR(T_v), F("wifisave"));
|
||||
pitem.replace(FPSTR(T_v), F("wifisave")); // set form action
|
||||
page += pitem;
|
||||
|
||||
pitem = FPSTR(HTTP_FORM_WIFI);
|
||||
@@ -765,14 +769,14 @@ void WiFiManager::handleWifi(boolean scan) {
|
||||
server->send(200, FPSTR(HTTP_HEAD_CT), page);
|
||||
// server->close(); // testing reliability fix for content length mismatches during mutiple flood hits
|
||||
|
||||
DEBUG_WM(F("Sent config page"));
|
||||
DEBUG_WM(DEBUG_DEV,F("Sent config page"));
|
||||
}
|
||||
|
||||
/**
|
||||
* HTTPD CALLBACK Wifi param page handler
|
||||
*/
|
||||
void WiFiManager::handleParam(){
|
||||
DEBUG_WM(F("<- HTTP Param"));
|
||||
DEBUG_WM(DEBUG_VERBOSE,F("<- HTTP Param"));
|
||||
handleRequest();
|
||||
String page = getHTTPHead(FPSTR(S_titleparam)); // @token titlewifi
|
||||
|
||||
@@ -790,7 +794,7 @@ void WiFiManager::handleParam(){
|
||||
server->sendHeader(FPSTR(HTTP_HEAD_CL), String(page.length()));
|
||||
server->send(200, FPSTR(HTTP_HEAD_CT), page);
|
||||
|
||||
DEBUG_WM(F("Sent param page"));
|
||||
DEBUG_WM(DEBUG_DEV,F("Sent param page"));
|
||||
}
|
||||
|
||||
|
||||
@@ -816,9 +820,9 @@ bool WiFiManager::WiFi_scanNetworks(bool force){
|
||||
if(force || _numNetworks == 0 || (millis()-_lastscan > 60000)){
|
||||
_numNetworks = WiFi.scanNetworks();
|
||||
_lastscan = millis();
|
||||
DEBUG_WM(F("Scan done"));
|
||||
DEBUG_WM(DEBUG_VERBOSE,F("WiFi Scan done"));
|
||||
return true;
|
||||
} else DEBUG_WM("Scan is cached");
|
||||
} else DEBUG_WM(DEBUG_VERBOSE,"Scan is cached");
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -830,8 +834,9 @@ String WiFiManager::WiFiManager::getScanItemOut(){
|
||||
if (n == 0) {
|
||||
DEBUG_WM(F("No networks found"));
|
||||
page += FPSTR(S_nonetworks); // @token nonetworks
|
||||
} else {
|
||||
|
||||
}
|
||||
else {
|
||||
DEBUG_WM(n,F("networks found"));
|
||||
//sort networks
|
||||
int indices[n];
|
||||
for (int i = 0; i < n; i++) {
|
||||
@@ -839,8 +844,6 @@ String WiFiManager::WiFiManager::getScanItemOut(){
|
||||
}
|
||||
|
||||
// RSSI SORT
|
||||
|
||||
// old sort
|
||||
for (int i = 0; i < n; i++) {
|
||||
for (int j = i + 1; j < n; j++) {
|
||||
if (WiFi.RSSI(indices[j]) > WiFi.RSSI(indices[i])) {
|
||||
@@ -849,10 +852,12 @@ String WiFiManager::WiFiManager::getScanItemOut(){
|
||||
}
|
||||
}
|
||||
|
||||
/*std::sort(indices, indices + n, [](const int & a, const int & b) -> bool
|
||||
/* test std:sort
|
||||
std::sort(indices, indices + n, [](const int & a, const int & b) -> bool
|
||||
{
|
||||
return WiFi.RSSI(a) > WiFi.RSSI(b);
|
||||
});*/
|
||||
});
|
||||
*/
|
||||
|
||||
// remove duplicates ( must be RSSI sorted )
|
||||
if (_removeDuplicateAPs) {
|
||||
@@ -862,7 +867,7 @@ String WiFiManager::WiFiManager::getScanItemOut(){
|
||||
cssid = WiFi.SSID(indices[i]);
|
||||
for (int j = i + 1; j < n; j++) {
|
||||
if (cssid == WiFi.SSID(indices[j])) {
|
||||
DEBUG_WM(F("DUP AP:"),WiFi.SSID(indices[j]));
|
||||
DEBUG_WM(DEBUG_VERBOSE,F("DUP AP:"),WiFi.SSID(indices[j]));
|
||||
indices[j] = -1; // set dup aps to index -1
|
||||
}
|
||||
}
|
||||
@@ -878,6 +883,7 @@ String WiFiManager::WiFiManager::getScanItemOut(){
|
||||
HTTP_ITEM_STR.replace("{qi}", FPSTR(HTTP_ITEM_QI));
|
||||
HTTP_ITEM_STR.replace("{h}",_scanDispOptions ? "h" : "");
|
||||
|
||||
// set token precheck flags
|
||||
bool tok_r = HTTP_ITEM_STR.indexOf(FPSTR(T_r)) > 0;
|
||||
bool tok_R = HTTP_ITEM_STR.indexOf(FPSTR(T_R)) > 0;
|
||||
bool tok_e = HTTP_ITEM_STR.indexOf(FPSTR(T_e)) > 0;
|
||||
@@ -888,7 +894,7 @@ String WiFiManager::WiFiManager::getScanItemOut(){
|
||||
for (int i = 0; i < n; i++) {
|
||||
if (indices[i] == -1) continue; // skip dups
|
||||
|
||||
DEBUG_WM(F("AP: "),(String)WiFi.RSSI(indices[i]) + " " + (String)WiFi.SSID(indices[i]));
|
||||
DEBUG_WM(DEBUG_VERBOSE,F("AP: "),(String)WiFi.RSSI(indices[i]) + " " + (String)WiFi.SSID(indices[i]));
|
||||
|
||||
int rssiperc = getRSSIasQuality(WiFi.RSSI(indices[i]));
|
||||
uint8_t enc_type = WiFi.encryptionType(indices[i]);
|
||||
@@ -911,7 +917,7 @@ String WiFiManager::WiFiManager::getScanItemOut(){
|
||||
page += item;
|
||||
delay(0);
|
||||
} else {
|
||||
DEBUG_WM(F("Skipping , does not meet _minimumQuality"));
|
||||
DEBUG_WM(DEBUG_VERBOSE,F("Skipping , does not meet _minimumQuality"));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1014,7 +1020,7 @@ String WiFiManager::getParamOut(){
|
||||
}
|
||||
|
||||
void WiFiManager::handleWiFiStatus(){
|
||||
DEBUG_WM(F("<- HTTP WiFi status "));
|
||||
DEBUG_WM(DEBUG_VERBOSE,F("<- HTTP WiFi status "));
|
||||
handleRequest();
|
||||
String page;
|
||||
// String page = "{\"result\":true,\"count\":1}";
|
||||
@@ -1029,8 +1035,8 @@ void WiFiManager::handleWiFiStatus(){
|
||||
* HTTPD CALLBACK save form and redirect to WLAN config page again
|
||||
*/
|
||||
void WiFiManager::handleWifiSave() {
|
||||
DEBUG_WM(F("<- HTTP WiFi save "));
|
||||
DEBUG_WM(F("Method:"),server->method() == HTTP_GET ? (String)FPSTR(S_GET) : (String)FPSTR(S_POST));
|
||||
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));
|
||||
handleRequest();
|
||||
|
||||
//SAVE/connect here
|
||||
@@ -1043,17 +1049,17 @@ 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());
|
||||
DEBUG_WM(F("static ip:"),ip);
|
||||
DEBUG_WM(DEBUG_DEV,F("static ip:"),ip);
|
||||
}
|
||||
if (server->arg(FPSTR(S_gw)) != "") {
|
||||
String gw = server->arg(FPSTR(S_gw));
|
||||
optionalIPFromString(&_sta_static_gw, gw.c_str());
|
||||
DEBUG_WM(F("static gateway:"),gw);
|
||||
DEBUG_WM(DEBUG_DEV,F("static gateway:"),gw);
|
||||
}
|
||||
if (server->arg(FPSTR(S_sn)) != "") {
|
||||
String sn = server->arg(FPSTR(S_sn));
|
||||
optionalIPFromString(&_sta_static_sn, sn.c_str());
|
||||
DEBUG_WM(F("static netmask:"),sn);
|
||||
DEBUG_WM(DEBUG_DEV,F("static netmask:"),sn);
|
||||
}
|
||||
|
||||
String page = getHTTPHead(FPSTR(S_titlewifisaved)); // @token titlewifisaved
|
||||
@@ -1063,15 +1069,15 @@ void WiFiManager::handleWifiSave() {
|
||||
server->sendHeader(FPSTR(HTTP_HEAD_CL), String(page.length()));
|
||||
server->send(200, FPSTR(HTTP_HEAD_CT), page);
|
||||
|
||||
DEBUG_WM(F("Sent wifi save page"));
|
||||
DEBUG_WM(DEBUG_DEV,F("Sent wifi save page"));
|
||||
|
||||
connect = true; //signal ready to connect/reset
|
||||
}
|
||||
|
||||
void WiFiManager::handleParamSave() {
|
||||
|
||||
DEBUG_WM(F("<- HTTP WiFi save "));
|
||||
DEBUG_WM(F("Method:"),server->method() == HTTP_GET ? (String)FPSTR(S_GET) : (String)FPSTR(S_POST));
|
||||
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));
|
||||
handleRequest();
|
||||
doParamSave();
|
||||
|
||||
@@ -1082,14 +1088,14 @@ void WiFiManager::handleParamSave() {
|
||||
server->sendHeader(FPSTR(HTTP_HEAD_CL), String(page.length()));
|
||||
server->send(200, FPSTR(HTTP_HEAD_CT), page);
|
||||
|
||||
DEBUG_WM(F("Sent param save page"));
|
||||
DEBUG_WM(DEBUG_DEV,F("Sent param save page"));
|
||||
}
|
||||
|
||||
void WiFiManager::doParamSave(){
|
||||
//parameters
|
||||
if(_paramsCount > 0){
|
||||
DEBUG_WM(F("Parameters"));
|
||||
DEBUG_WM(FPSTR(D_HR));
|
||||
DEBUG_WM(DEBUG_VERBOSE,F("Parameters"));
|
||||
DEBUG_WM(DEBUG_VERBOSE,FPSTR(D_HR));
|
||||
for (int i = 0; i < _paramsCount; i++) {
|
||||
if (_params[i] == NULL) {
|
||||
break;
|
||||
@@ -1101,9 +1107,9 @@ void WiFiManager::doParamSave(){
|
||||
|
||||
//store it in params array
|
||||
value.toCharArray(_params[i]->_value, _params[i]->_length+1); // length+1 null terminated
|
||||
DEBUG_WM((String)_params[i]->getID() + ":",value);
|
||||
DEBUG_WM(DEBUG_VERBOSE,(String)_params[i]->getID() + ":",value);
|
||||
}
|
||||
DEBUG_WM(FPSTR(D_HR));
|
||||
DEBUG_WM(DEBUG_VERBOSE,FPSTR(D_HR));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1111,7 +1117,7 @@ void WiFiManager::doParamSave(){
|
||||
* HTTPD CALLBACK info page
|
||||
*/
|
||||
void WiFiManager::handleInfo() {
|
||||
DEBUG_WM(F("<- HTTP Info"));
|
||||
DEBUG_WM(DEBUG_VERBOSE,F("<- HTTP Info"));
|
||||
handleRequest();
|
||||
String page = getHTTPHead(FPSTR(S_titleinfo)); // @token titleinfo
|
||||
reportStatus(page);
|
||||
@@ -1199,7 +1205,7 @@ void WiFiManager::handleInfo() {
|
||||
server->sendHeader(FPSTR(HTTP_HEAD_CL), String(page.length()));
|
||||
server->send(200, FPSTR(HTTP_HEAD_CT), page);
|
||||
|
||||
DEBUG_WM(F("Sent info page"));
|
||||
DEBUG_WM(DEBUG_DEV,F("Sent info page"));
|
||||
}
|
||||
|
||||
String WiFiManager::getInfoData(String id){
|
||||
@@ -1380,7 +1386,7 @@ String WiFiManager::getInfoData(String id){
|
||||
* HTTPD CALLBACK root or redirect to captive portal
|
||||
*/
|
||||
void WiFiManager::handleExit() {
|
||||
DEBUG_WM(F("<- HTTP Exit"));
|
||||
DEBUG_WM(DEBUG_VERBOSE,F("<- HTTP Exit"));
|
||||
handleRequest();
|
||||
String page = getHTTPHead(FPSTR(S_titleexit)); // @token titleexit
|
||||
page += FPSTR(S_exiting); // @token exiting
|
||||
@@ -1393,7 +1399,7 @@ void WiFiManager::handleExit() {
|
||||
* HTTPD CALLBACK reset page
|
||||
*/
|
||||
void WiFiManager::handleReset() {
|
||||
DEBUG_WM(F("<- HTTP Reset"));
|
||||
DEBUG_WM(DEBUG_VERBOSE,F("<- HTTP Reset"));
|
||||
handleRequest();
|
||||
String page = getHTTPHead(FPSTR(S_titlereset)); //@token titlereset
|
||||
page += FPSTR(S_resetting); //@token resetting
|
||||
@@ -1411,7 +1417,7 @@ void WiFiManager::handleReset() {
|
||||
* HTTPD CALLBACK erase page
|
||||
*/
|
||||
void WiFiManager::handleErase() {
|
||||
DEBUG_WM(F("<- HTTP Erase"));
|
||||
DEBUG_WM(DEBUG_VERBOSE,F("<- HTTP Erase"));
|
||||
handleRequest();
|
||||
String page = getHTTPHead(FPSTR(S_titleerase)); // @token titleerase
|
||||
page += FPSTR(HTTP_HEAD_END);
|
||||
@@ -1421,7 +1427,7 @@ void WiFiManager::handleErase() {
|
||||
if(ret) page += FPSTR(S_resetting); // @token resetting
|
||||
else {
|
||||
page += FPSTR(S_error); // @token erroroccur
|
||||
DEBUG_WM(F("[ERROR] WiFi EraseConfig failed"));
|
||||
DEBUG_WM(DEBUG_ERROR,F("[ERROR] WiFi EraseConfig failed"));
|
||||
}
|
||||
|
||||
page += FPSTR(HTTP_END);
|
||||
@@ -1466,12 +1472,12 @@ void WiFiManager::handleNotFound() {
|
||||
* Return true in that case so the page handler do not try to handle the request again.
|
||||
*/
|
||||
boolean WiFiManager::captivePortal() {
|
||||
DEBUG_WM("-> " + server->hostHeader());
|
||||
DEBUG_WM(DEBUG_DEV,"-> " + server->hostHeader());
|
||||
|
||||
if(!_enableCaptivePortal) return false; // skip redirections
|
||||
|
||||
if (!isIp(server->hostHeader())) {
|
||||
DEBUG_WM(F("<- Request redirected to captive portal"));
|
||||
DEBUG_WM(DEBUG_VERBOSE,F("<- Request redirected to captive portal"));
|
||||
server->sendHeader(F("Location"), (String)F("http://") + toStringIp(server->client().localIP()), true);
|
||||
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
|
||||
@@ -1539,7 +1545,7 @@ void WiFiManager::reportStatus(String &page){
|
||||
*/
|
||||
bool WiFiManager::disconnect(){
|
||||
if(WiFi.status() != WL_CONNECTED){
|
||||
DEBUG_WM("Disconnecting: Not connected");
|
||||
DEBUG_WM(DEBUG_VERBOSE,"Disconnecting: Not connected");
|
||||
return false;
|
||||
}
|
||||
DEBUG_WM("Disconnecting");
|
||||
@@ -1572,9 +1578,9 @@ bool WiFiManager::erase(bool opt){
|
||||
DEBUG_WM("Erasing NVS");
|
||||
int err;
|
||||
err=nvs_flash_init();
|
||||
DEBUG_WM("nvs_flash_init: ",err ? (String)err : "Success");
|
||||
DEBUG_WM(DEBUG_VERBOSE,"nvs_flash_init: ",err ? (String)err : "Success");
|
||||
err=nvs_flash_erase();
|
||||
DEBUG_WM("nvs_flash_erase: ", err ? (String)err : "Success");
|
||||
DEBUG_WM(DEBUG_VERBOSE,"nvs_flash_erase: ", err ? (String)err : "Success");
|
||||
return err;
|
||||
}
|
||||
#endif
|
||||
@@ -1875,15 +1881,28 @@ bool WiFiManager::getWiFiIsSaved(){
|
||||
|
||||
// HELPERS
|
||||
|
||||
// DEBUG
|
||||
template <typename Generic>
|
||||
void WiFiManager::DEBUG_WM(Generic text) {
|
||||
DEBUG_WM(text,"");
|
||||
DEBUG_WM(DEBUG_NOTIFY,text,"");
|
||||
}
|
||||
|
||||
template <typename Generic>
|
||||
void WiFiManager::DEBUG_WM(wm_debuglevel_t level,Generic text) {
|
||||
if(_debugLevel >= level) DEBUG_WM(text,"");
|
||||
}
|
||||
|
||||
template <typename Generic, typename Genericb>
|
||||
void WiFiManager::DEBUG_WM(Generic text,Genericb textb) {
|
||||
DEBUG_WM(DEBUG_NOTIFY,text,textb);
|
||||
}
|
||||
|
||||
template <typename Generic, typename Genericb>
|
||||
void WiFiManager::DEBUG_WM(wm_debuglevel_t level,Generic text,Genericb textb) {
|
||||
if(_debugLevel < level) return;
|
||||
|
||||
if (_debug) {
|
||||
if(_debugLevel > 2){
|
||||
if(_debugLevel > 3){
|
||||
_debugPort.print("MEM: ");
|
||||
_debugPort.println((String)ESP.getFreeHeap());
|
||||
}
|
||||
@@ -1897,6 +1916,7 @@ void WiFiManager::DEBUG_WM(Generic text,Genericb textb) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* [debugSoftAPConfig description]
|
||||
* @access public
|
||||
@@ -1939,7 +1959,7 @@ void WiFiManager::debugPlatformInfo(){
|
||||
DEBUG_WM(F("getFreeHeap(): "),(String)ESP.getFreeHeap());
|
||||
#elif defined(ESP32)
|
||||
size_t freeHeap = heap_caps_get_free_size(MALLOC_CAP_8BIT);
|
||||
DEBUG_WM("Free heap: ", freeHeap);
|
||||
DEBUG_WM("Free heap: ", freeHeap);
|
||||
DEBUG_WM("ESP-IDF version: ", esp_get_idf_version());
|
||||
#endif
|
||||
}
|
||||
@@ -1987,7 +2007,7 @@ boolean WiFiManager::validApPassword(){
|
||||
_apPassword = "";
|
||||
return false; // @todo FATAL or fallback to empty ?
|
||||
}
|
||||
DEBUG_WM(F("AccessPoint set password is VALID"));
|
||||
DEBUG_WM(DEBUG_VERBOSE,F("AccessPoint set password is VALID"));
|
||||
DEBUG_WM(_apPassword);
|
||||
}
|
||||
return true;
|
||||
@@ -2035,14 +2055,14 @@ bool WiFiManager::WiFi_Disconnect() {
|
||||
#ifdef ESP8266
|
||||
if((WiFi.getMode() & WIFI_STA) != 0) {
|
||||
bool ret;
|
||||
DEBUG_WM(F("wifi station disconnect"));
|
||||
DEBUG_WM(DEBUG_DEV,F("wifi station disconnect"));
|
||||
ETS_UART_INTR_DISABLE(); // @todo probably not needed
|
||||
ret = wifi_station_disconnect();
|
||||
ETS_UART_INTR_ENABLE();
|
||||
return ret;
|
||||
}
|
||||
#elif defined(ESP32)
|
||||
DEBUG_WM(F("wifi station disconnect"));
|
||||
DEBUG_WM(DEBUG_DEV,F("wifi station disconnect"));
|
||||
// @todo why does disconnect call these, might be needed
|
||||
// WiFi.getMode(); // @todo wifiLowLevelInit(), probably not needed, for save config only
|
||||
// esp_wifi_start(); // @todo can only disconnect if enabled perhaps, prevent failure, or correct for previous call ?
|
||||
@@ -2062,7 +2082,7 @@ bool WiFiManager::WiFi_enableSTA(bool enable,bool persistent) {
|
||||
|
||||
if((isEnabled != enable) || persistent) {
|
||||
if(enable) {
|
||||
if(persistent) DEBUG_WM(F("enableSTA PERSISTENT ON"));
|
||||
if(persistent) DEBUG_WM(DEBUG_DEV,F("enableSTA PERSISTENT ON"));
|
||||
return WiFi_Mode(newMode,persistent);
|
||||
} else {
|
||||
return WiFi_Mode(newMode,persistent);
|
||||
@@ -2145,7 +2165,7 @@ void WiFiManager::WiFi_autoReconnect(){
|
||||
WiFi.setAutoReconnect(_wifiAutoReconnect);
|
||||
#elif defined(ESP32)
|
||||
if(_wifiAutoReconnect){
|
||||
DEBUG_WM("ESP32 event handler enabled");
|
||||
DEBUG_WM(DEBUG_VERBOSE,"ESP32 event handler enabled");
|
||||
WiFi.onEvent(WiFiEvent);
|
||||
}
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user