Last Updated on : 2024-06-25 03:37:13download
The typical functionality of a low power device is to report device status and important events. However, users may need to set device parameters or control the device remotely. In this case, the cloud will send a data point (DP) command to the device. If the device is in sleep mode, it will fail to receive the command.
To solve this problem, the DP data can be cached in the cloud. When the low power device wakes up, it can proactively retrieve the cached data from the cloud. This can reduce parameter setting failures for low power devices and simplify user operations.
This solution enables the device to retrieve the cached data after waking up, so it is not suitable for time-sensitive use cases.
The process of retrieving the cached DP data from the cloud:
The mobile app sends the DP command to the cloud.
The cloud caches the received DP command.
After the device wakes up, it queries and retrieves the cached DP data from the cloud.
The device acts on the DP commands and reports the status of the respective DP.
The cached DP data is deleted automatically after it is sent to the device. If no DP data is cached in the cloud, the device will receive a null response to its query.
smart_frame.h
Create a product on the Tuya Developer Platform and then enter the product development process. In Function Definition > Advanced Functions, enable Low Power DP Cache Delivery.
If you cannot find Low Power DP Cache Delivery in advanced functions, this is because the product solution does not have this function bound. To request binding them with your product, contact your account manager or submit a service ticket.
After the device wakes up and gets connected, you can call query cached DP for low power devices.
OPRT_OK
indicates the communication with the cloud works fine but does not mean the cached DP data is obtained.obj_dps
or raw_dps
has a value, it indicates the cached DP data is obtained.This API is used to retrieve the cached DP data from the cloud.
/**
* @brief Definition of received structured dp
*/
typedef struct {
/** see DP_CMD_TYPE_E */
DP_CMD_TYPE_E cmd_tp;
/** see DP_TRANS_TYPE_T */
DP_TRANS_TYPE_T dtt_tp;
/** if(NULL == cid) then the cid represents gwid */
CHAR_T *cid;
/** mb id */
CHAR_T *mb_id;
/** count of dp */
UINT_T dps_cnt;
/** the dp data */
TY_OBJ_DP_S dps[0];
} TY_RECV_OBJ_DP_S;
/**
* @brief Definition of structured dp
*/
typedef struct {
/** dp id */
BYTE_T dpid;
/** data len */
UINT_T len;
/** dp value, see TY_OBJ_DP_VALUE_U */
BYTE_T* data;
} TY_RAW_DP_S;
/**
* @brief Definition of received raw dp
*/
typedef struct {
/** see DP_CMD_TYPE_E */
DP_CMD_TYPE_E cmd_tp;
/** see DP_TRANS_TYPE_T */
DP_TRANS_TYPE_T dtt_tp;
/** if(NULL == cid) then the cid represents gwid */
CHAR_T *cid;
/** mb id */
CHAR_T *mb_id;
/** count of dp */
UINT_T dps_cnt;
/** the dp data */
TY_RAW_DP_S dps[0];
} TY_RECV_MULTI_RAW_DP_S;
/**
* @brief Query dp for low power
*
* @param[in] dps: The DP ID to query.
* @param[in] cnt: The number of DP IDs to query.
* @param[out] obj_dps: The cached object-type DP data.
* @param[out] raw_dps: The cached raw-type DP data.
*
* @note This API is used for querying DP for low power
*
* @return OPRT_OK on success. Others on error, please refer to tuya_error_code.h
*/
OPERATE_RET sf_dp_low_power_query(IN CONST UCHAR_T *dps, IN CONST UINT_T cnt,
OUT TY_RECV_OBJ_DP_S **obj_dps, OUT TY_RECV_MULTI_RAW_DP_S **raw_dps);
service_query_lowpower_dp/example_query_lowpower_dp.c
in TuyaOS example collection contains the example code.
Yes, you can.
No, it is not possible. Only the last command set for a specific DP of the device will be cached.
It is possible for TuyaOS v3.6.0 and later. For frameworks prior to v3.6.0, you can retrieve the cached data for one raw-type DP in a single request. You can retrieve the cached data for multiple object-type DPs
in a single request.
Is this page helpful?
YesFeedbackIs this page helpful?
YesFeedback