Help Center > > API Reference> AgentLite API Reference (Android)> APIs> Management of Non-Directly Connected Devices on a Gateway> Updating Device Status

Updating Device Status

Updated at: Aug 28, 2019 GMT+08:00

API Function

This API is used to update status information about devices, including directly connected devices 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 login 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 developers 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

Identifies a device.

status

Mandatory

String

Specifies the device status.

  • ONLINE: The device is online.
  • OFFLINE: The device is offline.

statusDetail

Mandatory

String

Provides the detailed device status information.

  • NONE
  • CONFIGURATION_PENDING
  • COMMUNICATION_ERROR
  • CONFIGURATION_ERROR
  • BRIDGE_OFFLINE
  • FIRMWARE_UPDATING
  • DUTY_CYCLE
  • NOT_ACTIVE

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

Specifies the device status update result.

HUB_IE_DEVICEID

Identifies a device.

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.
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);

Did you find this page helpful?

Submit successfully!

Thank you for your feedback. Your feedback helps make our documentation better.

Failed to submit the feedback. Please try again later.

Which of the following issues have you encountered?







Please complete at least one feedback item.

Content most length 200 character

Content is empty.

OK Cancel