Support for setting the time in the Tuya MCU

Switch on with USE_TUYA_TIME
This commit is contained in:
Walter Zengel 2020-04-22 11:07:45 +02:00 committed by GitHub
parent 14e19b7cde
commit 550f079f6a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 0 deletions

View File

@ -410,6 +410,7 @@
#define USE_SONOFF_SC // Add support for Sonoff Sc (+1k1 code)
#define USE_TUYA_MCU // Add support for Tuya Serial MCU
#define TUYA_DIMMER_ID 0 // Default dimmer Id
#define USE_TUYA_TIME // Add support for Set Time in Tuya MCU
#define USE_ARMTRONIX_DIMMERS // Add support for Armtronix Dimmers (+1k4 code)
#define USE_PS_16_DZ // Add support for PS-16-DZ Dimmer (+2k code)
#define USE_SONOFF_IFAN // Add support for Sonoff iFan02 and iFan03 (+2k code)

View File

@ -36,6 +36,7 @@
#define TUYA_CMD_SET_DP 0x06
#define TUYA_CMD_STATE 0x07
#define TUYA_CMD_QUERY_STATE 0x08
#define TUYA_CMD_SET_TIME 0x1C
#define TUYA_LOW_POWER_CMD_WIFI_STATE 0x02
#define TUYA_LOW_POWER_CMD_WIFI_RESET 0x03
@ -539,6 +540,9 @@ void TuyaNormalPowerModePacketProcess(void)
if (Tuya.buffer[6] == 0) {
AddLog_P(LOG_LEVEL_DEBUG, PSTR("TYA: Detected MCU restart"));
Tuya.wifi_state = -2;
#ifdef USE_TUYA_TIME
TuyaSetTime();
#endif
}
break;
@ -797,6 +801,24 @@ void TuyaSetWifiLed(void)
}
}
#ifdef USE_TUYA_TIME
void TuyaSetTime(void)
{
uint16_t payload_len = 8;
uint8_t payload_buffer[8];
payload_buffer[0] = 0x01;
payload_buffer[1] = (uint8_t)RtcTime.year;
payload_buffer[2] = RtcTime.month;
payload_buffer[3] = RtcTime.day_of_month;
payload_buffer[4] = RtcTime.hour;
payload_buffer[5] = RtcTime.minute;
payload_buffer[6] = RtcTime.second;
payload_buffer[7] = RtcTime.day_of_week;
TuyaSendCmd(TUYA_CMD_SET_TIME, payload_buffer, payload_len);
}
#endif //USE_TUYA_TIME
#ifdef USE_ENERGY_SENSOR
/*********************************************************************************************\
* Energy Interface