Updated on 2022-02-24 GMT+08:00

Receiving Device Commands

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.