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

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