Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 3 Next »

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

NameTypeDescription
clusterIdintThe server-side cluster where the attribute resides.
attributeIdintThe attribute to read.

Returns

Return TypeDescription
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

NameTypeDescription
clusterIdintThe server-side cluster where the attribute resides.
attributeIdintThe attribute to read.
manufacturerCodeintThe manufacturerCode associated with the cluster; 0 if none.
isServerbooleanWhether the cluster is server-side.

Returns

Return TypeDescription
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

NameTypeDescription
clusterIdintThe server-side cluster where the attribute resides.
attributeIdintThe attribute to be written.
dataTypeshortThe identifier for the data type of the value being written. See Zigbee Specification References for supported data types.
valuebyte[]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 TypeDescription
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

NameTypeDescription
clusterIdintThe server-side cluster where the attribute resides.
attributeIdintThe attribute to be written.
dataTypeshortThe identifier for the data type of the value being written. See Zigbee Specification References for supported data types.
valuebyte[]The value, in bytes, to be written. The order is LSB. For example, 2700 (decimal) would be "new byte[] {(byte)0x8C, (byte)0x0A}".
manufacturerCodeintThe manufacturerCode associated with the cluster; 0 if none.
isServerbooleanWhether the cluster is server-side.

Returns

Return TypeDescription
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

NameTypeDescription
commandIdshotThe ZCL command id.
payloadbyte[]The payload in bytes. Each field in the payload is entered as LSB, so 2700 (decimal) would be 0x8C 0x0A.
clusterIdintThe cluster to send the command to.

Returns

Return TypeDescription
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

NameTypeDescription
commandIdshotThe ZCL command id.
payloadbyte[]The payload in bytes. Each field in the payload is entered as LSB, so 2700 (decimal) would be 0x8C 0x0A.
clusterIdintThe cluster to send the command to.
manufacurerCodeint

The manufacturer code. 0 means "not manufacturing specific".

isServerboolean

Whether the cluster is a server cluster.

isClusterSpecificboolean

Whether the command is cluster specific (as opposed to a ZCL general command).

Returns

Return TypeDescription
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());
});
  • No labels