设备管理 IoTDM(联通用户专用)-Agent Lite SDK使用指南(Java)(联通用户专用):非直连设备状态更新

时间:2023-11-01 16:20:05

非直连设备状态更新

注册观察者对非直连设备状态更新结果进行相应处理。

123456
//注册观察者AgentLiteHub agentLiteHub = AgentLiteHub.getInstance();HubService hubService = HubService.getInstance();hubService.registerObserver(agentLiteHub);//sensor状态更新agentLiteHub.updataDeviceStatus();

非直连设备添加上时,一般情况下是“离线”状态。所以在非直连设备添加成功后,或者在非直连设备上报数据前,要调用HubService.updateDeviceStatus(int cookie, String deviceId, String status, String statusDetail)进行设备状态更新。

 1 2 3 4 5 6 7 8 91011
public void updataDeviceStatus() {System.out.println(" =============  updataDeviceStatus  ============== ");    int cookie;    Random random = new Random();    cookie = random.nextInt(65535);    String sensorId = GatewayInfo.getSensorId();    System.out.println("cookie = " + cookie);    System.out.println("sensorId = " + sensorId);    HubService.updateDeviceStatus(cookie, sensorId, "ONLINE", "NONE");}
support.huaweicloud.com/devg-IoT/iot_02_5118.html