Receiving a Command
API Function
This API is used to register the broadcast for receiving commands from the IoT platform.
API Description
1 | DataTransService.TOPIC_COMMAND_RECEIVE;
|
Output
| Broadcast Name | Broadcast Parameter | Member | Description |
|---|---|---|---|
| TOPIC_COMMAND_RECEIVE | IotaMessage (Obtained by using intent.getSerializableExtra(DataTransService.DATATRANS_BROADCAST_IE_IOTAMSG)) | DATATRANS_IE_REQUESTID | Identifier of a request. |
| DATATRANS_IE_DEVICEID | Logical ID of a device, which is allocated by the IoT platform when the device is added. | ||
| DATATRANS_IE_SERVICEID | Identifier of a service. | ||
| DATATRANS_IE_METHOD | Service method. | ||
| DATATRANS_IE_CMDCONTENT | Command content. |
Example
Register a broadcast receiver to process the command reception.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | BroadcastReceiver mReceiveCmd;
mReceiveCmd = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
//Do Something
IotaMessage iotaMsg = (IotaMessage)intent.getSerializableExtra(DataTransService. DATATRANS_BROADCAST_IE_IOTAMSG);
String requstId = iotaMsg.getString(DataTransService.DATATRANS_IE_REQUESTID);
String deviceId = iotaMsg.getString(DataTransService.DATATRANS_IE_DEVICEID);
String serviceId = iotaMsg.getString(DataTransService.DATATRANS_IE_SERVICEID);
String method = iotaMsg.getString(DataTransService.DATATRANS_IE_METHOD);
String cmdContent = iotaMsg.getString(DataTransService.DATATRANS_IE_CMDCONTENT);
if (serviceId.equals("switch"))
{
//Use the JSON component to parse cmdContent based on the command parameters defined by the profile.
//Send command to Switch
}
return;
}
};
mLocalBroadcastManager = LocalBroadcastManager.getInstance(this);
IntentFilter filterReceiveCmd
= new IntentFilter(DataTransService.TOPIC_COMMAND_RECEIVE);
mLocalBroadcastManager.registerReceiver(mReceiveCmd, filterReceiveCmd);
|
Last Article: Reporting Device Data
Next Article: Releasing Data
Did this article solve your problem?
Thank you for your score!Your feedback would help us improve the website.