From f759e2698831653083e3cad1d26e9378cb657da8 Mon Sep 17 00:00:00 2001 From: Marcus Date: Fri, 8 Jan 2021 21:36:05 +0100 Subject: [PATCH 1/6] remove backward compatible #define option; ITurned it into an undocumented option to suppress it --- tasmota/xdrv_49_pid.ino | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/tasmota/xdrv_49_pid.ino b/tasmota/xdrv_49_pid.ino index 37b8774a3..eda2b633f 100644 --- a/tasmota/xdrv_49_pid.ino +++ b/tasmota/xdrv_49_pid.ino @@ -119,11 +119,6 @@ #define PID_REPORT_MORE_SETTINGS // If defined, the SENSOR output will provide more extensive json // output in the PID section -// #define PID_BACKWARD_COMPATIBLE // Preserve the backward compatible reporting of PID power via - // `%topic%/PID {"power":"0.000"}` This is now available in - // `%topic$/SENSOR {..., "PID":{"PidPower":0.00}}` - // Don't use unless you know that you need it - * Help with using the PID algorithm and with loop tuning can be found at * http://blog.clanlaw.org.uk/2018/01/09/PID-tuning-with-node-red-contrib-pid.html * This is directed towards using the algorithm in the node-red node node-red-contrib-pid but the algorithm here is based on @@ -362,14 +357,14 @@ void PIDShowValues(void) { static void run_pid() { double power = pid.tick(pid_current_time_secs); -#ifdef PID_BACKWARD_COMPATIBLE +#ifdef PID_DONT_USE_PID_TOPIC // This part is left inside to regularly publish the PID Power via // `%topic%/PID {"power":"0.000"}` char str_buf[FLOATSZ]; dtostrfd(power, 3, str_buf); snprintf_P(TasmotaGlobal.mqtt_data, sizeof(TasmotaGlobal.mqtt_data), PSTR("{\"%s\":\"%s\"}"), "power", str_buf); MqttPublishPrefixTopic_P(TELE, "PID", false); -#endif // PID_BACKWARD_COMPATIBLE +#endif // PID_DONT_USE_PID_TOPIC #if defined PID_SHUTTER // send output as a position from 0-100 to defined shutter From aedfe35b017567e28d06fd724699450235d67790 Mon Sep 17 00:00:00 2001 From: Marcus Date: Fri, 8 Jan 2021 21:36:28 +0100 Subject: [PATCH 2/6] re-add code to modify timeprop values via mqtt --- tasmota/xdrv_48_timeprop.ino | 51 ++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/tasmota/xdrv_48_timeprop.ino b/tasmota/xdrv_48_timeprop.ino index 6e8537dbb..a457c8d94 100644 --- a/tasmota/xdrv_48_timeprop.ino +++ b/tasmota/xdrv_48_timeprop.ino @@ -82,6 +82,11 @@ # include "Timeprop.h" +#define D_CMND_TIMEPROP "timeprop_" +#define D_CMND_TIMEPROP_SETPOWER "setpower_" // add index no on end (0:8) and data is power 0:1 + +enum TimepropCommands { CMND_TIMEPROP_SETPOWER }; +const char kTimepropCommands[] PROGMEM = D_CMND_TIMEPROP_SETPOWER; static Timeprop timeprops[TIMEPROP_NUM_OUTPUTS]; static int relayNos[TIMEPROP_NUM_OUTPUTS] = {TIMEPROP_RELAYS}; @@ -143,7 +148,50 @@ void Timeprop_Xdrv_Power() { /* } XdrvMailbox; */ // To get here post with topic cmnd/timeprop_setpower_n where n is index into timeprops 0:7 +bool Timeprop_Command() +{ + char command [CMDSZ]; + bool serviced = true; + uint8_t ua_prefix_len = strlen(D_CMND_TIMEPROP); // to detect prefix of command + /* + snprintf_P(log_data, sizeof(log_data), "Command called: " + "index: %d data_len: %d payload: %d topic: %s data: %s\n", + XdrvMailbox.index, + XdrvMailbox.data_len, + XdrvMailbox.payload, + (XdrvMailbox.payload >= 0 ? XdrvMailbox.topic : ""), + (XdrvMailbox.data_len >= 0 ? XdrvMailbox.data : "")); + AddLog(LOG_LEVEL_INFO); + */ + if (0 == strncasecmp_P(XdrvMailbox.topic, PSTR(D_CMND_TIMEPROP), ua_prefix_len)) { + // command starts with timeprop_ + int command_code = GetCommandCode(command, sizeof(command), XdrvMailbox.topic + ua_prefix_len, kTimepropCommands); + if (CMND_TIMEPROP_SETPOWER == command_code) { + /* + snprintf_P(log_data, sizeof(log_data), "Timeprop command timeprop_setpower: " + "index: %d data_len: %d payload: %d topic: %s data: %s", + XdrvMailbox.index, + XdrvMailbox.data_len, + XdrvMailbox.payload, + (XdrvMailbox.payload >= 0 ? XdrvMailbox.topic : ""), + (XdrvMailbox.data_len >= 0 ? XdrvMailbox.data : "")); + AddLog(LOG_LEVEL_INFO); + */ + if (XdrvMailbox.index >=0 && XdrvMailbox.index < TIMEPROP_NUM_OUTPUTS) { + timeprops[XdrvMailbox.index].setPower( atof(XdrvMailbox.data), timeprop_current_time_secs ); + } + snprintf_P(TasmotaGlobal.mqtt_data, sizeof(TasmotaGlobal.mqtt_data), PSTR("{\"" D_CMND_TIMEPROP D_CMND_TIMEPROP_SETPOWER "%d\":\"%s\"}"), + XdrvMailbox.index, XdrvMailbox.data); + } + else { + serviced = false; + } + } else { + serviced = false; + } + return serviced; +} /*********************************************************************************************\ * Interface @@ -162,6 +210,9 @@ bool Xdrv48(byte function) case FUNC_EVERY_SECOND: Timeprop_Every_Second(); break; + case FUNC_COMMAND: + result = Timeprop_Command(); + break; case FUNC_SET_POWER: Timeprop_Xdrv_Power(); break; From d966f1f74f3469567d91997e9b45f5f7f148149c Mon Sep 17 00:00:00 2001 From: Marcus Date: Fri, 8 Jan 2021 21:57:56 +0100 Subject: [PATCH 3/6] add ifndef to ensure "tasmota-minimal" still builds --- tasmota/xdrv_48_timeprop.ino | 3 +++ tasmota/xdrv_49_pid.ino | 2 ++ 2 files changed, 5 insertions(+) diff --git a/tasmota/xdrv_48_timeprop.ino b/tasmota/xdrv_48_timeprop.ino index a457c8d94..f11d5e46b 100644 --- a/tasmota/xdrv_48_timeprop.ino +++ b/tasmota/xdrv_48_timeprop.ino @@ -79,6 +79,7 @@ #ifdef USE_TIMEPROP +#ifndef FIRMWARE_MINIMAL # include "Timeprop.h" @@ -153,6 +154,7 @@ bool Timeprop_Command() char command [CMDSZ]; bool serviced = true; uint8_t ua_prefix_len = strlen(D_CMND_TIMEPROP); // to detect prefix of command + AddLog_P(LOG_LEVEL_ERROR, PSTR("TRP: Timeprop_Command called")); /* snprintf_P(log_data, sizeof(log_data), "Command called: " "index: %d data_len: %d payload: %d topic: %s data: %s\n", @@ -220,4 +222,5 @@ bool Xdrv48(byte function) return result; } +#endif // FIRMWARE_MINIMAL #endif // USE_TIMEPROP diff --git a/tasmota/xdrv_49_pid.ino b/tasmota/xdrv_49_pid.ino index eda2b633f..fdc02ea50 100644 --- a/tasmota/xdrv_49_pid.ino +++ b/tasmota/xdrv_49_pid.ino @@ -129,6 +129,7 @@ #ifdef USE_PID +#ifndef FIRMWARE_MINIMAL #include "PID.h" @@ -410,4 +411,5 @@ bool Xdrv49(byte function) } return result; } +#endif // FIRMWARE_MINIMAL #endif // USE_PID From 2e76946e2daab4c9f968d6931f0641bc79eef8db Mon Sep 17 00:00:00 2001 From: Marcus Date: Sat, 9 Jan 2021 18:05:54 +0100 Subject: [PATCH 4/6] add missing Response to SetPv --- tasmota/xdrv_49_pid.ino | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tasmota/xdrv_49_pid.ino b/tasmota/xdrv_49_pid.ino index fdc02ea50..529ca3913 100644 --- a/tasmota/xdrv_49_pid.ino +++ b/tasmota/xdrv_49_pid.ino @@ -237,6 +237,7 @@ void CmndSetPv(void) { // this runs it at the next second run_pid_now = true; } + ResponseCmndNumber(atof(XdrvMailbox.data)); } void CmndSetSp(void) { @@ -358,7 +359,7 @@ void PIDShowValues(void) { static void run_pid() { double power = pid.tick(pid_current_time_secs); -#ifdef PID_DONT_USE_PID_TOPIC +#ifndef PID_DONT_USE_PID_TOPIC // This part is left inside to regularly publish the PID Power via // `%topic%/PID {"power":"0.000"}` char str_buf[FLOATSZ]; From 1fd5c44e6c16d1cadcd2315ca882e748592d10b8 Mon Sep 17 00:00:00 2001 From: Marcus Date: Sat, 9 Jan 2021 18:23:07 +0100 Subject: [PATCH 5/6] add missing response; fix exclusion of PID power --- tasmota/xdrv_49_pid.ino | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tasmota/xdrv_49_pid.ino b/tasmota/xdrv_49_pid.ino index fdc02ea50..529ca3913 100644 --- a/tasmota/xdrv_49_pid.ino +++ b/tasmota/xdrv_49_pid.ino @@ -237,6 +237,7 @@ void CmndSetPv(void) { // this runs it at the next second run_pid_now = true; } + ResponseCmndNumber(atof(XdrvMailbox.data)); } void CmndSetSp(void) { @@ -358,7 +359,7 @@ void PIDShowValues(void) { static void run_pid() { double power = pid.tick(pid_current_time_secs); -#ifdef PID_DONT_USE_PID_TOPIC +#ifndef PID_DONT_USE_PID_TOPIC // This part is left inside to regularly publish the PID Power via // `%topic%/PID {"power":"0.000"}` char str_buf[FLOATSZ]; From 5a165962664b4ebf2294465d6433288e99f4b384 Mon Sep 17 00:00:00 2001 From: Marcus Date: Sun, 10 Jan 2021 15:47:26 +0100 Subject: [PATCH 6/6] update code size metrics --- tasmota/my_user_config.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tasmota/my_user_config.h b/tasmota/my_user_config.h index 5040f6c09..0eb76da95 100644 --- a/tasmota/my_user_config.h +++ b/tasmota/my_user_config.h @@ -811,10 +811,10 @@ // -- Prometheus exporter --------------------------- //#define USE_PROMETHEUS // Add support for https://prometheus.io/ metrics exporting over HTTP /metrics endpoint -// -- PID and Timeprop ------------------------------ -// #define use TIMEPROP // Add support for the timeprop feature (+0k8 code) +// -- PID and Timeprop ------------------------------ // Both together will add +12k1 code +// #define use TIMEPROP // Add support for the timeprop feature (+9k1 code) // For details on the configuration please see the header of tasmota/xdrv_48_timeprop.ino -// #define USE_PID // Add suport for the PID feature (+11k1 code) +// #define USE_PID // Add suport for the PID feature (+11k2 code) // For details on the configuration please see the header of tasmota/xdrv_49_pid.ino // -- End of general directives -------------------