Deleting a Device
API Function
This API is used to delete indirectly connected devices from the IoT platform.
API Description
1 | public static boolean rmvDevice(int cookie, String deviceId);
|
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. |
Return Value
| Return Value | Description |
|---|---|
| true | Success |
| false | Failure |
Return values only show API calling results. For example, the return value true indicates that the API is called successfully but does not indicate that the device is deleted successfully. The device is deleted successfully only after the TOPIC_RMVDEV_RSP broadcast is received.
Output
| Broadcast Name | Broadcast Parameter | Member | Description |
|---|---|---|---|
| TOPIC_ RMVDEV_RSP | IotaMessage (Obtained by using intent.getSerializableExtra(HubService.HUB_BROADCAST_IE_IOTAMSG)) | HUB_IE_RESULT | Device deletion result. |
| HUB_IE_COOKIE | The value ranges from 1 to 65535. |
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
Call this API to delete a device.
1 | HubService.rmvDevice(122, deviceId);
|
The device waits for the result.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | //java code
BroadcastReceiver mRmvdeviceRsp;
mRmvdeviceRsp = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
//Do Something
IotaMessage iotaMsg = (IotaMessage)intent.getSerializableExtra(HubService. HUB_BROADCAST_IE_IOTAMSG);
int result = iotaMsg.getUint(HubService.HUB_IE_RESULT, 0);
int cookie = iotaMsg.getUint(HubService.HUB_IE_COOKIE, 0);
return;
}
};
mLocalBroadcastManager = LocalBroadcastManager.getInstance(this);
IntentFilter filterRmvDev = new IntentFilter(HubService.TOPIC_RMVDEV_RSP);
mLocalBroadcastManager.registerReceiver(mDeldeviceRsp, filterRmvDev);
|
Last Article: Updating the Device Status
Next Article: Reporting Device Data
Did this article solve your problem?
Thank you for your score!Your feedback would help us improve the website.