diff --git a/lib/PsychicHttp/src/PsychicHttpsServer.h b/lib/PsychicHttp/src/PsychicHttpsServer.h index 51f8210..c60b25b 100644 --- a/lib/PsychicHttp/src/PsychicHttpsServer.h +++ b/lib/PsychicHttp/src/PsychicHttpsServer.h @@ -31,9 +31,8 @@ class PsychicHttpsServer : public PsychicHttpServer virtual esp_err_t _startServer() override final; virtual void stop() override final; }; - -#endif // PsychicHttpsServer_h - #else #warning ESP-IDF https server support not enabled. -#endif // CONFIG_ESP_HTTPS_SERVER_ENABLE \ No newline at end of file +#endif // CONFIG_ESP_HTTPS_SERVER_ENABLE + +#endif // PsychicHttpsServer_h \ No newline at end of file diff --git a/lib/WiFiManager/WiFiManager.cpp b/lib/WiFiManager/WiFiManager.cpp index 34c6868..aede273 100644 --- a/lib/WiFiManager/WiFiManager.cpp +++ b/lib/WiFiManager/WiFiManager.cpp @@ -627,6 +627,7 @@ boolean WiFiManager::configPortalHasTimeout(){ } void WiFiManager::setupHTTPServer(){ + server = new PsychicHttpServer; server->listen(_httpPort); /* Setup httpd callbacks, web pages: root, wifi config pages, SO captive portal detectors and not found. */ @@ -636,7 +637,7 @@ void WiFiManager::setupHTTPServer(){ { using namespace std::placeholders; server->on(String(FPSTR(R_root)).c_str(), (PsychicHttpRequestCallback)std::bind(&WiFiManager::handleRoot, this,_1)); - server->on(String(FPSTR(R_wifisave)).c_str(), (PsychicHttpRequestCallback)std::bind(&WiFiManager::handleWifiSave, this,_1)); + server->on(String(FPSTR(R_wifisave)).c_str(), HTTP_POST, (PsychicHttpRequestCallback)std::bind(&WiFiManager::handleWifiSave, this,_1)); server->on(String(FPSTR(R_info)).c_str(), (PsychicHttpRequestCallback)std::bind(&WiFiManager::handleInfo, this,_1)); server->on(String(FPSTR(R_param)).c_str(), (PsychicHttpRequestCallback)std::bind(&WiFiManager::handleParam, this,_1)); server->on(String(FPSTR(R_paramsave)).c_str(), (PsychicHttpRequestCallback)std::bind(&WiFiManager::handleParamSave, this,_1)); @@ -899,6 +900,7 @@ uint8_t WiFiManager::processConfigPortal(){ DEBUG_WM(F("Connect to new AP [SUCCESS]")); DEBUG_WM(F("Got IP Address:")); DEBUG_WM(WiFi.localIP()); + reboot(); } #endif @@ -981,7 +983,6 @@ bool WiFiManager::shutdownConfigPortal(){ #else server->stop(); #endif - server.reset(); dnsServer->stop(); // free heap ? dnsServer.reset(); @@ -1128,7 +1129,7 @@ bool WiFiManager::wifiConnectNew(String ssid, String pass,bool connect){ DEBUG_WM(F("find best RSSI: TRUE")); #endif if (!_numNetworks) - WiFi_scanNetworks(false, false); // scan in case this gets called before any scans + WiFi_scanNetworks(false, _enableCaptivePortal); // scan in case this gets called before any scans int n = _numNetworks; if (n == 0) { @@ -1217,7 +1218,7 @@ bool WiFiManager::wifiConnectDefault(){ DEBUG_WM(F("find best RSSI: TRUE")); #endif if (!_numNetworks) - WiFi_scanNetworks(false, false); // scan in case this gets called before any scans + WiFi_scanNetworks(false, _enableCaptivePortal); // scan in case this gets called before any scans int n = _numNetworks; if (n == 0) { @@ -1464,7 +1465,7 @@ esp_err_t WiFiManager::handleRoot(PsychicRequest *request) { reportStatus(page); page += FPSTR(HTTP_END); - if(_preloadwifiscan) WiFi_scanNetworks(_scancachetime,true); // preload wifiscan throttled, async + //if(_preloadwifiscan) WiFi_scanNetworks(_scancachetime,true); // preload wifiscan throttled, async // @todo buggy, captive portals make a query on every page load, causing this to run every time in addition to the real page load // I dont understand why, when you are already in the captive portal, I guess they want to know that its still up and not done or gone // if we can detect these and ignore them that would be great, since they come from the captive portal redirect maybe there is a refferer @@ -1486,7 +1487,7 @@ esp_err_t WiFiManager::handleWifi(PsychicRequest *request,bool scan = true) { #ifdef WM_DEBUG_LEVEL // DEBUG_WM(WM_DEBUG_DEV,"refresh flag:",request->hasArg(F("refresh"))); #endif - WiFi_scanNetworks(request->hasParam("refresh")); //wifiscan, force if arg refresh + WiFi_scanNetworks(request->hasParam("refresh"), true); //wifiscan, force if arg refresh page += getScanItemOut(); } String pitem = ""; @@ -1684,7 +1685,7 @@ void WiFiManager::resetScan(){ String WiFiManager::WiFiManager::getScanItemOut(){ String page; - if(!_numNetworks) WiFi_scanNetworks(); // scan in case this gets called before any scans + if(!_numNetworks) WiFi_scanNetworks(true, true); // scan in case this gets called before any scans int n = _numNetworks; if (n == 0) { @@ -1943,8 +1944,12 @@ esp_err_t WiFiManager::handleWifiSave(PsychicRequest *request) { handleRequest(); //SAVE/connect here - _ssid = request->getParam("s")->value(); - _pass = request->getParam("p")->value(); + if(request->hasParam("s")){ + _ssid = request->getParam("s")->value(); + } + if(request->hasParam("p")){ + _pass = request->getParam("p")->value(); + } if(_ssid == "" && _pass != ""){ _ssid = WiFi_SSID(true); // password change, placeholder ssid, @todo compare pass to old?, confirm ssid is clean @@ -1970,36 +1975,43 @@ esp_err_t WiFiManager::handleWifiSave(PsychicRequest *request) { #endif // set static ips from server args - if (request->getParam(S_ip)->value() != "") { - //_sta_static_ip.fromString(request->arg(FPSTR(S_ip)); - String ip = request->getParam(S_ip)->value(); - optionalIPFromString(&_sta_static_ip, ip.c_str()); - #ifdef WM_DEBUG_LEVEL - DEBUG_WM(WM_DEBUG_DEV,F("static ip:"),ip); - #endif + if(request->hasParam(S_ip)){ + if (request->getParam(S_ip)->value() != "") { + //_sta_static_ip.fromString(request->arg(FPSTR(S_ip)); + String ip = request->getParam(S_ip)->value(); + optionalIPFromString(&_sta_static_ip, ip.c_str()); + #ifdef WM_DEBUG_LEVEL + DEBUG_WM(WM_DEBUG_DEV,F("static ip:"),ip); + #endif + } } - if (request->getParam(S_gw)->value() != "") { - String gw = request->getParam(S_gw)->value(); - optionalIPFromString(&_sta_static_gw, gw.c_str()); - #ifdef WM_DEBUG_LEVEL - DEBUG_WM(WM_DEBUG_DEV,F("static gateway:"),gw); - #endif + if(request->hasParam(S_gw)){ + if (request->getParam(S_gw)->value() != "") { + String gw = request->getParam(S_gw)->value(); + optionalIPFromString(&_sta_static_gw, gw.c_str()); + #ifdef WM_DEBUG_LEVEL + DEBUG_WM(WM_DEBUG_DEV,F("static gateway:"),gw); + #endif + } } - if (request->getParam(S_sn)->value() != "") { - String sn = request->getParam(S_sn)->value(); - optionalIPFromString(&_sta_static_sn, sn.c_str()); - #ifdef WM_DEBUG_LEVEL - DEBUG_WM(WM_DEBUG_DEV,F("static netmask:"),sn); - #endif + if(request->hasParam(S_sn)){ + if (request->getParam(S_sn)->value() != "") { + String sn = request->getParam(S_sn)->value(); + optionalIPFromString(&_sta_static_sn, sn.c_str()); + #ifdef WM_DEBUG_LEVEL + DEBUG_WM(WM_DEBUG_DEV,F("static netmask:"),sn); + #endif + } } - if (request->getParam(S_dns)->value() != "") { - String dns = request->getParam(S_dns)->value(); - optionalIPFromString(&_sta_static_dns, dns.c_str()); - #ifdef WM_DEBUG_LEVEL - DEBUG_WM(WM_DEBUG_DEV,F("static DNS:"),dns); - #endif + if(request->hasParam(S_dns)){ + if (request->getParam(S_dns)->value() != "") { + String dns = request->getParam(S_dns)->value(); + optionalIPFromString(&_sta_static_dns, dns.c_str()); + #ifdef WM_DEBUG_LEVEL + DEBUG_WM(WM_DEBUG_DEV,F("static DNS:"),dns); + #endif + } } - if (_presavewificallback != NULL) { _presavewificallback(); // @CALLBACK } diff --git a/lib/WiFiManager/WiFiManager.h b/lib/WiFiManager/WiFiManager.h index 38f9bfb..c48ec7f 100644 --- a/lib/WiFiManager/WiFiManager.h +++ b/lib/WiFiManager/WiFiManager.h @@ -518,22 +518,7 @@ class WiFiManager std::unique_ptr dnsServer; - - #if defined(ESP32) && defined(WM_WEBSERVERSHIM) - #ifdef WM_ASYNCWEBSERVER - using WM_WebServer = PsychicHttpServer; - #else - using WM_WebServer = WebServer; - #endif - #else - #ifdef WM_ASYNCWEBSERVER - using WM_WebServer = AsyncWebServer; - #else - using WM_WebServer = ESP8266WebServer; - #endif - #endif - - std::unique_ptr server; + PsychicHttpServer* server; protected: // vars @@ -651,9 +636,9 @@ class WiFiManager // 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 + boolean _preloadwifiscan = true; // preload wifiscan if true unsigned int _scancachetime = 30000; // ms cache time for preload scans - boolean _asyncScan = false; // perform wifi network scan async + boolean _asyncScan = true; // perform wifi network scan async bool wifiConnectDefault(); protected: diff --git a/platformio.ini b/platformio.ini index 21d694f..a0f7376 100644 --- a/platformio.ini +++ b/platformio.ini @@ -131,6 +131,7 @@ build_flags = -DCONFIG_NIMBLE_CPP_LOG_LEVEL=0 -DCONFIG_BT_NIMBLE_LOG_LEVEL=0 -DDEBUG_NUKIHUB + -DWM_DEBUG_LEVEL=4 -DDEBUG_SENSE_NUKI -DDEBUG_NUKI_COMMAND -DDEBUG_NUKI_CONNECT @@ -152,6 +153,7 @@ build_flags = -DCONFIG_NIMBLE_CPP_LOG_LEVEL=0 -DCONFIG_BT_NIMBLE_LOG_LEVEL=0 -DDEBUG_NUKIHUB + -DWM_DEBUG_LEVEL=4 -DDEBUG_SENSE_NUKI -DDEBUG_NUKI_COMMAND -DDEBUG_NUKI_CONNECT @@ -173,6 +175,7 @@ build_flags = -DCONFIG_NIMBLE_CPP_LOG_LEVEL=0 -DCONFIG_BT_NIMBLE_LOG_LEVEL=0 -DDEBUG_NUKIHUB + -DWM_DEBUG_LEVEL=4 -DDEBUG_SENSE_NUKI -DDEBUG_NUKI_COMMAND -DDEBUG_NUKI_CONNECT @@ -195,6 +198,7 @@ build_flags = -DCONFIG_NIMBLE_CPP_LOG_LEVEL=0 -DCONFIG_BT_NIMBLE_LOG_LEVEL=0 -DDEBUG_NUKIHUB + -DWM_DEBUG_LEVEL=4 -DDEBUG_SENSE_NUKI -DDEBUG_NUKI_COMMAND -DDEBUG_NUKI_CONNECT @@ -216,6 +220,7 @@ build_flags = -DCONFIG_NIMBLE_CPP_LOG_LEVEL=0 -DCONFIG_BT_NIMBLE_LOG_LEVEL=0 -DDEBUG_NUKIHUB + -DWM_DEBUG_LEVEL=4 -DDEBUG_SENSE_NUKI -DDEBUG_NUKI_COMMAND -DDEBUG_NUKI_CONNECT @@ -237,6 +242,7 @@ build_flags = -DCONFIG_NIMBLE_CPP_LOG_LEVEL=0 -DCONFIG_BT_NIMBLE_LOG_LEVEL=0 -DDEBUG_NUKIHUB + -DWM_DEBUG_LEVEL=4 -DDEBUG_SENSE_NUKI -DDEBUG_NUKI_COMMAND -DDEBUG_NUKI_CONNECT diff --git a/src/Config.h b/src/Config.h index 70cfcf7..d3a61df 100644 --- a/src/Config.h +++ b/src/Config.h @@ -4,7 +4,7 @@ #define NUKI_HUB_VERSION "9.01" #define NUKI_HUB_BUILD "unknownbuildnr" -#define NUKI_HUB_DATE "2024-08-27" +#define NUKI_HUB_DATE "2024-08-28" #define GITHUB_LATEST_RELEASE_URL (char*)"https://github.com/technyon/nuki_hub/releases/latest" #define GITHUB_OTA_MANIFEST_URL (char*)"https://raw.githubusercontent.com/technyon/nuki_hub/binary/ota/manifest.json" diff --git a/src/WebCfgServer.cpp b/src/WebCfgServer.cpp index 86f62e3..90f40cf 100644 --- a/src/WebCfgServer.cpp +++ b/src/WebCfgServer.cpp @@ -164,7 +164,7 @@ void WebCfgServer::initialize() if(strlen(_credUser) > 0 && strlen(_credPassword) > 0) if(!request->authenticate(_credUser, _credPassword)) return request->requestAuthentication(BASIC_AUTH, "Nuki Hub", "You must log in."); return processFactoryReset(request); }); - _psychicServer->on("/info", HTTP_GET, [&](PsychicRequest *request){ + _psychicServer->on("/infopg", HTTP_GET, [&](PsychicRequest *request){ if(strlen(_credUser) > 0 && strlen(_credPassword) > 0) if(!request->authenticate(_credUser, _credPassword)) return request->requestAuthentication(BASIC_AUTH, "Nuki Hub", "You must log in."); return buildInfoHtml(request); }); @@ -2650,7 +2650,7 @@ esp_err_t WebCfgServer::buildHtml(PsychicRequest *request) printParameter(&response, "Nuki Opener PIN status", openerState.c_str(), "", "openerPin"); } } - printParameter(&response, "Firmware", NUKI_HUB_VERSION, "/info", "firmware"); + printParameter(&response, "Firmware", NUKI_HUB_VERSION, "/infopg", "firmware"); if(_preferences->getBool(preference_check_updates)) { printParameter(&response, "Latest Firmware", _preferences->getString(preference_latest_version).c_str(), "/ota", "ota"); @@ -3232,6 +3232,7 @@ esp_err_t WebCfgServer::buildConfigureWifiHtml(PsychicRequest *request) esp_err_t WebCfgServer::buildInfoHtml(PsychicRequest *request) { + Log->println("INFO HTML"); uint32_t aclPrefs[17]; _preferences->getBytes(preference_acl, &aclPrefs, sizeof(aclPrefs)); PsychicStreamResponse response(request, "text/plain"); diff --git a/src/main.cpp b/src/main.cpp index ee565d9..edefe53 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -422,8 +422,8 @@ void setup() psychicServer = new PsychicHttpServer; webCfgServer = new WebCfgServer(network, preferences, network->networkDeviceType() == NetworkDeviceType::WiFi, partitionType, psychicServer); webCfgServer->initialize(); - psychicServer->onNotFound([](PsychicRequest* request) { return request->redirect("/"); }); psychicServer->listen(80); + psychicServer->onNotFound([](PsychicRequest* request) { return request->redirect("/"); }); } #else Log->print(F("Nuki Hub version "));