Data Point (DP) Control

Last Updated on : 2022-11-24 09:20:19

This topic describes the APIs used to implement the functionality of data points (DPs).

Structs

TY_RECV_RAW_DP_S

typedef struct {
    DP_CMD_TYPE_E cmd_tp;
    DP_TRANS_TYPE_T dtt_tp;
    CHAR_T *cid;
    BYTE_T dpid;
    CHAR_T *mb_id;
    UINT_T len;
    BYTE_T data[0];
} TY_RECV_RAW_DP_S;

Functional specification

The commands of the raw type.

Member description

Parameter name Description
cmd_tp The types of commands:
  • DP_CMD_LAN: The command is issued by LAN-based device control.
  • DP_CMD_MQ: The command is issued by remote device control over MQTT.
  • DP_CMD_TIMER: The command is issued by local schedule.
  • DP_CMD_SCENE_LINKAGE: The command is issued by local linkage.
  • DP_CMD_RELIABLE_TRANSFER: The command is issued by the retransmission mechanism.
  • DP_CMD_BT: The command is issued over Bluetooth.
  • DP_CMD_SCENE_LINKAGE_LAN: The command is issued by LAN-based linkage.
dtt_tp The types of transmission:
  • DTT_SCT_UNC: Unicast.
  • DTT_SCT_BNC: Broadcast.
  • DTT_SCT_MNC: Multicast.
  • DTT_SCT_SCENE: Scene.
cid The unique identifier of the device.
  • If cid is NULL, it indicates this is a gateway.
  • If cid is not NULL, it indicates this is a sub-device.
dpid The ID of the data point.
mb_id The ID of the group. This parameter is valid when dtt_tp is DTT_SCT_MNC.
len The length of raw data.
data The raw data.

TY_RECV_OBJ_DP_S

typedef struct {
    DP_CMD_TYPE_E cmd_tp;
    DP_TRANS_TYPE_T dtt_tp;
    CHAR_T *cid;
    CHAR_T *mb_id;
    UINT_T dps_cnt;
    TY_OBJ_DP_S dps[0];
} TY_RECV_OBJ_DP_S;

Functional specification

The commands of the object type.

Member description

Member Description
cmd_tp The types of commands:
  • DP_CMD_LAN: The command is issued by LAN-based device control.
  • DP_CMD_MQ: The command is issued by remote device control over MQTT.
  • DP_CMD_TIMER: The command is issued by local schedule.
  • DP_CMD_SCENE_LINKAGE: The command is issued by local linkage.
  • DP_CMD_RELIABLE_TRANSFER: The command is issued by the retransmission mechanism.
  • DP_CMD_BT: The command is issued over Bluetooth.
  • DP_CMD_SCENE_LINKAGE_LAN: The command is issued by LAN-based linkage.
dtt_tp The types of transmission:
  • DTT_SCT_UNC: Unicast.
  • DTT_SCT_BNC: Broadcast.
  • DTT_SCT_MNC: Multicast.
  • DTT_SCT_SCENE: Scene.
cid The unique identifier of the device.
  • If cid is NULL, it indicates this is a gateway.
  • If cid is not NULL, it indicates this is a sub-device.
mb_id The ID of the group. This parameter is valid when dtt_tp is DTT_SCT_MNC.
dps_cnt The number of DPs.
dps An array of DPs. For more information, see TY_OBJ_DP_S.

TY_OBJ_DP_S

typedef struct {
    BYTE_T dpid;
    DP_PROP_TP_E type;
    TY_OBJ_DP_VALUE_U value;
    UINT_T time_stamp;
} TY_OBJ_DP_S;

Functional specification

The DP of the object type.

Member description

Member Description
dpid The ID of the data point.
type The data types of DP:
  • PROP_BOOL: Boolean.
  • PROP_VALUE: Value.
  • PROP_STR: String.
  • PROP_ENUM: Enum.
  • PROP_BITMAP: Bitmap.
value The value of a DP, in union type. For more information, see TY_OBJ_DP_VALUE_U.
time_stamp The timestamp.

TY_OBJ_DP_VALUE_U

typedef union {
    INT_T dp_value;
    UINT_T dp_enum;
    CHAR_T *dp_str;
    BOOL_T dp_bool;
    UINT_T dp_bitmap;
} TY_OBJ_DP_VALUE_U;

Functional specification

A union of DP values of the object type.

Member description

Member Description
dp_value This parameter is valid when the data type of a DP is PROP_VALUE.
dp_enum This parameter is valid when the data type of a DP is PROP_ENUM.
dp_str This parameter is valid when the data type of a DP is PROP_STR.
dp_bool This parameter is valid when the data type of a DP is PROP_BOOL.
dp_bitmap This parameter is valid when the data type of a DP is PROP_BITMAP.

TY_DP_QUERY_S

typedef struct {
    CHAR_T *cid;
    UINT_T cnt;
    BYTE_T dpid[0];
} TY_DP_QUERY_S;

Functional specification

Queries the DP information.

Member description

Parameter name Description
cid The unique identifier of the device.
  • If cid is NULL, it indicates this is a gateway.
  • If cid is not NULL, it indicates this is a sub-device.
cnt The number of DPs. If cnt is 0, it means to query all the DPs defined for a device.
dpid The list of DP IDs to query.

TY_IOT_DP_CBS_S

typedef struct  {
    DEV_OBJ_DP_CMD_CB   obj;
    DEV_RAW_DP_CMD_CB   raw;
    DEV_DP_QUERY_CB     query;
} TY_IOT_DP_CBS_S;

Functional specification

The DP callbacks.

Member description

Member Description
obj For more information, see dev_obj_dp_cb.
raw For more information, see dev_raw_dp_cb.
query For more information, see dev_dp_query_cb.

TY_DP_REPORT_CBS_S

typedef struct {
	VOID (*obj_dp_rept_cb)(CONST CHAR_T *dev_id, CONST TY_OBJ_DP_S *dps, CONST UINT_T dp_cnt);
	VOID (*raw_dp_rept_cb)(CONST CHAR_T *dev_id, BYTE_T dpid, CONST BYTE_T *data, UINT_T len);
} TY_DP_REPORT_CBS_S;

Functional description

The DP reporting callbacks.

Member description

Member Description
obj_dp_rept_cb The callback for DPs of the object type. Its parameters are the same as those of dev_report_dp_json_async.
raw_dp_rept_cb The callback for DPs of the raw type. Its parameters are the same as those of dev_report_dp_raw_sync.

API reference

tuya_iot_reg_dp_cb

OPERATE_RET tuya_iot_reg_dp_cb(IN CONST DP_DEV_TYPE_T subcribe_dev_type,
                               IN GW_PERMIT_DEV_TP_T tp,
                               TY_IOT_DP_CBS_S *cb)

Functional description

Registers the DP event handler callback.

Parameter description

Parameter name Description
sub_dev_type The types of DP event handlers:
  • DP_DEV: Process the DP of the sub-device only.
  • DP_GW: Process the DP of the gateway only.
  • DP_GW_DEV: Process the DP of either the sub-device or the gateway.
tp The types of the sub-device:
  • If the value is less than 10, this parameter is reserved for internal use.
  • If the value is greater than or equal to 10, this parameter can be user-defined.
cb The DP callbacks.

Return value

Return value Description
OPRT_OK Success
Error code For more information about the error code, see tuya_error_code.h.

dev_report_dp_json_async

OPERATE_RET dev_report_dp_json_async(IN CONST CHAR_T *dev_id,
                                     IN CONST TY_OBJ_DP_S *dp_data,
                                     IN CONST UINT_T cnt)

Functional description

Reports the status of DPs of the object type asynchronously.

Parameter description

Parameter name Description
dev_id The device ID.
dp_data The DP data. For more information, see TY_OBJ_DP_S.
cnt The number of DPs.

Return value

Return value Description
OPRT_OK Operation succeeded.
Error code For more information about the error code, see tuya_error_code.h.

dev_report_dp_raw_sync

OPERATE_RET dev_report_dp_raw_sync (IN CONST CHAR_T *dev_id,
                                    IN CONST BYTE_T dpid,
                                    IN CONST BYTE_T *data,
                                    IN CONST UINT_T len,
                                    IN CONST UINT_T timeout)

Functional description

Reports the status of DPs of the raw type synchronously. Make sure that the data delivery is reliable.

Parameter description

Parameter name Description
dev_id The device ID.
dpid The ID of the data point.
data The raw data.
len The length of raw data.
timeout The timeout period for interface blocking.

Return value

Return value Description
OPRT_OK Operation succeeded.
Error code For more information about the error code, see tuya_error_code.h.

dev_report_dp_stat_sync

#define dev_report_dp_stat_sync(dev_id, dp_data, cnt, timeout) \
    dev_report_dp_stat_sync_extend(dev_id, dp_data, cnt, timeout, TRUE)
OPERATE_RET dev_report_dp_stat_sync_extend(IN CONST CHAR_T *dev_id,
                                           IN CONST TY_OBJ_DP_S *dp_data,
                                           IN CONST UINT_T cnt,
                                           IN CONST UINT_T timeout,
                                           IN CONST BOOL_T enable_auto_retrans)

Functional description

Reports the status of DPs of the object type synchronously. Make sure that the data delivery is reliable.

Parameter description

Parameter name Description
dev_id The device ID.
dp_data The DP data. For more information, see TY_OBJ_DP_S.
cnt The number of DPs.
timeout The timeout period for interface blocking.

Return value

Return value Description
OPRT_OK Operation succeeded.
Error code For more information about the error code, see tuya_error_code.h.

tuya_iot_dev_obj_cmd_send

OPERATE_RET tuya_iot_dev_obj_cmd_send(CONST TY_RECV_OBJ_DP_S *cmd)

Functional description

Sends DP commands of the object type locally.

Parameter description

Parameter name Description
cmd For more information, see TY_RECV_OBJ_DP_S.

Return value

Return value Description
OPRT_OK Operation succeeded.
Error code For more information about the error code, see tuya_error_code.h.

tuya_iot_dev_raw_cmd_send

OPERATE_RET tuya_iot_dev_raw_cmd_send(CONST TY_RECV_RAW_DP_S *cmd)

Functional description

Sends DP commands of the raw type locally.

Parameter description

Parameter name Description
cmd For more information, see TY_RECV_RAW_DP_S.

Return value

Return value Description
OPRT_OK Operation succeeded.
Error code For more information about the error code, see tuya_error_code.h.

tuya_iot_reg_dp_report_cb

OPERATE_RET tuya_iot_reg_dp_report_cb(TY_DP_REPORT_CBS_S *cbs)

Functional description

Registers the DP status reporting callback, which is used to get the data reported.

Parameter description

Parameter name Description
cbs For more information, see TY_DP_REPORT_CBS_S.

Return value

Return value Description
OPRT_OK Operation succeeded.
Error code For more information about the error code, see tuya_error_code.h.

Callback functions

dev_obj_dp_cb

VOID dev_obj_dp_cb(IN CONST TY_RECV_OBJ_DP_S *dp)

Functional description

A callback processes the DP command of the object type.

Parameter description

Parameter name Description
dp The commands of the object type. For more information, see TY_RECV_OBJ_DP_S.

Return value

Return value Description
VOID /

dev_raw_dp_cb

VOID dev_raw_dp_cb(IN CONST TY_RECV_RAW_DP_S *dp)

Functional description

A callback processes the DP command of the raw type.

Parameter description

Parameter name Description
dp The commands of the raw type. For more information, see TY_RECV_RAW_DP_S.

Return value

Return value Description
VOID /

dev_dp_query_cb

VOID dev_dp_query_cb(IN CONST TY_DP_QUERY_S *dp_qry)

Functional description

A callback queries the status of DP.

Parameter description

Parameter name Description
dp_qry The query for DP information. For more information, see TY_DP_QUERY_S.

Return value

Return value Description
VOID /