Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions main/User_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -707,4 +707,8 @@ void storeSignalValue(uint64_t);
# define QueueSize 18
#endif

#ifndef EXPIRE_AFTER
# define EXPIRE_AFTER "0"
#endif

#endif
2 changes: 1 addition & 1 deletion main/config_WebContent.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ const char config_logging_body[] = body_header
#endif
"</select></p><br><button name='save' type='submit' class='button bgrn'>Save</button></form></fieldset>" body_footer_config_menu;

const char config_webui_body[] = body_header "<fieldset class=\"set1\"><legend><span><b>Configure WebUI</b></span></legend><form method='get' action='wu'><p><b>Display Metric</b><br><input id='dm' type='checkbox' %s></p><p><b>Secure WebUI</b><br><input id='sw' type='checkbox' %s></p><br><button name='save' type='submit' class='button bgrn'>Save</button></form></fieldset>" body_footer_config_menu;
const char config_webui_body[] = body_header "<fieldset class=\"set1\"><legend><span><b>Configure WebUI</b></span></legend><form method='get' action='wu'><p><b>Display Metric</b><br><input id='dm' type='checkbox' %s></p><p><b>Secure WebUI</b><br><input id='sw' type='checkbox' %s></p><p><b>Expire After</b><br><input id='ea' name='ea' placeholder=" EXPIRE_AFTER " value='%u'></p><br><button name='save' type='submit' class='button bgrn'>Save</button></form></fieldset>" body_footer_config_menu;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add the unit used after "Expire After" like "Expire After (s)"


const char config_rf_body[] = body_header
"<fieldset class=\"set1\">"
Expand Down
7 changes: 6 additions & 1 deletion main/mqttDiscovery.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@

#include "User_config.h"

uint16_t expireAfter = String(EXPIRE_AFTER).toInt();

#ifdef ZmqttDiscovery
# include "TheengsCommon.h"

Expand Down Expand Up @@ -571,8 +573,11 @@ void createDiscovery(const char* sensor_type,
sensor["pl_avail"] = payload_available; // payload_on
if (payload_not_available[0])
sensor["pl_not_avail"] = payload_not_available; //payload_off
if (state_class && state_class[0])
if (state_class && state_class[0]) {
sensor["stat_cla"] = state_class; //add the state class on the sensors ( https://developers.home-assistant.io/docs/core/entity/sensor/#available-state-classes )
if (expireAfter > 0 && strcmp(state_class, "measurement") == 0)
sensor["exp_aft"] = expireAfter; // handle stale sensors
}
if (state_on != nullptr)
if (strcmp(state_on, "true") == 0) {
sensor["stat_on"] = true;
Expand Down
16 changes: 14 additions & 2 deletions main/webUI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ const char* www_username = WEBUI_LOGIN;
String authFailResponse = "Authentication Failed";
bool webUISecure = WEBUI_AUTH;
boolean displayMetric = DISPLAY_METRIC;
extern uint16_t expireAfter;

/*********************************************************************************************\
* ESP32 AutoMutex
Expand Down Expand Up @@ -502,9 +503,10 @@ void handleCN() {

/**
* @brief /WU - Configuration Page
* T: handleWU: uri: /wu, args: 3, method: 1
* T: handleWU: uri: /wu, args: 4, method: 1
* T: handleWU Arg: 0, dm=on - displayMetric
* T: handleWU Arg: 1, sw=on - webUISecure
* T: handleWU Arg: 2, ea=0 - expireAfter
* T: handleWU Arg: 2, save=
*/
void handleWU() {
Expand All @@ -526,6 +528,11 @@ void handleWU() {
}
webUISecure = server.hasArg("sw");

if (server.hasArg("ea") && expireAfter != server.arg("ea").toInt()) {
expireAfter = server.arg("ea").toInt();
update = true;
}

if (server.hasArg("save") && update) {
WebUIConfig_save();
}
Expand All @@ -541,7 +548,7 @@ void handleWU() {
response += String(script);
response += String(style);
int logLevel = Log.getLevel();
snprintf(buffer, WEB_TEMPLATE_BUFFER_MAX_SIZE, config_webui_body, jsonChar, gateway_name, (displayMetric ? "checked" : ""), (webUISecure ? "checked" : ""));
snprintf(buffer, WEB_TEMPLATE_BUFFER_MAX_SIZE, config_webui_body, jsonChar, gateway_name, (displayMetric ? "checked" : ""), (webUISecure ? "checked" : ""), expireAfter);
response += String(buffer);
snprintf(buffer, WEB_TEMPLATE_BUFFER_MAX_SIZE, footer, OMG_VERSION);
response += String(buffer);
Expand Down Expand Up @@ -1789,6 +1796,7 @@ void WebUISetup() {

THEENGS_LOG_TRACE(F("[WebUI] displayMetric %T" CR), displayMetric);
THEENGS_LOG_TRACE(F("[WebUI] WebUI Secure %T" CR), webUISecure);
THEENGS_LOG_TRACE(F("[WebUI] Expire After %u" CR), expireAfter);
THEENGS_LOG_NOTICE(F("OpenMQTTGateway URL: http://%s/" CR), WiFi.localIP().toString().c_str());
displayPrint("URL: http://", (char*)WiFi.localIP().toString().c_str());
THEENGS_LOG_NOTICE(F("webUI setup done" CR));
Expand Down Expand Up @@ -1864,6 +1872,7 @@ String stateWebUIStatus() {
JsonObject WebUIdata = WebUIdataBuffer.to<JsonObject>();
WebUIdata["displayMetric"] = (bool)displayMetric;
WebUIdata["webUISecure"] = (bool)webUISecure;
WebUIdata["expireAfter"] = expireAfter;
WebUIdata["displayQueue"] = uxQueueMessagesWaiting(webUIQueue);

String output;
Expand All @@ -1880,6 +1889,7 @@ bool WebUIConfig_save() {
JsonObject jo = jsonBuffer.to<JsonObject>();
jo["displayMetric"] = (bool)displayMetric;
jo["webUISecure"] = (bool)webUISecure;
jo["expireAfter"] = expireAfter;
// Save config into NVS (non-volatile storage)
String conf = "";
serializeJson(jsonBuffer, conf);
Expand All @@ -1893,6 +1903,7 @@ bool WebUIConfig_save() {
void WebUIConfig_init() {
displayMetric = DISPLAY_METRIC;
webUISecure = WEBUI_AUTH;
expireAfter = String(EXPIRE_AFTER).toInt();
THEENGS_LOG_NOTICE(F("WebUI config initialised" CR));
}

Expand All @@ -1913,6 +1924,7 @@ bool WebUIConfig_load() {
JsonObject jo = jsonBuffer.as<JsonObject>();
displayMetric = jo["displayMetric"].as<bool>();
webUISecure = jo["webUISecure"].as<bool>();
expireAfter = jo["expireAfter"].as<uint16_t>();
return true;
} else {
preferences.end();
Expand Down