From 3dc88cddea4cca6c5366e274d2345533e9d3a0b1 Mon Sep 17 00:00:00 2001 From: technyon Date: Fri, 29 Apr 2022 22:04:51 +0200 Subject: [PATCH] disable wifimanager portal if connected via LAN --- WebCfgServer.cpp | 27 +++++++++++++++++---------- WebCfgServer.h | 3 ++- main.cpp | 2 +- 3 files changed, 20 insertions(+), 12 deletions(-) diff --git a/WebCfgServer.cpp b/WebCfgServer.cpp index d8448d1..ed6483e 100644 --- a/WebCfgServer.cpp +++ b/WebCfgServer.cpp @@ -3,11 +3,12 @@ #include "Version.h" #include "hardware/WifiEthServer.h" -WebCfgServer::WebCfgServer(NukiWrapper* nuki, Network* network, EthServer* ethServer, Preferences* preferences) +WebCfgServer::WebCfgServer(NukiWrapper* nuki, Network* network, EthServer* ethServer, Preferences* preferences, bool allowRestartToPortal) : _server(ethServer), _nuki(nuki), _network(network), - _preferences(preferences) + _preferences(preferences), + _allowRestartToPortal(allowRestartToPortal) { String str = _preferences->getString(preference_cred_user); @@ -54,11 +55,14 @@ void WebCfgServer::initialize() if (_hasCredentials && !_server.authenticate(_credUser, _credPassword)) { return _server.requestAuthentication(); } - String response = ""; - buildConfirmHtml(response, "Restarting. Connect to ESP access point to reconfigure WiFi.", 0); - _server.send(200, "text/html", response); - waitAndProcess(true, 2000); - _network->restartAndConfigureWifi(); + if(_allowRestartToPortal) + { + String response = ""; + buildConfirmHtml(response, "Restarting. Connect to ESP access point to reconfigure WiFi.", 0); + _server.send(200, "text/html", response); + waitAndProcess(true, 2000); + _network->restartAndConfigureWifi(); + } }); _server.on("/method=get", [&]() { if (_hasCredentials && !_server.authenticate(_credUser, _credPassword)) { @@ -263,9 +267,12 @@ void WebCfgServer::buildHtml(String& response) response.concat(""); response.concat(""); - response.concat("

WiFi

"); - response.concat("
"); - response.concat(""); + if(_allowRestartToPortal) + { + response.concat("

WiFi

"); + response.concat(""); + response.concat(""); + } response.concat("
"); response.concat("\n"); diff --git a/WebCfgServer.h b/WebCfgServer.h index bc00da0..dd477a6 100644 --- a/WebCfgServer.h +++ b/WebCfgServer.h @@ -20,7 +20,7 @@ enum class TokenType class WebCfgServer { public: - WebCfgServer(NukiWrapper* nuki, Network* network, EthServer* ethServer, Preferences* preferences); + WebCfgServer(NukiWrapper* nuki, Network* network, EthServer* ethServer, Preferences* preferences, bool allowRestartToPortal); ~WebCfgServer() = default; void initialize(); @@ -50,6 +50,7 @@ private: bool _hasCredentials = false; char _credUser[20] = {0}; char _credPassword[20] = {0}; + bool _allowRestartToPortal = false; bool _enabled = true; }; \ No newline at end of file diff --git a/main.cpp b/main.cpp index 2aa491c..202626e 100644 --- a/main.cpp +++ b/main.cpp @@ -122,7 +122,7 @@ void setup() initEthServer(networkDevice); nuki = new NukiWrapper("NukiHub", deviceId, network, preferences); - webCfgServer = new WebCfgServer(nuki, network, ethServer, preferences); + webCfgServer = new WebCfgServer(nuki, network, ethServer, preferences, networkDevice == NetworkDeviceType::WiFi); webCfgServer->initialize(); nuki->initialize();