Updating the Device Status
API Function
This API is used to update status information about devices, including directly and indirectly connected devices managed by the IoT platform. The device status can be updated through this API when the device is offline or online.
The status of directly connected devices is updated based on the device connection status. If a directly connected device is disconnected from the IoT platform, its status becomes offline. If a directly connected device is connected or reconnected to the IoT platform, its status becomes online and does not need to be updated through this API. Therefore, it is recommended that you call this API to update the status of indirectly connected devices.
API Description
1 | public static boolean updateDeviceStatus(int cookie, String deviceId, String status, String statusDetail);
|
Class
HubService
Parameter Description
| Parameter | Mandatory or Optional | Type | Description |
|---|---|---|---|
| cookie | Optional | int | The value ranges from 1 to 65535. |
| deviceId | Mandatory | String | Identifier of a device. |
| status | Mandatory | String | Status of the device.
|
| statusDetail | Mandatory | String | Details about the device status.
|
Return Value
| Return Value | Description |
|---|---|
| true | Success |
| false | Failure |
Output
| Broadcast Name | Broadcast Parameter | Member | Description |
|---|---|---|---|
| TOPIC_DEVSTATUS_UPDATA_RSP | IotaMessage object (Obtained by using intent.getSerializableExtra(HubService.HUB_BROADCAST_IE_IOTAMSG)) | HUB_IE_RESULT | Device status update result. |
| HUB_IE_DEVICEID | Identifier of a device. |
HUB_IE_RESULT:
| Enumerated Item | Value | Type | Description |
|---|---|---|---|
| HUB_RESULT_SUCCESS | 0 | N/A | The device is added or deleted. |
| HUB_RESULT_DEVICE_EXIST | 1 | N/A | The device already exists. |
| HUB_RESULT_DEVICE_NOTEXIST | 2 | N/A | The device does not exist. |
| HUB_RESULT_DEVICE_FAILED | 255 | N/A | The execution fails. |
Example
1 | HubService.deviceStatusUpdate(0, deviceId, "ONLINE", "NONE");
|
The device waits for the command execution result.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | //Register a broadcast receiver to process the device status update result.
BroadcastReceiver mReceiverDevStatus;
mReceiverDevStatus = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
//Obtain IotaMessage.
IotaMessage iotaMsg = (IotaMessage)intent.getSerializableExtra(HubService.HUB_BROADCAST_IE_IOTAMSG);
//Obtain the error code of the response.
String result = iotaMsg.getString(HubService.HUB_IE_RESULT);
String deviceId = iotaMsg.getString(HubService.HUB_IE_DEVICEID);
...
return true;
}
}
mLocalBroadcastManager = LocalBroadcastManager.getInstance(this);
IntentFilter filterDiscon= new IntentFilter(HubService. TOPIC_DEVSTATUS_UPDATA_RSP);
mLocalBroadcastManager.registerReceiver(mReceiverDevStatus, filterDiscon);
|
Last Article: Adding a Device
Next Article: Deleting a Device
Did this article solve your problem?
Thank you for your score!Your feedback would help us improve the website.