disable wifimanager portal if connected via LAN
This commit is contained in:
@@ -3,11 +3,12 @@
|
|||||||
#include "Version.h"
|
#include "Version.h"
|
||||||
#include "hardware/WifiEthServer.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),
|
: _server(ethServer),
|
||||||
_nuki(nuki),
|
_nuki(nuki),
|
||||||
_network(network),
|
_network(network),
|
||||||
_preferences(preferences)
|
_preferences(preferences),
|
||||||
|
_allowRestartToPortal(allowRestartToPortal)
|
||||||
{
|
{
|
||||||
String str = _preferences->getString(preference_cred_user);
|
String str = _preferences->getString(preference_cred_user);
|
||||||
|
|
||||||
@@ -54,11 +55,14 @@ void WebCfgServer::initialize()
|
|||||||
if (_hasCredentials && !_server.authenticate(_credUser, _credPassword)) {
|
if (_hasCredentials && !_server.authenticate(_credUser, _credPassword)) {
|
||||||
return _server.requestAuthentication();
|
return _server.requestAuthentication();
|
||||||
}
|
}
|
||||||
String response = "";
|
if(_allowRestartToPortal)
|
||||||
buildConfirmHtml(response, "Restarting. Connect to ESP access point to reconfigure WiFi.", 0);
|
{
|
||||||
_server.send(200, "text/html", response);
|
String response = "";
|
||||||
waitAndProcess(true, 2000);
|
buildConfirmHtml(response, "Restarting. Connect to ESP access point to reconfigure WiFi.", 0);
|
||||||
_network->restartAndConfigureWifi();
|
_server.send(200, "text/html", response);
|
||||||
|
waitAndProcess(true, 2000);
|
||||||
|
_network->restartAndConfigureWifi();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
_server.on("/method=get", [&]() {
|
_server.on("/method=get", [&]() {
|
||||||
if (_hasCredentials && !_server.authenticate(_credUser, _credPassword)) {
|
if (_hasCredentials && !_server.authenticate(_credUser, _credPassword)) {
|
||||||
@@ -263,9 +267,12 @@ void WebCfgServer::buildHtml(String& response)
|
|||||||
response.concat("<button type=\"submit\">Edit</button>");
|
response.concat("<button type=\"submit\">Edit</button>");
|
||||||
response.concat("</form>");
|
response.concat("</form>");
|
||||||
|
|
||||||
response.concat("<br><br><h3>WiFi</h3>");
|
if(_allowRestartToPortal)
|
||||||
response.concat("<form method=\"get\" action=\"/wifi\">");
|
{
|
||||||
response.concat("<button type=\"submit\">Restart and configure wifi</button>");
|
response.concat("<br><br><h3>WiFi</h3>");
|
||||||
|
response.concat("<form method=\"get\" action=\"/wifi\">");
|
||||||
|
response.concat("<button type=\"submit\">Restart and configure wifi</button>");
|
||||||
|
}
|
||||||
response.concat("</form>");
|
response.concat("</form>");
|
||||||
|
|
||||||
response.concat("</BODY>\n");
|
response.concat("</BODY>\n");
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ enum class TokenType
|
|||||||
class WebCfgServer
|
class WebCfgServer
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
WebCfgServer(NukiWrapper* nuki, Network* network, EthServer* ethServer, Preferences* preferences);
|
WebCfgServer(NukiWrapper* nuki, Network* network, EthServer* ethServer, Preferences* preferences, bool allowRestartToPortal);
|
||||||
~WebCfgServer() = default;
|
~WebCfgServer() = default;
|
||||||
|
|
||||||
void initialize();
|
void initialize();
|
||||||
@@ -50,6 +50,7 @@ private:
|
|||||||
bool _hasCredentials = false;
|
bool _hasCredentials = false;
|
||||||
char _credUser[20] = {0};
|
char _credUser[20] = {0};
|
||||||
char _credPassword[20] = {0};
|
char _credPassword[20] = {0};
|
||||||
|
bool _allowRestartToPortal = false;
|
||||||
|
|
||||||
bool _enabled = true;
|
bool _enabled = true;
|
||||||
};
|
};
|
||||||
2
main.cpp
2
main.cpp
@@ -122,7 +122,7 @@ void setup()
|
|||||||
initEthServer(networkDevice);
|
initEthServer(networkDevice);
|
||||||
|
|
||||||
nuki = new NukiWrapper("NukiHub", deviceId, network, preferences);
|
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();
|
webCfgServer->initialize();
|
||||||
nuki->initialize();
|
nuki->initialize();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user