From 2495b5c7822242645c0dd989952cab388eb0ffc1 Mon Sep 17 00:00:00 2001 From: technyon Date: Fri, 17 Jun 2022 22:49:39 +0200 Subject: [PATCH] move nuki config to seperate page --- WebCfgServer.cpp | 93 ++++++++++++++++++++++++++---------------------- WebCfgServer.h | 1 + 2 files changed, 52 insertions(+), 42 deletions(-) diff --git a/WebCfgServer.cpp b/WebCfgServer.cpp index 70e6bae..5faaae3 100644 --- a/WebCfgServer.cpp +++ b/WebCfgServer.cpp @@ -53,6 +53,14 @@ void WebCfgServer::initialize() buildMqttConfigHtml(response); _server.send(200, "text/html", response); }); + _server.on("/nukicfg", [&]() { + if (_hasCredentials && !_server.authenticate(_credUser, _credPassword)) { + return _server.requestAuthentication(); + } + String response = ""; + buildNukiConfigHtml(response); + _server.send(200, "text/html", response); + }); _server.on("/wifi", [&]() { if (_hasCredentials && !_server.authenticate(_credUser, _credPassword)) { return _server.requestAuthentication(); @@ -353,29 +361,10 @@ void WebCfgServer::buildHtml(String& response) response.concat(""); response.concat(""); - response.concat("
"); - - response.concat("

Configuration

"); - response.concat(""); - printCheckBox(response, "LOCKENA", "NUKI Lock enabled", _preferences->getBool(preference_lock_enabled)); - if(_preferences->getBool(preference_lock_enabled)) - { - printInputField(response, "MQTTPATH", "MQTT Lock Path", _preferences->getString(preference_mqtt_lock_path).c_str(), 180); - } - printCheckBox(response, "OPENA", "NUKI Opener enabled", _preferences->getBool(preference_opener_enabled)); - if(_preferences->getBool(preference_opener_enabled)) - { - printInputField(response, "MQTTOPPATH", "MQTT Opener Path", _preferences->getString(preference_mqtt_opener_path).c_str(), 180); - } - printInputField(response, "LSTINT", "Query interval lock state (seconds)", _preferences->getInt(preference_query_interval_lockstate), 10); - printInputField(response, "BATINT", "Query interval battery (seconds)", _preferences->getInt(preference_query_interval_battery), 10); - printCheckBox(response, "PUBAUTH", "Publish auth data (May reduce battery life)", _preferences->getBool(preference_publish_authdata)); - printInputField(response, "PRDTMO", "Presence detection timeout (seconds; -1 to disable)", _preferences->getInt(preference_presence_detection_timeout), 10); - response.concat("
"); - - response.concat("
"); - - response.concat("
"); + response.concat("

NUKI Configuration

"); + response.concat("
"); + response.concat(""); + response.concat("
"); response.concat("

Credentials

"); response.concat("
"); @@ -392,8 +381,8 @@ void WebCfgServer::buildHtml(String& response) response.concat("

WiFi

"); response.concat(""); response.concat(""); + response.concat("
"); } - response.concat(""); response.concat(""); } @@ -456,8 +445,7 @@ void WebCfgServer::buildCredHtml(String &response) printInputField(response, "CONFIRMTOKEN", message.c_str(), "", 10); response.concat("

"); } - - + response.concat(""); } void WebCfgServer::buildOtaHtml(String &response) @@ -477,7 +465,7 @@ void WebCfgServer::buildOtaHtml(String &response) response.concat(" }"); response.concat("});"); response.concat(""); - response.concat("\n\n"); + response.concat(""); } void WebCfgServer::buildMqttConfigHtml(String &response) @@ -498,7 +486,35 @@ void WebCfgServer::buildMqttConfigHtml(String &response) response.concat(""); response.concat("
"); response.concat(""); + response.concat(""); +} + +void WebCfgServer::buildNukiConfigHtml(String &response) +{ + buildHtmlHeader(response); + + response.concat("
"); + response.concat("

MQTT Configuration

"); + response.concat(""); + printCheckBox(response, "LOCKENA", "NUKI Lock enabled", _preferences->getBool(preference_lock_enabled)); + if(_preferences->getBool(preference_lock_enabled)) + { + printInputField(response, "MQTTPATH", "MQTT Lock Path", _preferences->getString(preference_mqtt_lock_path).c_str(), 180); + } + printCheckBox(response, "OPENA", "NUKI Opener enabled", _preferences->getBool(preference_opener_enabled)); + if(_preferences->getBool(preference_opener_enabled)) + { + printInputField(response, "MQTTOPPATH", "MQTT Opener Path", _preferences->getString(preference_mqtt_opener_path).c_str(), 180); + } + printInputField(response, "LSTINT", "Query interval lock state (seconds)", _preferences->getInt(preference_query_interval_lockstate), 10); + printInputField(response, "BATINT", "Query interval battery (seconds)", _preferences->getInt(preference_query_interval_battery), 10); + printCheckBox(response, "PUBAUTH", "Publish auth data (May reduce battery life)", _preferences->getBool(preference_publish_authdata)); + printInputField(response, "PRDTMO", "Presence detection timeout (seconds; -1 to disable)", _preferences->getInt(preference_presence_detection_timeout), 10); + response.concat("
"); + response.concat("
"); + response.concat("
"); + response.concat(""); } void WebCfgServer::buildConfirmHtml(String &response, const String &message, uint32_t redirectDelay) @@ -515,11 +531,9 @@ void WebCfgServer::buildConfirmHtml(String &response, const String &message, uin response.concat("\n"); response.concat(message); - response.concat("\n"); - response.concat("\n"); + response.concat(""); } - void WebCfgServer::buildConfigureWifiHtml(String &response) { buildHtmlHeader(response); @@ -589,11 +603,9 @@ void WebCfgServer::printInputField(String& response, itoa(maxLength, maxLengthStr, 10); - response.concat(""); - response.concat(""); + response.concat(""); response.concat(description); - response.concat(""); - response.concat(""); + response.concat(""); response.concat(""); - response.concat(""); - response.concat(""); + response.concat("\""); } void WebCfgServer::printInputField(String& response, @@ -646,11 +657,9 @@ void WebCfgServer::printTextarea(String& response, itoa(maxLength, maxLengthStr, 10); - response.concat(""); - response.concat(""); + response.concat(""); response.concat(description); - response.concat(""); - response.concat(""); + response.concat(""); response.concat(" "); - response.concat(""); - response.concat(""); + response.concat(""); } void WebCfgServer::printParameter(String& response, const char *description, const char *value) @@ -724,3 +732,4 @@ void WebCfgServer::handleOtaUpload() } } + diff --git a/WebCfgServer.h b/WebCfgServer.h index b9bdd59..1216954 100644 --- a/WebCfgServer.h +++ b/WebCfgServer.h @@ -35,6 +35,7 @@ private: void buildCredHtml(String& response); void buildOtaHtml(String& response); void buildMqttConfigHtml(String& response); + void buildNukiConfigHtml(String& response); void buildConfirmHtml(String& response, const String &message, uint32_t redirectDelay = 5); void buildConfigureWifiHtml(String& response); void processUnpair(bool opener);