Overview
The ZigbeeDevice class represents a zigbee device on the network.
As a sub-class of Device, it inherits everything from that interface, as well as providing convenience methods for interacting with zigbee devices.
API
readAttribute(int clusterId, int attributeId)
Usage
Sends a command over the network to read a zigbee attribute from the specified server cluster.
Returns a CompletableFuture of a Property containing the name, type, and value of the attribute. Otherwise, will complete exceptionally on all errors.
This is a non-blocking call.
Parameters
Name | Type | Description |
---|---|---|
clusterId | int | The server-side cluster where the attribute resides. |
attributeId | int | The attribute to read. |
Returns
Return Type | Description |
---|---|
CompletableFuture<Property> | Contains a CompletableFuture<Property> of the zigbee attribute being read. Will return exceptionally on any and all errors; the exception will contain an errorCode and description. |
Examples
GatewayClient gateway = new GatewayClient(new ConnectionInfo(ConnectionType.ZIGBEE_UART, "/dev/ttyUSB0"), ... Device device = gateway.getDevice(id); // blocking Property property = ((ZigbeeDevice)device).readAttribute(0x0000, 0x0001).get(); System.out.println(property.toString()); ... // async ((ZigbeeDevice)device).readAttribute(0x0000, 0x0001).thenAccept( property -> { System.out.println(property.toString()); });
readAttribute(int clusterId, int attributeId, int manufacturerCode, boolean isServer)
Usage
Sends a command over the network to read a zigbee attribute from the specified cluster, manufacturerCode, and cluster side (server or client).
Returns a CompletableFuture of a Property containing the name, type, and value of the attribute. Otherwise, will complete exceptionally on all errors.
This is a non-blocking call.
Parameters
Name | Type | Description |
---|---|---|
clusterId | int | The server-side cluster where the attribute resides. |
attributeId | int | The attribute to read. |
manufacturerCode | int | The manufacturerCode associated with the cluster; 0 if none. |
isServer | boolean | Whether the cluster is server-side. |
Returns
Return Type | Description |
---|---|
CompletableFuture<Property> | Contains a CompletableFuture<Property> of the zigbee attribute being read. Will return exceptionally on any and all errors; the exception will contain an errorCode and description. |
Examples
GatewayClient gateway = new GatewayClient(new ConnectionInfo(ConnectionType.ZIGBEE_UART, "/dev/ttyUSB0"), ... Device device = gateway.getDevice(id); // blocking Property property = ((ZigbeeDevice)device).readAttribute(0x0000, 0x0001, 0xFC01, true).get(); System.out.println(property.toString()); ... // async ((ZigbeeDevice)device).readAttribute(0x0000, 0x0001, 0xFC01, true).thenAccept( property -> { System.out.println(property.toString()); });
writeAttribute(int clusterId, int attributeId, short dataType, byte[] value)
Usage
Sends a command over the network to write a zigbee attribute to the specified server cluster.
Returns a CompletableFuture of a Property containing the name, type, and value of the attribute that was written. Otherwise, will complete exceptionally on all errors.
This is a non-blocking call.
Parameters
Name | Type | Description |
---|---|---|
clusterId | int | The server-side cluster where the attribute resides. |
attributeId | int | The attribute to be written. |
dataType | short | The identifier for the data type of the value being written. See Zigbee Specification References for supported data types. |
value | byte[] | The value, in bytes, to be written. The order is LSB. For example, 2700 (decimal) would be "new byte[] {(byte)0x8C, (byte)0x0A}". |
Returns
Return Type | Description |
---|---|
CompletableFuture<Property> | Contains a CompletableFuture<Property> of the zigbee attribute being written. Will return exceptionally on any and all errors; the exception will contain an errorCode and description. |
Examples
GatewayClient gateway = new GatewayClient(new ConnectionInfo(ConnectionType.ZIGBEE_UART, "/dev/ttyUSB0"), ... Device d = gateway.getDevice(id); // blocking Property p = ((ZigbeeDevice)d).writeAttribute(0x0201, 0x0012, 0x29, new byte[] {(byte)0x8C, (byte)0x0A}).get(); System.out.println(p.toString()); ... // async ((ZigbeeDevice)d).writeAttribute(0x0201, 0x0012, 0x29, new byte[] {(byte)0x8C, (byte)0x0A}).thenAccept( property -> { System.out.println(p.toString()); });
writeAttribute(int clusterId, int attributeId, short dataType, byte[] value, int manufacturerCode, boolean isServer)
Usage
Sends a command over the network to write a zigbee attribute to the specified server cluster.
Returns a CompletableFuture of a Property containing the name, type, and value of the attribute that was written. Otherwise, will complete exceptionally on all errors.
This is a non-blocking call.
Parameters
Name | Type | Description |
---|---|---|
clusterId | int | The server-side cluster where the attribute resides. |
attributeId | int | The attribute to be written. |
dataType | short | The identifier for the data type of the value being written. See Zigbee Specification References for supported data types. |
value | byte[] | The value, in bytes, to be written. The order is LSB. For example, 2700 (decimal) would be "new byte[] {(byte)0x8C, (byte)0x0A}". |
manufacturerCode | int | The manufacturerCode associated with the cluster; 0 if none. |
isServer | boolean | Whether the cluster is server-side. |
Returns
Return Type | Description |
---|---|
CompletableFuture<Property> | Contains a CompletableFuture<Property> of the zigbee attribute being written. Will return exceptionally on any and all errors; the exception will contain an errorCode and description. |
Examples
GatewayClient gateway = new GatewayClient(new ConnectionInfo(ConnectionType.ZIGBEE_UART, "/dev/ttyUSB0"), ... Device d = gateway.getDevice(id); // blocking Property p = ((ZigbeeDevice)d).writeAttribute(0xF001, 0x0001, 0x29, new byte[] {(byte)0x8C, (byte)0x0A}, 0xFC01, true).get(); System.out.println(p.toString()); ... // async ((ZigbeeDevice)d).writeAttribute(0xF001, 0x0001, 0x29, new byte[] {(byte)0x8C, (byte)0x0A}, 0xFC01, true).thenAccept( property -> { System.out.println(p.toString()); });
sendZclCommand(short commandId, byte[] payload, int clusterId)
Usage
Sends a ZCL general command over the network to the specified server cluster.
A CompletableFuture of a Property that contains a JSON string with the ZCL command response. The CompletableFuture completes exceptionally on any errors.
This is a non-blocking call.
Parameters
Name | Type | Description |
---|---|---|
commandId | shot | The ZCL command id. |
payload | byte[] | The payload in bytes. Each field in the payload is entered as LSB, so 2700 (decimal) would be 0x8C 0x0A. |
clusterId | int | The cluster to send the command to. |
Returns
Return Type | Description |
---|---|
CompletableFuture<Property> | Contains a CompletableFuture<Property> with a JSON string of the ZCL Command Response. Will return exceptionally on any and all errors; the exception will contain an errorCode and description. |
Examples
GatewayClient gateway = new GatewayClient(new ConnectionInfo(ConnectionType.ZIGBEE_UART, "/dev/ttyUSB0"), ... Device d = gateway.getDevice(id); // blocking command to discover commands that the OnOff cluster can receive Property p = ((ZigbeeDevice)d).sendZclCommand(0x11, new byte[] {(byte)0x00, (byte)0xFF}, 0x0006).get(); System.out.println(p.toString()); ... // async command to discover the commands that the OnOff cluster can receive ((ZigbeeDevice)d).sendZclCommand(0x11, new byte[] {(byte)0x00, (byte)0xFF}, 0x0006).thenAccept( property -> { System.out.println(p.toString()); });
sendZclCommand(short commandId, byte[] payload, int clusterId, int manufacturerCode, boolean isServer, boolean isClusterSpecific)
Usage
Sends a ZCL command (cluster specific, or general command) over the network to the specified cluster (server-side or client-side) and manufacturerCode.
A CompletableFuture of a Property that contains a JSON string with the ZCL command response. The CompletableFuture completes exceptionally on any errors.
This is a non-blocking call.
Parameters
Name | Type | Description |
---|---|---|
commandId | shot | The ZCL command id. |
payload | byte[] | The payload in bytes. Each field in the payload is entered as LSB, so 2700 (decimal) would be 0x8C 0x0A. |
clusterId | int | The cluster to send the command to. |
manufacurerCode | int | The manufacturer code. 0 means "not manufacturing specific". |
isServer | boolean | Whether the cluster is a server cluster. |
isClusterSpecific | boolean | Whether the command is cluster specific (as opposed to a ZCL general command). |
Returns
Return Type | Description |
---|---|
CompletableFuture<Property> | Contains a CompletableFuture<Property> with a JSON string of the ZCL Command Response. Will return exceptionally on any and all errors; the exception will contain an errorCode and description. |
Examples
GatewayClient gateway = new GatewayClient(new ConnectionInfo(ConnectionType.ZIGBEE_UART, "/dev/ttyUSB0"), ... Device d = gateway.getDevice(id); // blocking command to discover commands that the OnOff cluster can receive Property p = ((ZigbeeDevice)d).sendZclCommand(0x11, new byte[] {(byte)0x00, (byte)0xFF}, 0xFC01, 0xFCC0, true, true).get(); System.out.println(p.toString()); ... // async command to discover the commands that the OnOff cluster can receive ((ZigbeeDevice)d).sendZclCommand(0x11, new byte[] {(byte)0x00, (byte)0xFF}, 0xFC01, 0xFCC0, true, true).thenAccept( property -> { System.out.println(p.toString()); });