From 4d2ac90bf155e5adf063b1936910f8dc1b294a1e Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Wed, 2 Jun 2021 17:56:44 +0200 Subject: [PATCH] Add support for long rule events --- tasmota/support_command.ino | 2 +- tasmota/xdrv_02_mqtt_9_impl.ino | 13 +++++++++++++ tasmota/xdrv_10_rules.ino | 5 ++--- tasmota/xdrv_52_9_berry.ino | 4 ++-- tasmota/xdrv_interface.ino | 9 ++++++++- 5 files changed, 26 insertions(+), 7 deletions(-) diff --git a/tasmota/support_command.ino b/tasmota/support_command.ino index ec8e96060..012f04720 100644 --- a/tasmota/support_command.ino +++ b/tasmota/support_command.ino @@ -419,7 +419,7 @@ void CmndStatusResponse(uint32_t index) { all_status.replace("}{", ","); char cmnd_status[10]; // STATUS11 snprintf_P(cmnd_status, sizeof(cmnd_status), PSTR(D_CMND_STATUS "0")); - MqttPublishPayloadPrefixTopic_P(STAT, cmnd_status, all_status.c_str()); + MqttPublishPayloadPrefixTopicRulesProcess_P(STAT, cmnd_status, all_status.c_str()); all_status = (const char*) nullptr; } if (0 == index) { diff --git a/tasmota/xdrv_02_mqtt_9_impl.ino b/tasmota/xdrv_02_mqtt_9_impl.ino index 506b8ebaa..56493b0c5 100644 --- a/tasmota/xdrv_02_mqtt_9_impl.ino +++ b/tasmota/xdrv_02_mqtt_9_impl.ino @@ -719,6 +719,19 @@ void MqttPublishPayloadPrefixTopic_P(uint32_t prefix, const char* subtopic, cons MqttPublishPayloadPrefixTopic_P(prefix, subtopic, payload, 0, false); } +void MqttPublishPayloadPrefixTopicRulesProcess_P(uint32_t prefix, const char* subtopic, const char* payload, bool retained) { + // Publish //> payload string with optional retained + // then process rules + MqttPublishPayloadPrefixTopic_P(prefix, subtopic, payload, 0, retained); + XdrvRulesProcess(0, payload); +} + +void MqttPublishPayloadPrefixTopicRulesProcess_P(uint32_t prefix, const char* subtopic, const char* payload) { + // Publish //> default TasmotaGlobal.mqtt_data string no retained + // then process rules + MqttPublishPayloadPrefixTopicRulesProcess_P(prefix, subtopic, payload, false); +} + void MqttPublishPrefixTopic_P(uint32_t prefix, const char* subtopic, bool retained) { // Publish //> default TasmotaGlobal.mqtt_data string with optional retained MqttPublishPayloadPrefixTopic_P(prefix, subtopic, TasmotaGlobal.mqtt_data, 0, retained); diff --git a/tasmota/xdrv_10_rules.ino b/tasmota/xdrv_10_rules.ino index 1f6536b4a..8f12f9cbb 100644 --- a/tasmota/xdrv_10_rules.ino +++ b/tasmota/xdrv_10_rules.ino @@ -835,9 +835,8 @@ bool RulesProcessEvent(char *json_event) return serviced; } -bool RulesProcess(void) -{ - return RulesProcessEvent(TasmotaGlobal.mqtt_data); +bool RulesProcess(void) { + return RulesProcessEvent(XdrvMailbox.data); } void RulesInit(void) diff --git a/tasmota/xdrv_52_9_berry.ino b/tasmota/xdrv_52_9_berry.ino index d898b0df0..e78884efd 100644 --- a/tasmota/xdrv_52_9_berry.ino +++ b/tasmota/xdrv_52_9_berry.ino @@ -93,9 +93,9 @@ extern "C" { bool callBerryRule(void) { if (berry.rules_busy) { return false; } berry.rules_busy = true; - char * json_event = TasmotaGlobal.mqtt_data; + char * json_event = XdrvMailbox.data; bool serviced = false; - serviced = callBerryEventDispatcher(PSTR("rule"), nullptr, 0, TasmotaGlobal.mqtt_data); + serviced = callBerryEventDispatcher(PSTR("rule"), nullptr, 0, XdrvMailbox.data); berry.rules_busy = false; return serviced; // TODO event not handled } diff --git a/tasmota/xdrv_interface.ino b/tasmota/xdrv_interface.ino index f508fd588..79035ef9c 100644 --- a/tasmota/xdrv_interface.ino +++ b/tasmota/xdrv_interface.ino @@ -1079,16 +1079,23 @@ void XsnsDriverState(void) /*********************************************************************************************/ -bool XdrvRulesProcess(bool teleperiod) { +bool XdrvRulesProcess(bool teleperiod, const char* payload) { + char* data_save = XdrvMailbox.data; + XdrvMailbox.data = (char*)payload; bool rule_handled = XdrvCallDriver(10, (teleperiod) ? FUNC_TELEPERIOD_RULES_PROCESS : FUNC_RULES_PROCESS); #ifdef USE_BERRY // events are passed to both Rules engine AND Berry engine bool berry_handled = XdrvCallDriver(52, FUNC_RULES_PROCESS); rule_handled |= berry_handled; #endif + XdrvMailbox.data = data_save; return rule_handled; } +bool XdrvRulesProcess(bool teleperiod) { + return XdrvRulesProcess(teleperiod, TasmotaGlobal.mqtt_data); +} + #ifdef USE_DEBUG_DRIVER void ShowFreeMem(const char *where) {