接收设备命令
接口功能
注册设备命令接收广播来接收处理平台下发的控制命令。
接口描述
1
|
DataTransService.TOPIC_COMMAND_RECEIVE; |
返回结果
广播名称 |
广播参数 |
成员 |
描述 |
---|---|---|---|
TOPIC_COMMAND_RECEIVE |
IotaMessage (使用intent.getSerializableExtra(DataTransService.DATATRANS_BROADCAST_IE_IOTAMSG)方法获取) |
DATATRANS_IE_REQUESTID |
请求ID。 |
DATATRANS_IE_DEVICEID |
设备逻辑ID,在设备添加时由平台分配。 |
||
DATATRANS_IE_SERVICEID |
服务ID。 |
||
DATATRANS_IE_METHOD |
服务方法。 |
||
DATATRANS_IE_CMDCONTENT |
命令内容。 |
示例
开发者注册广播接收器对设备命令接收结果进行相应的处理。
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”)) { //根据Proflie定义的命令参数,使用Json组件解析cmdContent //Send command to Switch } return; } }; mLocalBroadcastManager = LocalBroadcastManager.getInstance(this); IntentFilter filterReceiveCmd = new IntentFilter(DataTransService.TOPIC_COMMAND_RECEIVE); mLocalBroadcastManager.registerReceiver(mReceiveCmd, filterReceiveCmd); |