From aa721abe77a9870535be25466e02d04a76c8be45 Mon Sep 17 00:00:00 2001 From: Paul Date: Sun, 12 Jan 2020 00:27:14 +0100 Subject: [PATCH] publish_time changes - #287 --- CHANGELOG.md | 3 +-- src/MyESP.cpp | 14 +++++++------- src/MyESP.h | 2 +- src/custom.htm | 2 +- src/custom.js | 2 +- src/ems-esp.cpp | 32 +++++++++++++------------------- tools/wsemulator/wserver.js | 2 +- 7 files changed, 25 insertions(+), 32 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9e000000a..df6f20278 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,8 +17,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - set boiler warm water temp on Junkers/Bosch HT3 ### Changed - -- improved MQTT publishing to stop flooding +- improved MQTT publishing to stop flooding. `publish_time` must be at least 1 (second) ### Removed - `autodetect scan` diff --git a/src/MyESP.cpp b/src/MyESP.cpp index f0b6b79eb..8ce0e816d 100644 --- a/src/MyESP.cpp +++ b/src/MyESP.cpp @@ -1474,13 +1474,13 @@ void MyESP::_heartbeatCheck(bool force) { StaticJsonDocument doc; JsonObject rootHeartbeat = doc.to(); - rootHeartbeat["version"] = _app_version; - rootHeartbeat["IP"] = WiFi.localIP().toString(); - rootHeartbeat["rssid"] = getWifiQuality(); - rootHeartbeat["load"] = getSystemLoadAverage(); - rootHeartbeat["uptime"] = _getUptime(); - rootHeartbeat["freemem"] = mem_available; - rootHeartbeat["MQTTdisconnects"] = _getSystemDropoutCounter(); + //rootHeartbeat["version"] = _app_version; + //rootHeartbeat["IP"] = WiFi.localIP().toString(); + rootHeartbeat["rssid"] = getWifiQuality(); + rootHeartbeat["load"] = getSystemLoadAverage(); + rootHeartbeat["uptime"] = _getUptime(); + rootHeartbeat["freemem"] = mem_available; + //rootHeartbeat["MQTTdisconnects"] = _getSystemDropoutCounter(); char data[300] = {0}; serializeJson(doc, data, sizeof(data)); diff --git a/src/MyESP.h b/src/MyESP.h index b79bd64c6..fb6a98570 100644 --- a/src/MyESP.h +++ b/src/MyESP.h @@ -9,7 +9,7 @@ #ifndef MyESP_h #define MyESP_h -#define MYESP_VERSION "1.2.22" +#define MYESP_VERSION "1.2.23" #include #include diff --git a/src/custom.htm b/src/custom.htm index ad1e4d745..931ac7948 100644 --- a/src/custom.htm +++ b/src/custom.htm @@ -114,7 +114,7 @@
+ data-content="How often to send the MQTT topics in seconds. Must be at least 1"> diff --git a/src/custom.js b/src/custom.js index 5d8a16fd7..12468ee6d 100644 --- a/src/custom.js +++ b/src/custom.js @@ -8,7 +8,7 @@ var custom_config = { "listen_mode": false, "shower_timer": false, "shower_alert": false, - "publish_time": 0, + "publish_time": 10, "tx_mode": 1 } }; diff --git a/src/ems-esp.cpp b/src/ems-esp.cpp index 747845148..d4fa344b4 100644 --- a/src/ems-esp.cpp +++ b/src/ems-esp.cpp @@ -98,7 +98,7 @@ static const command_t project_cmds[] PROGMEM = { {true, "listen_mode ", "when set to on all automatic Tx are disabled"}, {true, "shower_timer ", "send MQTT notification on all shower durations"}, {true, "shower_alert ", "stop hot water to send 3 cold burst warnings after max shower time is exceeded"}, - {true, "publish_time ", "set frequency for publishing data to MQTT (0=automatic)"}, + {true, "publish_time ", "set frequency for publishing data to MQTT"}, {true, "tx_mode ", "changes Tx logic. 1=EMS generic, 2=EMS+, 3=HT3"}, {true, "master_thermostat [product id]", "set default thermostat to use. Omit [product id] to show options."}, @@ -494,12 +494,11 @@ void showInfo() { // Dallas external temp sensors if (EMSESP_Settings.dallas_sensors) { myDebug_P(PSTR("")); // newline - char buffer[128] = {0}; - char valuestr[8] = {0}; // for formatting temp - float sensorValue; + char buffer[128] = {0}; + char valuestr[8] = {0}; // for formatting temp myDebug_P(PSTR("%sExternal temperature sensors:%s"), COLOR_BOLD_ON, COLOR_BOLD_OFF); for (uint8_t i = 0; i < EMSESP_Settings.dallas_sensors; i++) { - sensorValue = ds18.getValue(i); + float sensorValue = ds18.getValue(i); if (sensorValue != DS18_DISCONNECTED) { myDebug_P(PSTR(" Sensor #%d %s: %s C"), i + 1, ds18.getDeviceString(buffer, i), _float_to_char(valuestr, sensorValue)); } @@ -1090,8 +1089,13 @@ bool SetListCallback(MYESP_FSACTION_t action, uint8_t wc, const char * setting, // publish_time if ((strcmp(setting, "publish_time") == 0) && (wc == 2)) { - EMSESP_Settings.publish_time = atoi(value); - ok = true; + int16_t val = atoi(value); + if (val > 0) { + EMSESP_Settings.publish_time = atoi(value); + ok = true; + } else { + myDebug_P(PSTR("Error. time must be at least 1 second")); + } } // tx_mode @@ -1140,12 +1144,7 @@ bool SetListCallback(MYESP_FSACTION_t action, uint8_t wc, const char * setting, myDebug_P(PSTR(" listen_mode=%s"), EMSESP_Settings.listen_mode ? "on" : "off"); myDebug_P(PSTR(" shower_timer=%s"), EMSESP_Settings.shower_timer ? "on" : "off"); myDebug_P(PSTR(" shower_alert=%s"), EMSESP_Settings.shower_alert ? "on" : "off"); - - if (EMSESP_Settings.publish_time) { - myDebug_P(PSTR(" publish_time=%d"), EMSESP_Settings.publish_time); - } else { - myDebug_P(PSTR(" publish_time=0 (always publish on data received)"), EMSESP_Settings.publish_time); - } + myDebug_P(PSTR(" publish_time=%d"), EMSESP_Settings.publish_time); if (EMSESP_Settings.master_thermostat) { myDebug_P(PSTR(" master_thermostat=%d"), EMSESP_Settings.master_thermostat); @@ -1953,7 +1952,7 @@ void setup() { regularUpdatesTimer.attach(REGULARUPDATES_TIME, do_regularUpdates); // regular reads from the EMS } - // set timers for MQTT publish, only if publish_time is not 0 (automatic mode) + // set timers for MQTT publish if (EMSESP_Settings.publish_time) { publishValuesTimer.attach(EMSESP_Settings.publish_time, do_publishValues); // post MQTT EMS values } @@ -1984,11 +1983,6 @@ void loop() { ds18.loop(); } - // publish EMS data to MQTT, only if in automatic mode (publish_time=0) otherwise it'll use the timer - if (EMSESP_Settings.publish_time == 0) { - publishEMSValues(false); - } - // if we have an EMS connect go and fetch some data and MQTT publish it if (_need_first_publish) { publishEMSValues(false); diff --git a/tools/wsemulator/wserver.js b/tools/wsemulator/wserver.js index 8f5353f82..2f5f461e2 100644 --- a/tools/wsemulator/wserver.js +++ b/tools/wsemulator/wserver.js @@ -97,7 +97,7 @@ var custom_configfile = { "listen_mode": false, "shower_timer": true, "shower_alert": false, - "publish_time": 0, + "publish_time": 10, "tx_mode": 1 } };