From 6ac7c46b41a8c9481872ea55d1f95c91c07df80d Mon Sep 17 00:00:00 2001 From: Benny Nestler Date: Wed, 30 Mar 2022 11:21:20 +0200 Subject: [PATCH 1/3] Add SetOption137 to avoid mqtt-publish of Tuya MCU heartbeat responses. --- tasmota/settings.h | 2 +- tasmota/xdrv_16_tuyamcu.ino | 14 +++++++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/tasmota/settings.h b/tasmota/settings.h index c0488a194..fbfac2e42 100644 --- a/tasmota/settings.h +++ b/tasmota/settings.h @@ -166,7 +166,7 @@ typedef union { // Restricted by MISRA-C Rule 18.4 bu uint32_t pwm_force_same_phase : 1; // bit 20 (v10.1.0.6) - SetOption134 - (PWM) force PWM lights to start at same phase, default is to spread phases to minimze overlap (also needed for H-bridge) uint32_t display_no_splash : 1; // bit 21 (v11.0.0.2) - SetOption135 - (Display & LVGL) forece disbabling default splash screen uint32_t tuyasns_no_immediate : 1; // bit 22 (v11.0.0.4) - SetOption136 - (TuyaSNS) When ON disable publish single SNS value on Tuya Receive (keep Teleperiod) - uint32_t spare23 : 1; // bit 23 + uint32_t tuya_exclude_heartbeat : 1; // bit 23 (v11.0.0.5) - SetOption137 - (Tuya) When Set, avoid the (mqtt-) publish of Tuya MCU Heartbeat response if SetOption66 is active uint32_t spare24 : 1; // bit 24 uint32_t spare25 : 1; // bit 25 uint32_t spare26 : 1; // bit 26 diff --git a/tasmota/xdrv_16_tuyamcu.ino b/tasmota/xdrv_16_tuyamcu.ino index 2b3fccd8a..ccd4f56d7 100644 --- a/tasmota/xdrv_16_tuyamcu.ino +++ b/tasmota/xdrv_16_tuyamcu.ino @@ -1203,6 +1203,7 @@ void TuyaSerialInput(void) uint8_t dpId = 0; uint8_t dpDataType = 0; char DataStr[15]; + bool isHeartbeat = false; if (len > 0) { ResponseAppend_P(PSTR(",\"CmndData\":\"%s\""), ToHex_P((unsigned char*)&Tuya.buffer[6], len, hex_char, sizeof(hex_char))); @@ -1246,11 +1247,22 @@ void TuyaSerialInput(void) dpidStart += dpDataLen + 4; } } + else if (TUYA_CMD_HEARTBEAT == Tuya.buffer[3]) { + isHeartbeat = true; + } } ResponseAppend_P(PSTR("}}")); if (Settings->flag3.tuya_serial_mqtt_publish) { // SetOption66 - Enable TuyaMcuReceived messages over Mqtt - MqttPublishPrefixTopic_P(RESULT_OR_TELE, PSTR(D_JSON_TUYA_MCU_RECEIVED)); + if (Settings->flag5.tuya_exclude_heartbeat) { // SetOption137 - (Tuya) When Set, avoid the (mqtt-) publish of Tuya MCU Heartbeat response if SetOption66 is active + if (false == isHeartbeat) { + MqttPublishPrefixTopic_P(RESULT_OR_TELE, PSTR(D_JSON_TUYA_MCU_RECEIVED)); + } + } + else { + MqttPublishPrefixTopic_P(RESULT_OR_TELE, PSTR(D_JSON_TUYA_MCU_RECEIVED)); + } + } else { AddLog(LOG_LEVEL_DEBUG, ResponseData()); } From cfa18b6708311fc8ad3f836035cf200a7c9e6866 Mon Sep 17 00:00:00 2001 From: Benny Nestler Date: Wed, 30 Mar 2022 12:14:36 +0200 Subject: [PATCH 2/3] Add macro TUYA_SETOPTION_137 to set SetOption137 during compile time --- tasmota/my_user_config.h | 1 + tasmota/settings.ino | 1 + 2 files changed, 2 insertions(+) diff --git a/tasmota/my_user_config.h b/tasmota/my_user_config.h index b0579a30f..25751644b 100644 --- a/tasmota/my_user_config.h +++ b/tasmota/my_user_config.h @@ -346,6 +346,7 @@ #define TUYA_SETOPTION_20 false // [SetOption54] Apply SetOption20 settings to Tuya device #define TUYA_ALLOW_DIMMER_0 false // [SetOption131] Allow save dimmer = 0 receved by MCU #define TUYA_TEMP_SET_RES 1 // [TuyaTempSetRes] Maximum number of decimals (0 - 3) showing sensor TemperatureSet +#define TUYA_SETOPTION_137 false // [SetOption137] Avoid mqtt-publish of Tuya MCU heartbeat responses #define IR_ADD_RAW_DATA false // [SetOption58] Add IR Raw data to JSON message #define BUZZER_ENABLE false // [SetOption67] Enable buzzer when available #define DS18X20_PULL_UP false // [SetOption74] Enable internal pullup for single DS18x20 sensor diff --git a/tasmota/settings.ino b/tasmota/settings.ino index 3170ad42c..719918208 100644 --- a/tasmota/settings.ino +++ b/tasmota/settings.ino @@ -1208,6 +1208,7 @@ void SettingsDefaultSet2(void) { // Tuya flag3.tuya_apply_o20 |= TUYA_SETOPTION_20; flag5.tuya_allow_dimmer_0 |= TUYA_ALLOW_DIMMER_0; + flag5.tuya_exclude_heartbeat |= TUYA_SETOPTION_137; flag3.tuya_serial_mqtt_publish |= MQTT_TUYA_RECEIVED; mbflag2.temperature_set_res |= TUYA_TEMP_SET_RES; From 699eb30ed56e24a1644b01605165f2982fe37c1b Mon Sep 17 00:00:00 2001 From: Benny Nestler Date: Wed, 30 Mar 2022 14:47:46 +0200 Subject: [PATCH 3/3] CHG: Refactored if-condition --- tasmota/xdrv_16_tuyamcu.ino | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/tasmota/xdrv_16_tuyamcu.ino b/tasmota/xdrv_16_tuyamcu.ino index ccd4f56d7..3351355f3 100644 --- a/tasmota/xdrv_16_tuyamcu.ino +++ b/tasmota/xdrv_16_tuyamcu.ino @@ -1254,15 +1254,9 @@ void TuyaSerialInput(void) ResponseAppend_P(PSTR("}}")); if (Settings->flag3.tuya_serial_mqtt_publish) { // SetOption66 - Enable TuyaMcuReceived messages over Mqtt - if (Settings->flag5.tuya_exclude_heartbeat) { // SetOption137 - (Tuya) When Set, avoid the (mqtt-) publish of Tuya MCU Heartbeat response if SetOption66 is active - if (false == isHeartbeat) { - MqttPublishPrefixTopic_P(RESULT_OR_TELE, PSTR(D_JSON_TUYA_MCU_RECEIVED)); - } - } - else { + if (!(isHeartbeat && Settings->flag5.tuya_exclude_heartbeat)) { // SetOption137 - (Tuya) When Set, avoid the (mqtt-) publish of Tuya MCU Heartbeat response if SetOption66 is active MqttPublishPrefixTopic_P(RESULT_OR_TELE, PSTR(D_JSON_TUYA_MCU_RECEIVED)); - } - + } } else { AddLog(LOG_LEVEL_DEBUG, ResponseData()); }