Help Center > > API Reference> AgentLite API Reference (C)> API Description> Receiving Device Commands

Receiving Device Commands

Updated at: Aug 28, 2019 GMT+08:00

API Function

This API is used to register the broadcast for receiving control commands from the IoT platform.

API Description

1
IOTA_TOPIC_SERVICE_COMMAND_RECEIVE/{deviceId};

Parameter Description

For details, see IEs in the EN_IOTA_DATATRANS_IE_TYPE Messages.

Output

None

Example

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
//Developers call this API to register the function for subsequent processing after device commands are received.
HW_iNT Switch_CommandRecvtHandler(HW_UiNT uiCookie, HW_MSG pstMsg) 
{
    HW_cHAR *pcMethod, *pcServiceId, *pcCmdContent, *pcDeviceId;
    pcDeviceId = HW_MsgGetStr(pstMsg, EN_IOTA_DATATRANS_IE_DEVICEID);
    pcServiceId = HW_MsgGetStr(pstMsg, EN_IOTA_DATATRANS_IE_SERVICEID);
    pcMethod = HW_MsgGetStr(pstMsg, EN_IOTA_DATATRANS_IE_METHOD);
    pcCmdContent = HW_MsgGetStr(pstMsg, EN_IOTA_DATATRANS_IE_CMDCONTENT);
if (strcmp(pcServiceId, "switch"))
    {
//Developers call this API to use the JSON components to parse pcCmdContent based on command parameters in the profile.
        //Send command to Switch
    }
    return 0;
}
//Developers call this API to register the broadcast for receiving device commands immediately after the device is added.
HW_BroadCastReg("IOTA_TOPIC_SERVICE_CMD_RECEIVE/XXXX_XXXX_XXXX_XXXX",
Device_AddResultHandler);

After a device is added, developers must register the broadcast for receiving commands for the device. The broadcast is in format of IOTA_TOPIC_SERVICE_CMD_RECEIVE/Device ID. When the AgentLite receives commands delivered by the IoT platform to the device, it broadcasts these commands to the broadcast processing function registered by the device. If the commands do not need to be dispatched by device ID, the broadcast can be in format of IOTA_TOPIC_SERVICE_CMD_RECEIVE.

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