Tuya Cloud Universal Serial Port Access Protocol

Last Updated on2020-03-27 07:18:38

Serial communication conventions

Baud rate: 9600/115200

Data bits: 8

Parity: None

Stop bits: 1

Data flow control: None

MCU: User control board control chip, connected with Tuya module through serial port.

Frame Format Description

FieldLength (byte)Description
Frame Header2Fixed at 0x55aa
Version1Upgrade and Expansion
Command word1Specific frame type
Data Length2Big Endian
DataN
Checksum1Byte-sum results from the beginning of the frame, 256 remainder

Explanation:

  • All data larger than 1 byte is transmitted in big-endian mode.

  • Under normal circumstances, the same command word is used to send and receive synchronization mechanism, that is, one party sends a command and the other responds. If the sender does not receive the correct response packet after timeout, the timeout is transmitted, as shown in the figure below:

  

    Note: The specific communication method is subject to the "Protocol Details" section.

  • The module control command is issued and the MCU status is reported in asynchronous mode. Assuming that the module control command is issued with the "command word" as x and the MCU status is reported with the "command word" as y, as follows:

  • Module control command is issued:

   

  1. MCU status report:

   

Protocol details

Heartbeat detection

Explanation:

  1. After the WIFI module is powered on, it periodically sends heartbeats at 15s intervals. If no response is received from the MCU within the timeout period (3s), the MCU is considered offline.

  2. The MCU can also periodically check whether the module is working properly based on this heartbeat. If the module is issued without a heartbeat, the MCU can reset the WIFI module through the hardware reset pin provided by the module.

Module sends:

FieldLength (byte)Description
Frame Header20x55aa
Version10x00
Command Word10x00
Data length20x0000
Data0None
Checksum1Byte-sum results from the beginning of the frame, 256 remainder

Example: 0x55aa 00 00 0000 ff

The MCU returns:

FieldLength (byte)Description
Frame Header20x55aa
Version10x03
Command Word10x00
Data length20x0001
Data10x00: The first heartbeat return value after the MCU restarts, sent only once, used by the module to determine whether the MCU restarts during the work process. Return this value
Checksum1Byte-sum results from the beginning of the frame, 256 remainder

Example: 0x55aa 03 00 0001 00 03 (MCU returns for the first time)

0x55aa 03 00 0001 01 04 (except for the first time, return normally)

Query Product Information

Explanation:

  1. Product ID: Corresponds to the Tuya Developer Platform PID (product identification), which is generated by the Tuya Cloud Developer Platform and used to record product-related information in the cloud.

  2. Product information consists of product ID and MCU software version

  3. MCU software version number format definition: in dotted decimal form, "x.x.x" (0 \ <= x \ <= 99), x is a decimal number

Module sends:

FieldLength (byte)Description
Frame Header20x55aa
Version10x00
Command Word10x01
Data length20x0000
Data0None
Checksum1Byte-sum results from the beginning of the frame, 256 remainder

Example: 0x55aa 00 01 0000 00

The MCU returns:

FieldLength (byte)Description
Frame Header20x55aa
Version10x03
Command Word10x01
Data Length2N
DataN{"p": "AIp08kLIftb8x2x0", "v": "1.0.0", "m": 1}
Checksum1Byte-sum results from the beginning of the frame, 256 remainder

Example: {"p": "AIp08kLIftb8x2x0", "v": "1.0.0", "m": 1}

p indicates that the product ID is AIp08kLIftb8x2x0

v means MCU version is 1.0.0

m indicates the distribution network: 0 default distribution network, 1 low power consumption, 2 special distribution network

Query MCU and set the module's working mode

Explanation:

  1. The module working mode is mainly for how to indicate the working status of WIFI and how to reset WIFI. There are mainly two cases:

    a. MCU cooperates with the module, that is, the module notifies the MCU through the serial port    The current working status of WIFI is supported by the MCU; the MCU detects the need to reset the WIFI and informs the module to reset the WIFI through the serial port.

    b. Module self-processing: The working status of the WIFI module drives the LED status display through the WIFI GPIO pins; WIFI reset is handled by detecting the GPIO input requirements.    The module's self-processing WIFI reset method is: WIFI detects the GPIO entry low level for more than 5s to trigger Wi-Fi reset. The GPIO pins used by the indicators and buttons are configured by the following commands.

Module sends:

FieldLength (byte)Description
Frame Header20x55aa
Version10x00
Command Word10x02
Data length20x0000
Data0None
Checksum1Byte-sum results from the beginning of the frame, 256 remainder

Example: 0x55aa 00 02 0000 01

The MCU returns:

FieldLength (byte)Description
Frame Header20x55aa
Version10x03
Command Word10x02
Data length20x0000 / 0x0002
0x0000: Instruct the module to work in "MCU and module cooperative processing" mode. The MCU must implement the functions mentioned in the "Description" above.
0x0002: Instruct the module to work in "module self-processing" mode.
Data0/2The data length is 2: the first byte is the WIFI status indication GPIO sequence number; the second byte is the WIFI reset button GPIO sequence number
Checksum1Byte-sum results from the beginning of the frame, 256 remainder

Example: 0x55aa 03 02 0000 04 (MCU and module work together)

0x55aa 03 02 0002 0c0d1f (module self-processing, indicator 0x0c: GPIO12, reset button 0x0d: GPIO13)

Report device networking status

Device Networking StatusDescriptionStatus Values ​​
Status 1smartconfig configuration status0x00
State 2AP configuration state0x01
State 3WIFI is configured but not connected to the router0x02
State 4WIFI is configured and connected to the router0x03
Status 5Connected to the router and connected to the cloud0x04
State 6WIFI device is in low power mode0x05

Explanation:

  1. Device networking status: 1 smartconfig configuration status 2 AP configuration status 3     WIFI configured successfully but not connected to the router 4 WIFI configured successfully and connected to the router 5     The device is connected to a router and connected to the cloud. The corresponding LED displays of the "module self-processing" working mode are: 1     250ms flashing interval; 2 1500ms flashing interval; 3 long dark state; 4 or 5 long bright state

  2. When the module detects the process of MCU restart or MCU disconnection and then online, it will actively send WIFI status to MCU

  3. When the WIFI status of the module changes, it will actively send the WIFI status to the MCU

  4. If the module working mode is set to "module self-processing", the MCU does not need to implement the protocol

Module sends:

Field | Length (byte) | Description | | -------- | ------------ | --------------------------- --------------------------------- | | Frame Header | 2 | 0x55aa | | Version | 1 | 0x00 | | Command Word | 1 | 0x03 | Data length | 2 | 0x0001 | Data | 1 | Indicate the working status of WIFI:
0x00: State 1
0x01: State 2
0x02: State 3
0x03: State 4
0x04: State 5
0x05: State 6 | Checksum | 1 | Byte-sum results from the beginning of the frame, 256 remainder |

Example: 0x55aa 00 03 0001 00 03

The MCU returns:

Field | Length (byte) | Description | | -------- | ------------ | --------------------------- ------------ | | Frame Header | 2 | 0x55aa | | Version | 1 | 0x03 | | Command Word | 1 | 0x03 | Data length | 2 | 0x0000 | | Data | 0 | None | Checksum | 1 | Byte-sum results from the beginning of the frame, 256 remainder |

Example: 0x55aa 03 03 0000 05

Reset WIFI

Explanation:

  1. Reset WIFI status transition as shown below:

   

   The module's self-processing WIFI reset method is: WIFI detects the GPIO entry low level for more than 5s to trigger Wi-Fi reset.

   2. If the module working mode is set to "module self-processing", the MCU does not need to implement the protocol

MCU sends:

FieldLength (byte)Description
Frame Header20x55aa
Version10x03
Command Word10x04
Data length20x0000
Data0None
Checksum1Byte-sum results from the beginning of the frame, 256 remainder

Example: 0x55aa 03 04 0000 06

The module returns:

FieldLength (byte)Description
Frame Header20x55aa
Version10x00
Command Word10x04
Data length20x0000
Data0None
Checksum1Byte-sum results from the beginning of the frame, 256 remainder

Example: 0x55aa 00 04 0000 03

Reset WIFI-select configuration mode

Explanation:

  1. Compared to “Resetting WIFI” in section 3.5, this frame provides the MCU to selectively choose the configuration mode after resetting WIFI according to its own needs.

  2. MCU access users can selectively implement the protocol

  3. If the module working mode is set to "module self-processing", the MCU does not need to implement the protocol

MCU sends:

FieldLength (byte)Description
Frame Header20x55aa
Version10x03
Command Word10x05
Data length20x0001
Data10x00: Enter smartconifg configuration mode
0x01: Enter AP configuration mode
Checksum1Byte-sum results from the beginning of the frame, 256 remainder

Example: 0x55aa 03 05 0001 00 08, enter smartconfig configuration mode

The module returns:

FieldLength (byte)Description
Frame Header20x55aa
Version10x00
Command Word10x05
Data length20x0000
Data0None
Checksum1Byte-sum results from the beginning of the frame, 256 remainder

Example: 0x55aa 00 05 0000 04

Command issued

Explanation:

  1. The datapoint command / status data unit is as follows:

Data Section | Length (byte) | Explanation | | ------ | ------------ | ----------------------------- ------------------------------- | ------ | ------------| -------------------------------- | dpid | 1 | datapoint serial number | | | | | type | 1 | Corresponds to the specific data type of a datapoint on the open platform, identified by the following "representation value" | | | | | | | Type | Value | Length (bytes) | | | | raw | 0x00 | N | Corresponds to raw datapoint (module transparent transmission) | | | | bool | 0x01 | 1 | value range: 0x00 / 0x01 | | | value | 0x02 | 4 | Corresponds to int type, big-endian | | | | string | 0x03 | N | corresponds to a specific string | | | | enum | 0x04 | 1 | Enumeration type, range 0-255 | | | | bitmap | 0x05 | 1/2/4 | len | 2 | Number of bytes corresponding to length | | | | value | 1/2/4 / N | hex indicates that big-endian transmission is used for more than 1 byte | | | |

  1. Datapoint command / status data unit except "raw" type, other types are "obj" type datapoint

  2. The "command delivery" may contain multiple datapoint "command data units"

  3. "Command Issue" is an asynchronous processing protocol, corresponding to the "status report" of the MCU's datapoint

Module sends:

FieldLength (byte)Description
Frame Header20x55aa
Version10x00
Command Word10x06
Data length2Depends on Command Data Unit type and number
DataN"3.7.1 Command Data Unit" Group
Checksum1Byte-sum results from the beginning of the frame, 256 remainder

Example: The system switch corresponds to DP No. 3, using a bool-type variable, and the power-on value is 1.

0x55aa 00 06 0005 ** 03 01 0001 01 ** 10

Status report

Explanation:

  1. For details of the datapoint status data unit, see "Section 3.7"

  2. "State Report" is an asynchronous processing protocol. There are three types of "State Report" trigger mechanisms:

    a. When the MCU receives the "command to issue a processing frame, the corresponding datapoint command is correctly executed, and then the changed datapoint status is sent to the module through the" status report "frame;

    b. The MCU actively detects a change in the datapoint and sends the changed datapoint status to the module;

    c. When the MCU receives the status query frame of “3.9”, it sends all datapoint status to the module.

  3. The "status report" may contain multiple datapoint "command data units"

MCU sends:

FieldLength (byte)Description
Frame Header20x55aa
Version10x03
Command Word10x07
Data length2Depends on the type and number of Status Data Units
DataN"3.7.1 Status Data Unit" Group
Checksum1Byte-sum results from the beginning of the frame, 256 remainder

Example: The humidity corresponds to No. 5 DP, using a valve-type variable, and the humidity is 30 ° C

0x55aa 03 07 0008 05 02 0004 0000001e 3a

Status query

Explanation:

  1. "Status query" is an asynchronous processing protocol, which is mainly used by the module to query the status of all "obj" type datapoints of the MCU. When the MCU receives this frame, it reports the datapoint status through the "3.8" status report frame

  2. There are two main timings for sending "Status Query":

    a. The module is powered on for the first time, and after the connection is established with the MCU through the heartbeat, the query is sent;

    b. During the module's work, it is detected that the MCU restarts or goes offline and then goes online. The query is sent.

Module sends:

FieldLength (byte)Description
Frame Header20x55aa
Version10x00
Command Word10x08
Data length20x0000
Data0None
Checksum1Byte-sum results from the beginning of the frame, 256 remainder

Example: 0x55aa 00 08 0000 07

MCU upgrade service

Explanation:

  1. When to upgrade the customer The Tuya IoT platform ’s own product page configuration related upgrade options are triggered. The module is only used as a data transmission channel to support MCU upgrades and does not perform any analysis of the data content.

  2. At present, the MCU upgrade of Tuya platform supports the following four configuration methods:

    a.App reminder upgrade: In this upgrade method, users will receive the pop-up window of the upgrade reminder every time they enter the device control panel. Whether to confirm the upgrade is confirmed by the user in the App.

    b.App silent upgrade: This upgrade method App will not have any pop-up window. The firmware will automatically detect the upgrade within one minute after the firmware is powered on. It will automatically start pulling related upgrade packages if it finds a higher version upgrade package. After power-on, the module will go to the cloud to check whether there is an upgrade package configuration at an interval of 24 hours.

    c.App forced upgrade:In this upgrade method, there will be an upgrade reminder pop-up on the App side. If the user does not confirm the upgrade, the user cannot use the control panel of this product normally.

    d.App detection upgrade: this upgrade method App sideThere will not be any pop-up window for upgrade reminder. The user must click on the App to check the relevant firmware version by himself. If there is a higher firmware configuration, the upgrade prompt message will be displayed.

  3. MCU upgrade related flowchart:

    After the WIFI module sends all the upgrade packages, resend the 01 command word (3.2 query product information). The MCU needs to reply the software version number in the product information with the updated MCU version number in one minute. The version number needs to be configured in Tuya's background. Upgraded version numbers remain the same.

Upgrade started (upgrade package size notification)

Explanation:

  1. The upgrade startup method includes automatic and manual upgrades. When it is in automatic upgrade, the module detects that the cloud MCU has a newer version of firmware, then it automatically starts the interaction process with the MCU upgrade package; when it is in manual upgrade, it is determined by the App that the module inspires the interaction process with the MCU upgrade package

Module sends:

FieldLength (byte)Description
Frame Header20x55aa
Version10x00
Command Word10x0a
Data length20x0004
Data4Firmware Package Bytes, unsigned int, Big Endian
Checksum1Byte-sum results from the beginning of the frame, 256 remainder

Example: 0x55aa 00 0a 0004 00006800 75 (the firmware package length is 26624, which is 26KB)

The MCU returns:

FieldLength (byte)Description
Frame Header20x55aa
Version10x03
Command Word10x0a
Data length20x0001
Data1Upgrading packet transfer size:
0x00: default 256byte (compatible with old firmware)
0x01: 512byte
0x02: 1024byte
Checksum1Byte-sum results from the beginning of the frame, 256 remainder

Example: 0x55aa 03 0a 0001 00 0d

Upgrade package transmission

Explanation:

  1. Upgrade packet transmission data format: packet offset (unsigned short) + packet data

  2. If the MCU receives the frame data length of 4 and the packet offset > = firmware size, the packet transmission ends.

Module sends:

FieldLength (byte)Description
Frame Header20x55aa
Version10x00
Command Word10x0b
Data length20x0004 + Data packet length
DataNThe first four bytes, fixed at the packet offset, followed by the packet content
Checksum1Byte-sum results from the beginning of the frame, 256 remainder

example:

The file size to be upgraded is 530Byte, (the last packet of data may not be returned)

(1) The first packet of data, the packet offset is 0x00000000, and the packet length is 256

0x55aa 00 0b 0104 00000000 xx ... xx XX

(2) The second packet of data, the packet offset is 0x00000100, and the packet length is 256

0x55aa 00 0b 0104 00000100 xx ... xx XX

(3) The third packet of data, the packet offset is 0x00000200, and the packet length is 18

0x55aa 00 0b 0016 00000200 xx ... xx XX

(4) The last packet, the packet offset is 0x00000212, and the data packet length is 0

0x55aa 00 0b 0004 00000212 xx ... xx XX

The MCU returns:

FieldLength (byte)Description
Frame Header20x55aa
Version10x03
Command Word10x0b
Data length20x0000
Data0None
Checksum1Byte-sum results from the beginning of the frame, 256 remainder

Example: 0x55aa 03 0b 0000 0d

Get System Time (GMT)

Explanation:

(1) Green Time does not include time zone and daylight saving time factors, and is an international standard time reference.

(2) When the local time stamp is calibrated before the module is connected to the network, it will return success with valid time data.

MCU sends:

FieldLength (byte)Description
Frame Header20x55aa
Version10x03
Command Word10x0c
Data length20x0000
Data0None
Checksum1Byte-sum results from the beginning of the frame, 256 remainder

Example: 0x55aa 03 0c 0000 0e

The module returns:

FieldLength (byte)Description
Frame Header20x55aa
Version10x00
Command Word10x0c
Data length20x0007
Data7Data length is 7 bytes:
Data [0] is the time success flag, 0 means failure, 1 means success
Data [1] means year, 0x00 means 2000 Year
Data [2] is the month, starting from 1 to 12
Data [3] is the date, starting from 1 to 31
Data [4] is the clock, starting from 0 to 23 ends
Data [5] is minutes, starting from 0 to 59 and ends
Data [6] is seconds, starting from 0 to 59 ends
Checksum1Byte-sum results from the beginning of the frame, 256 remainder

Example: 0x55aa 00 0c 0007 01 10 04 13 05 06 07 4c (5: 6: 7 GMT on April 19, 2016)

Get local time

Explanation:

(1) Local time is based on GMT plus local time (where the device is activated) and daylight saving time.

(2) When the local time stamp is calibrated before the module is connected to the network, it will return success with valid time data.

MCU sends:

FieldLength (byte)Description
Frame Header20x55aa
Version10x03
Command Word10x1c
Data length20x0000
DataxxxxNone
Checksum1Byte-sum results from the beginning of the frame, 256 remainder

The module returns:

FieldLength (byte)Description
Frame Header20x55aa
Version10x00
Command Word10x1c
Data length20x0008
DataDataThe length of the data is 8 bytes:
Data [0] is the time success flag, 0 means failure, 1 means success
Data [1] means year, 0x00 means 2000 Year
Data [2] is the month, starting from 1 to 12
Data [3] is the date, starting from 1 to 31
Data [4] is the clock, starting from 0 to 23 ends
Data [5] is minutes, starts from 0 to 59 ends
Data [6] is seconds, starts from 0 to 15 ends
Data [7] is days, from 1 Start to end of 7, 1 for Monday
Checksum1Byte-sum results from the beginning of the frame, 256 remainder

example:

(1) If the device is activated and used in China, local time is Beijing time (Eastern District 8)

0x55aa 00 1c 0008 01 10 04 13 05 06 07 02 5f (Beijing time April 19, 2016 5: 6: 7PM)

(2) If the device is activated for use abroad, the local time is the time zone of the device

WIFI functional test (scan specified routes)

Explanation:

  1. The module currently scans the specified SSID: tuya_mdev_test, and returns the scan result and signal strength percentage.

  2. In order to prevent the defective products to the greatest extent, it is recommended that the customer control the distance between the router and the device to about 5 meters.

    A signal strength of 60% or higher is qualified. Here you can adjust it according to your production line and factory environment.

MCU sends:

FieldLength (byte)Description
Frame Header20x55aa
Version10x03
Command Word10x0e
Data length20x0000
DataNone
Checksum1Byte-sum results from the beginning of the frame, 256 remainder

The module returns:

FieldLength (byte)Description
Frame Header20x55aa
Version10x00
Command Word10x0e
Data Length20x0002
Data2Data length is 2 bytes:
Data [0]: 0x00 failed, 0x01 succeeded;
When Data [0] is 0x01, that is, Data [1] indicates the signal strength (0-100, 0 signal is the worst, 100 signal is the strongest)
When Data [0] is 0x00, which means failure, Data [1] is 0x00 means that the specified ssid is not scanned, and Data [1] is 0x01 indicates that the module has not flashed the authorization key
Checksum1Byte-sum results from the beginning of the frame, 256 remainder

Get module memory

Description: Get the remaining memory of the WIFI module

MCU sends:

FieldLength (byte)Description
Frame Header20x55aa
Version10x03
Command Word10x0f
Data length20x0000
DataNone
Checksum1Byte-sum results from the beginning of the frame, 256 remainder

The module returns:

FieldLength (byte)Description
Frame Header20x55aa
Version10x00
Command Word10x0f
Data length20x0004
Data4Data length is 4 bytes, big-endian format:
Such as 0x00 0x00 0x28 0x00 represents the remaining 10240 bytes of memory
Checksum1Byte-sum results from the beginning of the frame, 256 remainder

Turn on the function of obtaining weather data (optional)

Note: Turn on the function of obtaining weather data

MCU sends:

FieldLength (byte)Description
Frame Header20x55aa
Version10x03
Command Word10x20
Data length2N ((L + K) + (L + K) ...)
DataDataL: Occupies 1 byte, indicating the length of K K: Request parameter name
For example: L: 0x06 K: w.temp
L: 0x06 K: w.pm25
L : 0x0a K: w.humidity
L: 0x0b K: w.condition
Checksum1Byte-sum results from the beginning of the frame, 256 remainder

The module returns:

Fieldlength (byte)Description
Frame Header20x55aa
Version10x00
Command Word10x20
Data Length20x0002
Data2Data [0]:
0x00 indicates failure. For the specific error reason, see the error code description of Data [1]
0x01 indicates success
Data [1]: <br / > 0x00 No error
0x01 error code, illegal data format
0x02 error code, abnormal error
Checksum1Byte-sum results from the beginning of the frame, 256 remainder

Send weather data (optional)

Note: The weather data is issued. After the weather data function is turned on, the module will issue it regularly. After the function is turned on, it will be sent out immediately, followed by 30-minute intervals.

Module sends:

FieldLength (byte)Description
Frame Header20x55aa
Version10x00
Command Word10x21
Data length2N ((LKTLV) + (LKTLV) + ...)
DataData0x00: indicates failure
0x01: error code, indicates that the parameter service does not have permissions (confirm whether the parameter service is purchased)

0x01: indicates success
L: Parameter name length
K: Parameter name T: 0x00 integer, 0x01 character string
L: Field name length
V: Field value
Checksum1Byte-sum results from the beginning of the frame, 256 remainder

The MCU module returns:

FieldLength (byte)Description
Frame Header20x55aa
Version10x00
Command Word10x21
Data length20x0000
Data0None
Checksum1Byte-sum results from the beginning of the frame, 256 remainder

Remarks:

  1. The request parameter list such as w.temp, w.pm25 returns w.temp, and the returned parameters are less than the request parameters. Please check carefully that the request parameter names are correct.

  2. The field value of w.condition can refer to "Weather UTF-8 Code Comparison Table" or the following "W.condition Weather UTF-8 Code Table"

example:

w.humidity: 69, w.temp: 32, w.pm25: 10, w.condition: cloudy (UTF-8 encoding E5A49A E4BA91)

55 AA 00 21 00 40 01 0A 77 2E 68 75 6D 69 64 69 74 79 00 04 00 00 00 45 06 77 2E 74 65 6D 70 00 04 00 00 00 20 06 77 2E 70 6D 32 35 00 04 00 00 00 10 0B 77 2E 63 6F 6E 64 69 74 69 6F 6E 01 06 E5 A4 9A E4 BA 91 1E

The weather UTF-8 code table for w.condition is as follows:

Texthex encodingtexthex encoding
SunnyE699B4Heavy RainE5A4A7 E99BA8
ThunderstormE99BB7 E69AB4SandstormE6B299 E5B098 E69AB4
Light SnowE5B08F E99BAASnowE99BAA
Frost MistE586BB E99BBEHeavy RainE69AB4 E99BA8
Partial showersE5B180 E983A8 E998B5 E99BA8DustE6B5AE E5B098
LightningE99BB7 E794B5Light ShowerE5B08F E998B5 E99BA8
RainE99BA8SleetE99BA8 E5A4B9 E99BAA
Dust tornadoE5B098 E58DB7 E9A38EIce particlesE586B0 E7B292
Strong SandstormE5BCBA E6B299 E5B098 E69AB4YangshaE689AC E6B299
Light to moderate rainE5B08F E588B0 E4B8AD E99BA8Mostly sunnyE5A4A7 E983A8 E699B4 E69C97
FogE99BBEShowerE998B5 E99BA8
Strong showersE5BCBA E998B5 E99BA8Heavy SnowE5A4A7 E99BAA
Heavy RainE789B9 E5A4A7 E69AB4 E99BA8BlizzardE69AB4 E99BAA
HailE586B0 E99BB9Small to medium snowE5B08F E588B0 E4B8AD E99BAA
Shao YunE5B091 E4BA91Snow showersE5B08F E998B5 E99BAA
ZhongxueE4B8AD E99BAAOvercastE998B4
Ice NeedleE586B0 E99288Heavy RainE5A4A7 E69AB4 E99BA8
Thunderstorm with hailE99BB7 E998B5 E99BA8 E4BCB4 E69C89 E586B0 E99BB9Freezing rainE586BB E99BA8
Snow showersE998B5 E99BAALight rainE5B08F E99BA8
HazeE99CBERainE4B8AD E99BA8
CloudyE5A49A E4BA91ThunderstormE99BB7 E998B5 E99BA8
Medium to heavy rainE4B8AD E588B0 E5A4A7 E99BA8Heavy rainE5A4A7 E588B0 E69AB4 E99BA8

Status reporting (synchronous)

Explanation:

  1. This command is a synchronous instruction. After the MCU data status is reported, you need to wait for the module to return the result.

  2. Each time the sending module will respond, the WIFI module cannot report multiple times before it responds;

  3. When the network is not good and the data is difficult to report in time, the module will fail after 5 and the MCU will need to wait more than 5 seconds.

  4. For details of the datapoint status data unit, see "Section 3.7"

  5. The "status report" may contain multiple datapoint "command data units"

MCU sends:

FieldLength (byte)Description
Frame Header20x55aa
Version10x03
Command Word10x22
Data length2Depends on the type and number of Status Data Units
DataN"3.7.1 Status Data Unit" Group
Checksum1Byte-sum results from the beginning of the frame, 256 remainder

The module returns:

FieldLength (byte)Description
Frame Header20x55aa
Version10x00
Command Word10x23
Data Length20x01
DataData0x00: indicates failure
0x01: indicates success
Checksum1Byte-sum results from the beginning of the frame, 256 remainder

Get the current WIFI signal strength (optional)

MCU sends:

FieldLength (byte)Description
Frame Header20x55aa
Version10x03
Command Word10x24
Data length20
DataNNone
Checksum1Byte-sum results from the beginning of the frame, 256 remainder

The module returns:

FieldLength (byte)Description
Frame Header20x55aa
Version10x00
Command Word10x24
Data length20x0001
DataData0x00: indicates failure
less than 0: indicates signal strength, such as (-60db)
Checksum1Byte-sum results from the beginning of the frame, 256 remainder

Notify WIFI module to turn off heartbeat (optional)

MCU sends:

FieldLength (byte)Description
Frame Header20x55aa
Version10x03
Command Word10x25
Data length20
DataNNone
Checksum1Byte-sum results from the beginning of the frame, 256 remainder

The module returns:

FieldLength (byte)Description
Frame Header20x55aa
Version10x00
Command Word10x25
Data length20
DataNNone
Checksum1Byte-sum results from the beginning of the frame, 256 remainder

Explanation:

For MCU modules that need to sleep to reduce power consumption, this command can be sent before sleep to turn off the heartbeat of the WIFI module, which is convenient for entering the sleep state. Do not send this command when the device is powered on. After the WIFI module is powered on, a heartbeat connection must be established with the MCU.

Serial port network interface (optional)

Explanation:

  1. It can be used for Tuya App or Tuya App's SDK for independent development to obtain relevant distribution network parameters, and can send serial data to the module through the serial port to achieve the module's network distribution operation through serial communication.

  2. The module must be in the network ready state to complete serial port network configuration.

  3. After the module returns the response of successfully receiving the serial network configuration information, it will use the received information to connect to the route and activate it in the cloud.

MCU sends:

FieldLength (byte)Description
Frame Header20x55aa
Version10x03
Command Word10x2A
Data length2xx
DataData{"s": "xxx", "p": "yyy", "t": "zzz"} s: ssid p: password t: token, generated by the App
Checksum1Byte-sum results from the beginning of the frame, 256 remainder

The module returns:

FieldLength (byte)Description
Frame Header20x55aa
Version10x00
Command Word10x2A
Data Length20x0001
Datax0x00: Data received successfully
0x01: Not in the network status
0x02: json data is illegal
0x03: Other errors
Checksum1Byte-sum results from the beginning of the frame, 256 remainder

Get the current WIFI network status

Device Networking StatusDescriptionStatus Values ​​
Status 1smartconfig configuration status0x00
State 2AP configuration state0x01
State 3WIFI is configured but not connected to the router0x02
State 4WIFI is configured and connected to the router0x03
Status 5Connected to the router and connected to the cloud0x04
State 6WIFI device is in low power mode0x05

Note: Consistent with 3.4.

MCU sends:

FieldLength (byte)Description
Frame Header20x55aa
Version10x03
Command Word10x2B
Data length20x0000
DataNone
Checksum1Byte-sum results from the beginning of the frame, 256 remainder

The module returns:

FieldLength (byte)Description
Frame Header20x55aa
Version10x00
Command Word10x2B
Data length20x0000
Datax0x00: smartconfig configuration status
0x01: AP configuration status
0x02: WIFI is configured but not connected to a router
0x03: WIFI is configured and connected to a router
0x04: Connected to the router and connected to the cloud
0x05: WIFI device is in low power mode
Checksum1Byte-sum results from the beginning of the frame, 256 remainder

Sweeper map data service (optional)

Explanation:

  1. The command of the sweeper stream service is not supported by all modules. The use of this service requires the use of a specific module to enable related services before it can be used normally.

  2. This service is currently a service for the transmission of the map data of the sweeper, as a special shortcut channel for the sweeper and Tuya App map line.

  3. The complete map data of the sweeper is distinguished by the map ID in the protocol. The data App of the same ID will think that this is a map data and will be accumulated.

  4. The sweeping machine needs to move around the whole house during the cleaning process. Here, weak WIFI signals in some areas may cause data upload failure. At present, the module can cache 24 pieces of data under sufficient premise.

Map Stream Data Transmission

Explanation:

1) The offset indicates the total length of data that has been sent before the map data MCU.

2) The data content here can be up to 1024 bytes in the module serial port.

The data part of the data packet cannot exceed 1024 bytes, and the content of map data in each packet is recommended to be 512 bytes per packet.

3) The map ID is used as a sign of a complete map data. The data transmission party needs to change the map ID to start a new cleaning after the completion of a completed cleaning, that is, the end of a map data. Generally, the map ID is performed in increments. Display local map ID. Changing the current map data display will clear the previous data and restart the display.

4) After the data transmission is started, the module will stop sending heartbeat packets to ensure the priority transmission of map data. The subsequent modules will not actively resume the sending of heartbeat packets under the premise of continuous power.

MCU sends:

FieldLength (byte)Description
Frame Header20x55aa
Version10x03
Command Word10x28
Data length20x0006 + N
Data2Map ID number: The map ID number is used as the belonging identifier of a map data.
4Offset (the first packet is 0)
NEntity Data (Big Endian Mode)
Checksum1Byte-sum results from the beginning of the frame, 256 remainder

The module returns:

FieldLength (byte)Description
Frame Header20x55aa
Version10x00
Command Word10x28
Data length20x0001
DataData0x00: Success
0x01: The streaming service function is not enabled
0x02: The streaming server was not successfully connected
0x03: Data push timeout
0x04: The length of the transmitted data is wrong
Checksum1Byte-sum results from the beginning of the frame, 256 remainder

WIFI functional test (connection specified route)

Explanation:

  1. After the MCU sends the routing information to the module successfully, the module will use the relevant information to connect to the route.

  2. The MCU here determines whether to connect to the router, according to the packet received in the module 3.4 protocol (state 4-WIFI is configured and connected to the router). Here it is judged that the failed MCU receives the return failure, or does not receive the status packet connected to the route for a long time (more than 15S) and considers it to have failed.

  3. The production test can be re-sent to the production test and the test command can be resent. If no routing packet is received, it indicates that the module is in production test and needs to reset the module or send the test command to power on again.

  4. The module needs to be connected to the network to complete the connection test.

  5. Before the production test, the module's heartbeat package and product query package module must be initialized before entering the production test of the connection route.

  6. The router name string length supports a maximum of 32 bytes, and the router password string length supports a maximum of 64 bytes.

MCU sends:

FieldLength (byte)Description
Frame Header20x55aa
Version10x03
Command Word10x2C
Data Length2xxxx
DataData{"ssid": "xxx", "password": "xxxxxxxx"} ssid: route name password: routing password
Checksum1Byte-sum results from the beginning of the frame, 256 remainder

The module returns:

FieldLength (byte)Description
Frame Header20x55aa
Version10x00
Command Word10x2C
Data length20x0001
Data1The data length is 1 byte:
Data [0]:
0x00 routing information reception failed:
(Please check whether the routing information packet sent is not the completed JSON packet data )
0x01 routing information received successfully (result please note the network status packet in 3.4)
Checksum1Byte-sum results from the beginning of the frame, 256 remainder

Get module MAC

MCU sends:

FieldLength (byte)Description
Frame Header20x55aa
Version10x03
Command Word10x2d
Data length20x0000
DataNone
Checksum1Byte-sum results from the beginning of the frame, 256 remainder

The module returns:

FieldLength (byte)Description
Frame Header20x55aa
Version10x00
Command Word10x2d
Data length20x0007
Datadata [0]:
Flag indicating whether the MAC address was successfully obtained:
0x00 indicates success, which means that the next 6 bytes of the MAC address are valid.
0x01 indicates that the MAC address failed, Indicates that the following 6 bytes of the MAC are invalid.

data [1] \ ~ data [6]: When the MAC address flag data [0] is obtained, it indicates that the module has a valid MAC address.
Checksum1Byte-sum results from the beginning of the frame, 256 remainder

Infrared status notification (optional)

Device Infrared StatusDescriptionStatus Value
Status 1Sending Infrared Code0x00
State 2Send infrared code end0x01
State 3Infrared Learning Begins0x02
State 4Infrared Learning End0x03

Explanation:

  1. The infrared function is manually configured and sent samples by the Tuya IOT front desk configuration or the relevant project manager.

  2. The time period of infrared code sending is very short and needs to maintain good real-time performance. Here the serial data is sent directly.     No related retransmissions are performed.

  3. According to their own development needs, customers can display related status according to the infrared status report.

  4. Infrared code sending and receiving infrared codes need to use the two IO pins of the module. If the networking status of your device is also the module's self-processing mode, please note that the IO port should not be set with related IO pins.

Module sends:

FieldLength (byte)Description
Frame Header20x55aa
Version10x00
Command Word10x2e
Data length20x0001
DataDataIndicate infrared working status:
0x00: status 1
0x01: status 2
0x02: status 3
0x03: status 4
Checksum1Byte-sum results from the beginning of the frame, 256 remainder

MCU returns:

FieldLength (byte)Description
Frame Header20x55aa
Version10x03
Command Word10x2e
Data length20x0000
DataNone
Checksum1Byte-sum results from the beginning of the frame, 256 remainder

Infrared enters production test (optional)

Explanation:

  1. The infrared production test function can be entered only when the network is not configured.

  2. The module enters the infrared learning state when it enters the infrared production test state.

  3. Once the module enters the infrared production test mode, it will always be in the production test state and then send it out according to the learning data. When the module is equipped with the Internet or is powered off, it will exit the production test.

MCU sends:

FieldLength (byte)Description
Frame Header20x55aa
Version10x03
Command Word10x2f
Data length20x0000
DataNone
Checksum1Byte-sum results from the beginning of the frame, 256 remainder

The module returns:

FieldLength (byte)Description
Frame Header20x55aa
Version10x00
Command Word10x2f
Data length20x0001
DataData0x00 indicates that the infrared transmission and reception production testing was successful
0x01 indicates that the infrared transmission and reception production test failed
Checksum1Byte-sum results from the beginning of the frame, 256 remainder