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 22 Next »

Overview

The GatewayClient represents a connection to a network interface, such as a zigbee module. It allows a user to query for, and interact with, remote network devices without knowing anything about the underlying network or communication protocols.

The GatewayClient API offers methods to construct and shutdown the GatewayClient, grab the connection information of the underlying network interface, interact with Devices, as well as add/remove event listeners, and perform firmware upgrades of the underlying network interface (i.e. module). It also offers some network management methods.

Constructors, Shutdown, and Connection Info API

GatewayClient(ConnectionInfo)

Usage

Creates a GatewayClient object that represents a single network interface.

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

Parameters

TypeDescription
ConnectionInfoRepresents a network interface that the GatewayClient can connect to.

Returns

A newly constructed GatewayClient object connected to the network interface described by the ConnectionInfo object.

Will attempt to form a network on the network interface.

Will return an exception if the client cannot connect to, or configure, the network interface.

Example

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

GatewayClient(ConnectionInfo, DeviceEventListener)

Usage

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

Parameters

TypeDescription
ConnectionInfoRepresents a network interface that the GatewayClient can connect to.
DeviceEventListenerAn instance of a class that implements the DeviceEventListener interface (or a lambda that does the same).

Returns

A newly constructed GatewayClient object connected to the network interface described by the ConnectionInfo object, that will call the registered DeviceEventListener when a DeviceEvent is received.

Will attempt to form a network on the network interface.

Will return an exception if the client cannot connect to, or configure, the network interface.

Example

// Example of a lambda implementation of the DeviceEventListener parameter.
// Will simply print the event that is received from the Device with the given ID.
GatewayClient gw = new GatewayClient(new ConnectionInfo(ConnectionType.ZIGBEE_UART, "/dev/ttyUSB0"),
    (event) -> {
        System.out.println("Device Event: " + event.getStatus());
        System.out.println("Device: " + event.getDevice().getID()); 
    }
);

shutdown()

Usage

Performs a graceful shut down of the GatewayClient, allowing for all subsystems to save any critical data and release system resources, such as file handles, open ports, user threads, etc.

This is a blocking call and is not thread-safe.

Parameters

None.

Returns

True if the system shut down gracefully; false otherwise.

Example

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

getConnectionInfo()

Usage

Gets a list of ConnectionInfo descriptors that the GatewayClient knows about.

Parameters

None.

Returns

Collection<ConnectionInfo> containing one ConnectionInfo object per network interface that the GatewayClient knows about.

Example

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)

Usage

Allows a class to register itself to receive DeviceEvents.

If a listener object is already registered, calling this method will have no effect (i.e. duplicate listener objects are ignored).

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

Parameters

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

Returns

None.

Example

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)

Usage

Removes a previously registered listener.

Parameters

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

Returns

None.

Example

GatewayClient gw = new GatewayClient(new ConnectionInfo(ConnectionType.ZIGBEE_UART, "/dev/ttyUSB0"));
...
DeviceEventListener l = new SampleDeviceEventListener();
gw.addDeviceEventListener(l);
...
gw.removeDeviceEventListener(l);
...

removeAllDeviceEventListeners()

Usage

Removes all previously registered listeners.

Parameters

None.

Returns

None.

Example

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


Devices API

listDevices(Predicate<Device>)

Usage

...

Parameters

TypeDescription
Predicate<Device>

Returns

Collection<Device> containing ...

Example

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

listDevices()

Usage

...

Parameters

None.

Returns

Collection<Device> containing ...

Example

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

getDevice(String)

Usage

...

Parameters

TypeDescription
String

Returns

Device ...

Example

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

Upgrade API

upgradeFirmware(ConnectionInfo, File, ResultConsumer<SerialUploadResult>)

Network API

getNetworkStatus(ConnectionInfo)

createNetwork(ConnectionInfo)

dissolveNetwork(ConnectionInfo)

scanForDevices(ConnectionInfo, int)

  • No labels