Messaging With Custom Format

Last Updated on : 2022-10-25 03:01:53download

If the connected devices cannot communicate with the cloud using JSON-formatted data, they can send raw data to the cloud. Tuya IoT Development Platform converts data between a custom format and the JSON format based on the scripts you have submitted.

This topic describes messaging using a custom format and the relevant MQTT topics.

Feature description

To enable a device to report and receive data in custom format, choose Custom for Data Protocol when you create a TuyaLink-based product and then submit a data parsing script. For more information, see Data Parsing.

Report custom format data

Interaction diagram

Messaging With Custom Format

Device sends messages

Topic: tylink/${deviceId}/channel/raw/up

Message content

// Custom format data, such as
0x312c332c312c302c312c31342c313633373131343839323238372c4f4e

Parse upstream data

function rawDataToTyLink(bytes)

  • Input parameter: raw data (bytes)

  • Output parameter: JSON data

    {
      "msgType": "thing.action.execute.response",
      "payload": {
        "msgId": "17",
        "time": 1637114892287,
        "code": 0
      }
    }
    

Description

Parameter Type Description Required Remark
msgType string Message type Yes The msgType of the reported data.
payload string payload Yes JSON data

The msgType of the reported data.

Feature Message type msgType
Report property values The device positively reports property updates. thing.property.report
Receive property settings The device responds to the property setting. thing.property.set.response
Report property values in bulk The device reports property updates or those of the sub-devices in bulk. thing.data.batch.report
Report events The device reports event-triggered messages. thing.event.trigger
Perform actions The device returns the result of the action. thing.action.execute.response

Receive custom format data

Interaction diagram

Messaging With Custom Format

Device receives messages

Topic: tylink/${deviceId}/channel/raw/down

Message content

// Custom format data into which the downstream data is parsed, such as
0x312c312c312c302c312c313030312c313633373131343839323238372c4f4e

Parse downstream data

function tyLinkToRawData(json)

  • Input parameter: JSON data

    {
      "msgType": "thing.action.execute",
      "payload": {
        "msgId": "2011",
        "time": 1637114892287,
        "data": {
          "actionCode": "ptzcontrol",
          "inputParams": {
            "direction": "UP"
          }
        }
      }
    }
    
  • Output parameter: custom format data

Description

Parameter Type Description Required Remark
msgType string Message type Yes The msgType of the received data.
payload string payload Yes JSON data

The msgType of the received data.

Feature Message type msgType
Report property values The device receives a response to the reported property. thing.property.report.response
Receive property settings The device receives property settings from the cloud. thing.property.set
Report property values in bulk The device receives a response to the reported property in bulk. thing.data.batch.report.response
Report events The device receives a response to the reported event message. thing.event.trigger.response
Perform actions The device receives a command to perform an action. thing.action.execute