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] 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();