...
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(); devicegw.sendProtocolMessage(message.toJson()) .thenAccept(jsonResponse -> System.out.println(jsonResponse)); } |
...