Help Center > > Developer Guide> SDK Usage Guide on the Device Side> LiteOS SDK Integration Development Guide> Processfor Connecting Devices to OceanConnect on the Device Side> Creating a Data Reporting Task

Creating a Data Reporting Task

Updated at: Jun 26, 2019 GMT+08:00

After initializing Agent Tiny, create a data reporting task function app_data_report() by calling the creat_report_task() function.

    UINT32 creat_report_task()
     {
         UINT32 uwRet = LOS_OK;
         TSK_INIT_PARAM_S task_init_param;
         UINT32 TskHandle;
         task_init_param.usTaskPrio = 1;
         task_init_param.pcName = "app_data_report";
         task_init_param.pfnTaskEntry = (TSK_ENTRY_FUNC)app_data_report;
         task_init_param.uwStackSize = 0x400;
         uwRet = LOS_TaskCreate(&TskHandle, &task_init_param);
         if(LOS_OK != uwRet)
         {
             return uwRet;
         }
         return uwRet;
     }

In the app_data_report() function, assign a value to the reported data structure data_report_t, including the data buffer address buf, callback function callback called after the ACK response is received from a platform, data cookie, data length len, and data reporting type type (set to APP_DATA by default).

    uint8_t buf[5] = {0, 1, 6, 5, 9};
     data_report_t report_data;
     int ret = 0;
     int cnt = 0;
     report_data.buf = buf;
     report_data.callback = ack_callback;
     report_data.cookie = 0;
     report_data.len = sizeof(buf);
     report_data.type = APP_DATA;

After a value is assigned to the report_data parameter, data can be reported by calling the atiny_data_report() function.

Function

Description

int atiny_data_report(void* phandle, data_report_t* report_data)

Function for reporting data of device-cloud interconnect components, which is implemented by device-cloud interconnect components and invoked by devices. This function is used to report device application data. The function is blocked and cannot be used when being interrupted. The parameters involved are as follows:

Parameter list: phandle is the Agent Tiny handle obtained by calling the initialization function atiny_init(). report_data is the reported data structure.

Return value: Integer variable, indicating that the data reporting is successful or failed.

The implementation method of a report task in the sample code is as follows:

    while(1)
     {
         report_data.cookie = cnt;
         cnt++;
         ret = atiny_data_report(g_phandle, &report_data);   //Data reporting function
         ATINY_LOG(LOG_DEBUG, "data report ret: %d\n", ret);
         (void)LOS_TaskDelay(250 * 8);
     }

Did you find this page helpful?

Submit successfully!

Thank you for your feedback. Your feedback helps make our documentation better.

Failed to submit the feedback. Please try again later.

Which of the following issues have you encountered?







Please complete at least one feedback item.

Content most length 200 character

Content is empty.

OK Cancel