...
Code Block | ||
---|---|---|
| ||
GatewayClient gw = new GatewayClient(new ConnectionInfo(ConnectionType.ZIGBEE_UART, "/dev/ttyUSB0")); ... // This is an example of using the Protocol Passthrough API, with a zigbee message formed as a json string. // The zigbee message we're forming is a Zone Enroll Response Command (see ZCL Spec Section 8.2.2.3.1) Device device = gw.getDevice(id); Optional<Property> protocolProperty = device.getCachedProperty(PropertyNames.PROTOCOL_PROPERTY_NAME); if (protocolProperty.isPresent()) { Property p = protocolProperty.get(); JsonObject jsonObject = jsonParser.parse(p.getValue()).getAsJsonObject(); ZCLUnicastMessageBuilder builder = new ZCLUnicastMessageBuilder(); builder.setGatewayAPIVersion(GatewayClient.getApiVersion()); builder.setProtocolName("zigbee"); builder.setProtocolVersion(3); builder.setNodeID(jsonObject.get(ZigBeeMessageTypeAdapter.NODE_ID_KEY).getAsString()); builder.setEndpointID(jsonObject.get(ZigBeeMessageTypeAdapter.ENDPOINT_ID_KEY).getAsString()); builder.setClusterID(IAS_ZONE_CLUSTER_ID); builder.setResponseOptions(ZigBee.FrameConstants.RESPONSE_OPTIONS_APS_RESPONSE.toBitmap8()); builder.setFrameControl(ZigBee.FrameConstants.FRAME_CONTROL_CLIENT_TO_SERVER_CLUSTER_CMD.toBitmap8()); builder.setCommandID(ZONE_ENROLL_RESPONSE_ID); // Zone Enroll Response: // Field 1: 00 - enroll success // Field 2: 01 - zone id // therefore, final payload is: 0x0001 builder.setPayload("0x0001"); ZCLUnicastMessage message = builder.build(); device.sendProtocolMessage(message.toJson()) .thenAccept(jsonResponse -> System.out.println(jsonResponse)); } |
Upgrade API
startOtaUpgrade()
Usage
Notifies the remote device that an OTA image is available for upgrade.
Assumes that GatewayClient.registerOtaFile(...) API has been called first to register a valid OTA upgrade file that the remote device will accept.
Notes:
- All status messages and progress updates associated with the upgrade will be relayed through the callback that was registered using the GatewayClient.registerOtaProgressHandler(...) API.
- This is a non-blocking call.
- This method is thread-safe.
Parameters
None.
Returns
None.
All status messages and progress updates associated with the upgrade will be relayed through the callback that was registered using the GatewayClient.registerOtaProgressHandler(...) API.
Examples
Code Block | ||
---|---|---|
| ||
ConnectionInfo c = new ConnectionInfo(ConnectionType.ZIGBEE_UART, "/dev/ttyUSB0");
GatewayClient gw = new GatewayClient(c);
...
gw.registerOtaFile("path/to/otaFile.ota", c);
gw.registerOtaProgressHandler( progress ->
System.out.println("DeviceId: " + progress.getId() + ", Progress: " + progress.getProgress() + " %")
);
...
Device device = gw.getDevice(id);
device.startOtaUpgrade();
... |
abortOtaUpgrade()
Usage
Signals the remote device that it should stop any on-going OTA upgrade, and stops serving OTA upgrade files to that device.
Notes:
- All status messages and progress updates associated with the upgrade will be relayed through the callback that was registered using the GatewayClient.registerOtaProgressHandler(...) API.
- This is a non-blocking call.
- This method is thread-safe.
Parameters
None.
Returns
None.
All status messages and progress updates associated with the upgrade will be relayed through the callback that was registered using the GatewayClient.registerOtaProgressHandler(...) API.
Examples
Code Block | ||
---|---|---|
| ||
ConnectionInfo c = new ConnectionInfo(ConnectionType.ZIGBEE_UART, "/dev/ttyUSB0");
GatewayClient gw = new GatewayClient(c);
...
gw.registerOtaFile("path/to/otaFile.ota", c);
gw.registerOtaProgressHandler( progress ->
System.out.println("DeviceId: " + progress.getId() + ", Progress: " + progress.getProgress() + " %")
);
...
Device device = gw.getDevice(id);
device.startOtaUpgrade();
...
device.abortOtaUpgrade(); |