Data Transfer

Last Updated on : 2024-06-25 03:44:51download

TuyaOS development framework supports the following types of data transfers: report, read, and write attributes, send and receive commands, and send data points (DPs) of raw type.

Attribute

The status information and configuration of Zigbee devices are stored as attributes in each cluster. Each Zigbee device keeps an attribute table that supports the following attribute operations:

  • Report attributes
  • Read attributes
  • Write attributes

Standard attributes supported by Zigbee devices are defined by Connectivity Standards Alliance (CSA). For more information, see Zigbee Cluster Library Specification published by CSA. For TuyaOS-based devices, you can additionally define private attributes.

Data Transfer

  • Report attributes: Zigbee sub-devices proactively report attributes to sync their current status. For example, a temperature sensor can report the temperature attribute to the associated gateway if temperature changes are detected.
  • Read attributes: Read attributes from Zigbee sub-devices to get their information, such as the manufacturer name, firmware version, and model ID. This operation also returns the current status of a device, for example, the on/off status of a light.
  • Write attributes: Set and modify one or more attributes on a device. For example, to make the color temperature of a light adjustable within a range, write the attribute ColorTempPhysicalMinMireds (0x400b) to define the minimum value and ColorTempPhysicalMaxMireds (0x400c) to define the maximum value.

TuyaOS provides the APIs for reporting attributes and callback functions to invoke when attributes are read or written. You can configure attribute tables and save them to non-volatile memory. This prevents the loss of attribute values in case of a power outage.

Note that certain attributes cannot be written. For more information, see Zigbee Cluster Library Specification.

To reduce network congestion, we recommend that you avoid frequent attribute reporting. Instead, report attributes only when needed.

Command

A device can send a command to control another device. For example, a lighting remote control can send on and off commands to a lighting device to control the on/off status of the peer. Similarly, gateways send commands to control Zigbee sub-devices.

The Zigbee Cluster Library Specification defines the commands specific to each cluster. A command can be sent to a device, to a group, or throughout the network.

TuyaOS provides the APIs for sending commands and callback functions to invoke when commands are received. Unicast, multicast, and broadcast apply to both command receiving and sending

After a command is sent, the application layer provides TuyaOS with function parameters that specify whether the command reception status is required. If it is required, TuyaOS invokes a callback function to notify the application layer whether the command is received.

Send raw DP

A DP is a collection of functions that are supported by a product created on the Tuya Developer Platform. Each DP is identified by a DPID. This is how Tuya’s things data model works.

A Zigbee gateway communicates with the cloud in the format of DPs. The gateway acts as a translator between Tuya’s DPs and the Zigbee protocol. The following section describes this communication process:

  • The cloud sends Tuya’s DP commands to the Zigbee gateway. Then, the gateway translates the commands into Zigbee-compatible commands and sends them to the associated Zigbee sub-devices.

  • After Zigbee sub-devices report status using Zigbee-compatible commands, the gateway converts the reported content into Tuya’s DPs and forwards them to the cloud.

    The following diagram shows how this process works.

    Data Transfer

Typically, if a DP is covered by the Zigbee Cluster Library Specification, the Zigbee gateway communicates with its sub-devices based on the commands specified in this specification. On the Tuya Developer Platform, each product is assigned standard DPs. You can additionally define custom DPs for a product. For more information, see Product Functions.

  • Standard DP: The gateway interacts with its sub-devices based on generic attributes or commands. Standard or private attributes or commands are supported.
  • Custom DP: The gateway interacts with its sub-devices based on pass-through commands defined by Tuya. In this process, the gateway does not convert between Tuya’s DPs and Zigbee-compatible commands. Instead, data is passed through without any alteration or interpretation. For more information, see specific TuyaOS development guidelines.

Support and help

If you have any problems with TuyaOS development, you can post your questions in the Tuya Developer Forum.