Updated on 2022-02-24 GMT+08:00

Updating Device Status

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

NOTE:

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 status is updated successfully. The device status is updated successfully only after the HubService broadcast is received.

Example

Call this API to update the device status.

1
HubService.deviceStatusUpdate(0, deviceId, "ONLINE", "NONE");

Implement the observer API provided by the AgentLite before calling this API.

1
2
3
4
5
public class Subscribe implements MyObserver {
    public Subscribe (Observable hubService) {
        hubService. registerObserver (this);
    }
    @Override Same as those used for adding a device.