From b660e1c1a2b87fcdc4d401f15e2d29ec90cf493e Mon Sep 17 00:00:00 2001 From: technyon Date: Sun, 3 Apr 2022 12:16:23 +0200 Subject: [PATCH] add methods to generate html --- WebCfgServer.cpp | 55 +++++++++++++++++++++++++++++++----------------- WebCfgServer.h | 2 ++ 2 files changed, 38 insertions(+), 19 deletions(-) diff --git a/WebCfgServer.cpp b/WebCfgServer.cpp index 8ebe0d8..75e2546 100644 --- a/WebCfgServer.cpp +++ b/WebCfgServer.cpp @@ -131,25 +131,11 @@ void WebCfgServer::serveHtml(WiFiClient &client) client.println("
"); - client.print("MQTT Broker: getString(preference_mqtt_broker)); - client.println("\" NAME=\"MQTTSERVER\" SIZE=\"25\" MAXLENGTH=\"40\">
"); - - client.print("MQTT Broker port: getInt(preference_mqtt_broker_port)); - client.println("\" NAME=\"MQTTPORT\" SIZE=\"25\" MAXLENGTH=\"40\">
"); - - client.print("MQTT Path: getString(preference_mqtt_path)); - client.println("\" NAME=\"MQTTPATH\" SIZE=\"25\" MAXLENGTH=\"40\">
"); - - client.print("Query interval lock state (seconds): getInt(preference_query_interval_lockstate)); - client.println("\" NAME=\"LSTINT\" SIZE=\"25\" MAXLENGTH=\"16\">
"); - - client.print("Query interval battery (seconds): getInt(preference_query_interval_battery)); - client.println("\" NAME=\"BATINT\" SIZE=\"25\" MAXLENGTH=\"16\">
"); + printInputField(client, "MQTTSERVER", "MQTT Broker:", _preferences->getString(preference_mqtt_broker).c_str(), 100); + printInputField(client, "MQTTPORT", "MQTT Broker port:", _preferences->getInt(preference_mqtt_broker_port), 5); + printInputField(client, "MQTTPATH", "MQTT Path:", _preferences->getString(preference_mqtt_path).c_str(), 180); + printInputField(client, "LSTINT", "Query interval lock state (seconds):", _preferences->getInt(preference_query_interval_lockstate), 10); + printInputField(client, "BATINT", "Query interval battery (seconds):", _preferences->getInt(preference_query_interval_battery), 10); client.println("
"); @@ -186,3 +172,34 @@ TokenType WebCfgServer::getParameterType(char *&token) return TokenType::None; } + +void WebCfgServer::printInputField(WiFiClient &client, + const char *token, + const char *description, + const char *value, + size_t maxLength) +{ + char maxLengthStr[20]; + + itoa(maxLength, maxLengthStr, 10); + + client.print(description); + client.print("
"); +} + +void WebCfgServer::printInputField(WiFiClient &client, + const char *token, + const char *description, + const int value, + size_t maxLength) +{ + char valueStr[20]; + itoa(value, valueStr, 10); + printInputField(client, token, description, valueStr, maxLength); +} \ No newline at end of file diff --git a/WebCfgServer.h b/WebCfgServer.h index 7e81ef5..321eb70 100644 --- a/WebCfgServer.h +++ b/WebCfgServer.h @@ -27,6 +27,8 @@ public: private: void serveHtml(WiFiClient& client); + void printInputField(WiFiClient& client, const char* token, const char* description, const char* value, size_t maxLength); + void printInputField(WiFiClient& client, const char* token, const char* description, const int value, size_t maxLength); TokenType getParameterType(char*& token);