From 39615c070005b0251893060e2da3dfcf537f88a3 Mon Sep 17 00:00:00 2001 From: digiblur <3240875+digiblur@users.noreply.github.com> Date: Wed, 17 Apr 2019 21:41:58 -0500 Subject: [PATCH 1/2] Add Tuya Dimmer 10 second heartbeat Some newer dimmer modules require the stock firmware method of sending a heartbeat packet every 10-11 seconds to the secondary MCU. This was tested on 2 other Tuya based dimmers that did not require this heartbeat packet and no adverse impacts have been found. --- sonoff/xdrv_16_tuyadimmer.ino | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/sonoff/xdrv_16_tuyadimmer.ino b/sonoff/xdrv_16_tuyadimmer.ino index d43e6397e..ffb44adab 100644 --- a/sonoff/xdrv_16_tuyadimmer.ino +++ b/sonoff/xdrv_16_tuyadimmer.ino @@ -52,6 +52,7 @@ uint8_t tuya_cmd_status = 0; // Current status of serial-read uint8_t tuya_cmd_checksum = 0; // Checksum of tuya command uint8_t tuya_data_len = 0; // Data lenght of command int8_t tuya_wifi_state = -2; // Keep MCU wifi-status in sync with WifiState() +uint8_t tuya_heartbeat_timer = 0; // 10 second heartbeat timer for tuya module char *tuya_buffer = nullptr; // Serial receive buffer int tuya_byte_counter = 0; // Index in serial receive buffer @@ -294,6 +295,7 @@ void TuyaInit(void) TuyaSendCmd(TUYA_CMD_MCU_CONF); } } + tuya_heartbeat_timer = 0; // init heartbeat timer when dimmer init is done } void TuyaSerialInput(void) @@ -410,6 +412,11 @@ bool Xdrv16(uint8_t function) break; case FUNC_EVERY_SECOND: if(TuyaSerial && tuya_wifi_state!=WifiState()) { TuyaSetWifiLed(); } + tuya_heartbeat_timer++; + if (tuya_heartbeat_timer > 10) { + tuya_heartbeat_timer = 0; + TuyaSendCmd(TUYA_CMD_HEARTBEAT); + } break; case FUNC_SET_CHANNELS: result = TuyaSetChannels(); From a75dc0c4ab56beaf27e81ceb64e65f398647325b Mon Sep 17 00:00:00 2001 From: digiblur <3240875+digiblur@users.noreply.github.com> Date: Wed, 17 Apr 2019 23:01:50 -0500 Subject: [PATCH 2/2] Update _changelog.ino --- sonoff/_changelog.ino | 1 + 1 file changed, 1 insertion(+) diff --git a/sonoff/_changelog.ino b/sonoff/_changelog.ino index 3e1ddb71d..00d134c75 100644 --- a/sonoff/_changelog.ino +++ b/sonoff/_changelog.ino @@ -1,4 +1,5 @@ /* 6.5.0.8 20190413 + * Add Tuya Dimmer 10 second heartbeat serial packet required by some Tuya dimmer secondary MCUs * Fix use of SerialDelimiter value 128 (#5634) * Fix lost syslog connection regression from 6.5.0.4 * Add Shelly 2.5 Energy Monitoring (#5592)