Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Constructors, Shutdown, and Connection Info API

GatewayClient(ConnectionInfo c)

Usage

Creates a GatewayClient object that represents a single network interface.

Will attempt to automatically form a network on the given interface.

Parameters

NameTypeDescription
cConnectionInfoRepresents a network interface that the GatewayClient can connect to.

...

Code Block
languagejava
GatewayClient gw = new GatewayClient(new ConnectionInfo(ConnectionType.ZIGBEE_UART, "/dev/ttyUSB0"));

GatewayClient(ConnectionInfo c, DeviceEventListener listener)

Usage

Creates a GatewayClient object that represents a single network interface, with an attached DeviceEventListener that will be called when DeviceEvents are received.

Parameters

NameTypeDescription
cConnectionInfoRepresents a network interface that the GatewayClient can connect to.
listenerDeviceEventListenerAn instance of a class that implements the DeviceEventListener interface (or a lambda that does the same).

...

Code Block
languagejava
GatewayClient gw = new GatewayClient(new ConnectionInfo(ConnectionType.ZIGBEE_UART, "/dev/ttyUSB0"));
...
for (ConnectionInfo c : gw.getConnectionInfo()) {
    System.out.println("Connected to port: " + c.getValue());    
}


Listeners API

addDeviceEventListener(DeviceEventListener listener)

Usage

Allows a class to register itself to receive DeviceEvents.

...

Listeners are called from a dedicated thread, in the sequence that they were registered.

Parameters

NameTypeDescription
listenerDeviceEventListenerAn instance of a class that implements the DeviceEventListener interface (or a lambda that does the same).

...

Code Block
languagejava
GatewayClient gw = new GatewayClient(new ConnectionInfo(ConnectionType.ZIGBEE_UART, "/dev/ttyUSB0"));
...
gw.addDeviceEventListener(
    (event) -> {
        // do something with event
        System.out.println("Device Event: " + event.getStatus());
        System.out.println("Device: " + event.getDevice().getID()); 
    }
);

removeDeviceEventListener(DeviceEventListener listener)

Usage

Removes a previously registered listener.

Parameters

NameTypeDescription
listenerDeviceEventListenerAn instance of a class that implements the DeviceEventListener interface (or a lambda that does the same).

...

Code Block
languagejava
GatewayClient gw = new GatewayClient(new ConnectionInfo(ConnectionType.ZIGBEE_UART, "/dev/ttyUSB0"));
...
gw.removeAllDeviceEventListeners();


Devices API

listDevices(Predicate<Device> filter)

Usage

Get a filtered list of known devices on the network.

The method takes a Predicate, which is used to filter the device list.

Parameters

NameTypeDescription
filterPredicate<Device>A Predicate that can be used to query for certain types of devices.

...

Code Block
languagejava
GatewayClient gw = new GatewayClient(new ConnectionInfo(ConnectionType.ZIGBEE_UART, "/dev/ttyUSB0"));
...
Collection<Device> devices = gw.listDevices();

getDevice(String id)

Usage

Get the device with the corresponding ID.

Assumes that id is unique, and there should only be one device per ID.

Parameters

NameTypeDescription
idStringA unique identifier associated with the Device.

...

Code Block
languagejava
GatewayClient gw = new GatewayClient(new ConnectionInfo(ConnectionType.ZIGBEE_UART, "/dev/ttyUSB0"));
...
Device d = gw.getDevice("0123456789");

Upgrade API

upgradeFirmware(ConnectionInfo c, File file, ResultConsumer<SerialUploadResult> callback)

Usage

Performs a firmware upgrade of the network interface (i.e. module) represented by the given ConnectionInfo object.

...

  • If there is an attempt to upgrade to the same ConnectionInfo while an upgrade is already in progress, then that attempt will fail, the ResultConsumer callback will be called with an error, and the CompletableFuture shall return a Status.FAILED immediately.
  • This method is non-blocking.
  • This method is not thread-safe.

Parameters

NameTypeDescription
cConnectionInfoConnectionInfo of the network interface being upgraded (see getConnectionInfo() API).
fileFileUpgrade file for the specified network interface.
callbackResultConsumer<SerialUploadResult>User-provided callback in order to receive notifications regarding upgrade progress.

...

Code Block
languagejava
public void doSerialUpgrade() throws InterruptedException, ExecutionException, TimeoutException, IOException {
	// setup
	final GatewayClient gw = new GatewayClient(new ConnectionInfo(ConnectionType.ZIGBEE_UART, "/dev/ttyUSB0"));
	final File upgradeFile = new File("/path/to/file");

	// start the upgrade
	final Collection<ConnectionInfo> connections = gw.getConnectionInfo();
	for (ConnectionInfo c : connections) {
		if (c.getType() == ConnectionType.ZIGBEE_UART) {
			final Status status = gw.upgradeFirmware(c, upgradeFile, serialCallback).get(UPGRADE_TIMEOUT_MINUTES, TimeUnit.MINUTES);
			System.out.println("Status: " + status);
		}
	}
}
    
public final static ResultConsumer<SerialUploadResult> serialCallback = ResultConsumer.createResultConsumer(
    (result) -> {
        SerialUploadResult r = (SerialUploadResult)result;
        System.out.println("Progress: " + r.getProgress());
    },
    (throwable) -> {
        System.err.println("Serial upload failed: " + throwable.getMessage());
     }
);


Network API

getNetworkStatus(ConnectionInfo c)

Usage

...

Parameters

NameTypeDescription
cConnectionInfoConnectionInfo of the network interface of interest (see getConnectionInfo() API).

Returns

Return TypeDescription
CompletableFuture<NetworkStatus>

Example

Code Block
languagejava
...

createNetwork(ConnectionInfo c)

Usage

...

Parameters

NameTypeDescription
cConnectionInfoConnectionInfo of the network interface of interest (see getConnectionInfo() API).

Returns

Return TypeDescription
CompletableFuture<NetworkStatus>

Example

Code Block
languagejava
...

dissolveNetwork(ConnectionInfo c)

Usage

...

Parameters

NameTypeDescription
cConnectionInfoConnectionInfo of the network interface of interest (see getConnectionInfo() API).

Returns

Return TypeDescription
CompletableFuture<NetworkStatus>

Example

Code Block
languagejava
...

scanForDevices(ConnectionInfo c, int duration)

Usage

...

Parameters

NameTypeDescription
cConnectionInfoConnectionInfo of the network interface of interest (see getConnectionInfo() API).
durationint

Returns

Return TypeDescription
CompletableFuture<NetworkStatus>

Example

Code Block
languagejava
...