Receiving a Command
API Function
This API is used to register the broadcast for receiving control commands from the IoT platform.
API Description
1 |
DataTransService.TOPIC_COMMAND_RECEIVE;
|
Parameter Description
N/A
Output
Broadcast Name |
Broadcast Parameter |
Member |
Description |
---|---|---|---|
TOPIC_COMMAND_RECEIVE |
IotaMessage (Obtained by using intent.getSerializableExtra(DataTransService.DATATRANS_BROADCAST_IE_IOTAMSG)) |
DATATRANS_IE_REQUESTID |
Identifies a request. |
DATATRANS_IE_DEVICEID |
Specifies the logical ID of a device, which is allocated by the IoT platform when the device is added. |
||
DATATRANS_IE_SERVICEID |
Identifies a service. |
||
DATATRANS_IE_METHOD |
Specifies the service method. |
||
DATATRANS_IE_CMDCONTENT |
Specifies the 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);
|
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot