diff --git a/TuyaMCU.md b/TuyaMCU.md index 9fcd5b47..8d08471a 100644 --- a/TuyaMCU.md +++ b/TuyaMCU.md @@ -2,56 +2,6 @@ Module **TuyaMCU (54)** is configured for devices with a Tuya Wi-Fi module and a Originally, in those devices, the Wi-Fi module takes care of network and software features. Meanwhile, the MCU controls the hardware based on commands received from the Wi-Fi module or built-in controls (buttons, switches, remotes and similar) and reports the status back to the Wi-Fi module. -The MCU communicates with the Wi-Fi module through the serial port. Protocols are classified into basic and functional protocols. - -## Basic protocols -They are common protocols integrated in Tasmota's TuyaMCU module. They stay the same for each product and are mandatory for Tuya module to work correctly. - -## Functional protocols -Functional protocols are used for delivering and reporting data of functions. These protocols differ between devices and manufacturers and might require configuration in Tasmota using [`TuyaMCU`](#tuyamcu) command or with [`TuyaSend`](#tuyasend) command. - -### Anatomy of functional protocols - -|Name|Description| -|---|---| -|Frame Header Version|Fixed value of 0x55aa | -|Command Word | `0x06` - send commands
`0x07` - report status| -|Data Length | defines expected length of data -|dpID|numbered ID of a function (DP = Data Point or Define Product)| -|Data Type|[see Data Type table below](#data-type-table)| -|Function Length|length of command| -|Function Command|formatted according to Data Type| -|Verification Method| checksum = remainder of the byte sum starting from Frame Header to 256| - - -#### Data Type -|Hex|Tasmota Command|Decription|Max length| -|---|---|---|---| -|0x01|TuyaSend1|boolean data `0/1`|1 byte| -|0x02|TuyaSend2|value data. If a value contains less than 4 bytes, 0 is supplemented before|4 bytes| -|0x00|TuyaSend3|string data|unknown| -|0x04|TuyaSend4|enum data `0/1/2/3/4/5`|1 byte| -|0x05|###|fault data, report only|8 bytes| - -Let's dissect and explain the MCU protocol using serial command `55aa0006000501010001010e`: - -| Frame Header Version | Command Word | Data Length | dpID | Data Type | Function Length | Function Command | Verification Method | -|:---:|:---:|:---:|:---:|:---:|:---:|:---:|:---:| -| 55aa00| 06| 0005| 01 | 01| 0001| 01| 0e| - -This is the command which powers on the device sending Function Command = `1` to dpID 1 (Switch): -- Frame Header Version = `0x55aa00` which is a fixed value and always the same -- Command Word = `0x06` because we're sending a command -- Data Type = `0x01` since the command sent is a 1 byte boolean -- Function Length = `0x001` instruct 1 character only for function command length -- Function Command = `0x01` in hex which equals `1` in int -- Verification Method = `0e` is calculated - -### Protocol flow -On device boot, TuyaMCU executes the required basic protocols and reads the functional protocol data received, which are used to update status of components mapped in TuyaMCU (Relays, dimmer, power monitoring data). - -After receiving a command from Tasmota (Command Word `0x06`), the MCU performs corresponding logical control. When the dpID status is changed, the MCU reports the data (Command Word `0x07`) to TuyaMCU component. - TuyaMCU module facilitates communication between Tasmota and the MCU with: - `TuyaMCU` command maps device functions to Tasmota components - `TuyaSend` command calculates and sends complex serial commands using only two parameters