APIs and Examples

Last Updated on : 2022-11-24 09:20:29download

This topic describes the data reporting API and provides examples of how to report data to the cloud using the API.

API

typedef enum
{
    DP_TYPE_RAW		= 0,                /* tuya datapoint type raw */
    DP_TYPE_BOOL	= 1,                /* tuya datapoint type bool */
    DP_TYPE_VALUE	= 2,                /* tuya datapoint type value */
    DP_TYPE_STRING	= 3,                /* tuya datapoint type string */
    DP_TYPE_ENUM	= 4,                /* tuya datapoint type enum */
    DP_TYPE_BITMAP	= 5,                /* tuya datapoint type bitmap */
    TY_DP_TYPE,
}TY_LOCK_DP_TYPE_E;

typedef enum
{
    TIME_TYPE_VOID	 = 0,               /* tuya time type null */
    TIME_TYPE_LOCAL	 = 1,               /* tuya time type local */
    TIME_TYPE_GREEKN = 2,               /* tuya time type green */
}TY_LOCK_TIME_TYPE_E;

typedef struct{
    TY_LOCK_TIME_TYPE_E   type;         /* tuya time type*/
    POSIX_TM_S time;                    /* tuya time, if type is TIME_TYPE_VOID, time is invalid*/
}DP_TIME_S;

typedef struct {
    UCHAR_T			    dpid;	        /* tuya datapoint id */
    TY_LOCK_DP_TYPE_E	type;	        /* tuya datapoint type */
    WORD_T			    data_len;	    /* tuya datapoint len */
    UCHAR_T			    *data;	        /* tuya datapoint data */
}TY_LOCK_DP_S;

/**
 * Init tuya lock datapoint report.
 * @return Function Operation Result  OPRT_OK is ok other is fail 
 */
__SVC_LOCK_DP_REPORT_EXT \
OPERATE_RET tuya_svc_lock_dp_report_init(VOID);

/**
 * Tuya datapoint wil be reported synchronously.
 * @param  dp_data[]    datapoint.
 * @param  dp_data_num  datapoint number.
 * @param  time         the time of datapoint.
 * @param  timeout      time out,unit s.
 * @return Function Operation Result  OPRT_OK is ok other is fail 
 */
__SVC_LOCK_DP_REPORT_EXT \
OPERATE_RET tuya_svc_lock_dp_report_syn(IN TY_LOCK_DP_S dp_data[],IN UINT_T dp_data_num, DP_TIME_S *time,IN UINT_T timeout);

/**
 * Tuya datapoint wil be reported asynchronously.
 * @param  dp_data[]    datapoint.
 * @param  dp_data_num  datapoint number.
 * @param  time         the time of datapoint.
 * @return Function Operation Result  OPRT_OK is ok other is fail 
 */
__SVC_LOCK_DP_REPORT_EXT \
OPERATE_RET tuya_svc_lock_dp_report_asyn(IN TY_LOCK_DP_S dp_data[],IN UINT_T dp_data_num, DP_TIME_S *time);

/**
 * Tuya datapoint wil be reported synchronously, and it will be stored when sending fails.
 * @param  dp_data[]    datapoint.
 * @param  dp_data_num  datapoint number.
 * @param  time         the time of datapoint.
 * @param  timeout      time out,unit s.
 * @return Function Operation Result  OPRT_OK is ok other is fail 
 */
__SVC_LOCK_DP_REPORT_EXT \
OPERATE_RET tuya_svc_lock_dp_report_with_record_syn(IN TY_LOCK_DP_S dp_data[],IN UINT_T dp_data_num, DP_TIME_S *time,IN UINT_T timeout);

/**
 * Tuya datapoint wil be reported asynchronously, and it will be stored when sending fails.
 * @param  dp_data[]    datapoint.
 * @param  dp_data_num  datapoint number.
 * @param  time         the time of datapoint.
 * @return Function Operation Result  OPRT_OK is ok other is fail 
 */
__SVC_LOCK_DP_REPORT_EXT \
OPERATE_RET tuya_svc_lock_dp_report_with_record_asyn(IN TY_LOCK_DP_S dp_data[],IN UINT_T dp_data_num, DP_TIME_S *time);

/**
 * Tuya one datapoint stored in the flash wil be reported synchronously, and it will be deleted when sending success.
 * @param  timeout      time out,unit s.
 * @return Function Operation Result  OPRT_OK is ok other is fail 
 */
__SVC_LOCK_DP_REPORT_EXT \
OPERATE_RET tuya_svc_lock_dp_report_one_flash_record_syn(IN UINT_T timeout);

/**
 * Tuya one datapoint stored in the flash wil be reported asynchronously, and it will be deleted when sending success.
 * @return Function Operation Result  OPRT_OK is ok other is fail 
 */
__SVC_LOCK_DP_REPORT_EXT \
OPERATE_RET tuya_svc_lock_dp_report_one_flash_record_asyn(VOID);


/**
 * Get the number of datapoints in the flash.
 * @return the number of datapoints in the flash
 */
__SVC_LOCK_DP_REPORT_EXT \
UINT_T tuya_svc_lock_get_flash_record_num(VOID);

/**
 * clean the datapoints in the flash.
 * @return Function Operation Result  OPRT_OK is ok other is fail 
 */
__SVC_LOCK_DP_REPORT_EXT \
OPERATE_RET tuya_svc_lock_clr_flash_record(VOID);

Examples

OPERATE_RET device_init(VOID)
{
    OPERATE_RET op_ret = OPRT_OK;
   // Initialize the data reporting component
    op_ret =  tuya_svc_lock_dp_report_init();
    if(OPRT_OK != op_ret) {
        PR_ERR("tuya_svc_lock_dp_report_init err:%d",op_ret);
        return op_ret;
    }
   TY_LOCK_DP_S lock_dp = {
           // The payload
  };
    UINT_T lock_dp_num = 1;
   op_ret = tuya_svc_lock_dp_report_syn(&lock_dp,lock_dp_num,NULL,5);
}