Data Pass-Through

Last Updated on : 2023-12-21 02:43:00download

This topic describes how data pass-through works on Bluetooth devices.

Concepts

The communication between the Bluetooth device and the Tuya-enabled mobile app is typically based on DP data. However, DP data communication is not applicable to specific scenarios. In this case, the data pass-through protocol is used to exchange data in the user-defined format. The mobile app directly sends the received data to the panel or cloud without parsing the data.

For example, with the pass-through channel, you can bind or unbind a Bluetooth lock to or from an accessory and get offline operation records. Bluetooth tags can authorize devices during a rework. For products that have been rolled out, data pass-through can be an alternative when it is not possible to add a new feature by defining a DP.

Features

The app must parse the DP data before sending it to the panel or cloud. However, data pass-through does not require parsing as it transfers raw data directly.

Data Pass-Through

Data structure

tuya_ble_passthrough_data_t

typedef struct {
    UINT16_T data_len;
    UINT8_T *p_data;
} tuya_ble_passthrough_data_t;
  • data_len: The length of the pass-through data.

  • p_data: The pass-through data.

API description

Receive pass-through data

case TUYA_BLE_CB_EVT_DATA_PASSTHROUGH

Send pass-through data

API description

tuya_ble_status_t tuya_ble_data_passthrough(UINT8_T *p_data, UINT32_T len);

Parameter description

Parameter Description
p_data The pass-through data.
len The length of the pass-through data.

How to use

Communication process

Data Pass-Through

Code development

The data pass-through channel is enabled by default. However, for the data pass-through to work, both the panel and cloud service must also support it. Before you use this feature, consult your product manager.

Receive and send data

STATIC VOID_T tuya_ble_protocol_callback(tuya_ble_cb_evt_param_t* event)
{
    switch (event->evt) {
        case TUYA_BLE_CB_EVT_DATA_PASSTHROUGH: {
            // do your things
            tuya_ble_data_passthrough(event->ble_passthrough_data.p_data, event->ble_passthrough_data.data_len);
        } break;

        ……
    }
    ……
}

Support and help

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