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

Overview

This page describes how to develop against the Gateway API. It goes over the basics of initializing a GatewayClient object, and interacting with Device references.

Initializing GatewayClient

Initialize a GatewayClient by passing in a ConnectionInfo object, which contains details about what the connection type is (i.e. a zigbee uart port) and a string describing where to connect to it.

In the following example, we also pass in a lambda that will handle device events by simply printing them out. In a real application, you can replace this with your own event handling method, or an object that implements the DeviceEventListener interface.

Initializing GatewayClient
// example of a lambda implementation of the DeviceEventListener parameter.
final GatewayClient gw = new GatewayClient(new ConnectionInfo(ConnectionType.ZIGBEE_UART, "/dev/ttyS1"),
    (event) -> {
        System.out.println("Device Event: " + event.getStatus());
        System.out.println("Device: " + event.getDevice().getID());
    }
);

Once constructed, the GatewayClient will automatically connect to the device, configure it as a Combined Interface, and form a network. Otherwise, on any failure, it will throw a GatewayConnectionException.

Scanning for Devices

To join a device to the network, you first have to open the permit join window on the GatewayClient.

The following example shows how to call "scanForDevices" on all known connections for a duration of 30 seconds. It also implements a callback displaying the status of the command. The expected result should be "NETWORK_OPEN".

Scanning for Devices (i.e. opening the permit join window)
for (ConnectionInfo c: gw.getConnectionInfo()) {
    gw.scanForDevices(c, 30).thenAccept( status -> {
        System.out.println("Status for connection " + c.getValue() + " is " + status);
    });
}

Once the permit join window is open, you can initiate the pairing process from a secondary (i.e. remote) device.

Note: You can close the permit join window by calling "scanForDevices" with 0 as the "duration" parameter.

Interacting with Devices

When a device joins the network, you should see a DeviceEvent. For example, the lambda we passed into GatewayClient should print something like the following:

Device Event: ADD
Device ID: 00244600000f1472_1

"ADD" means a new device has been added to the network.

Getting Properties

You can use the Device API to request properties of the connected device.

Getting the Properties of the Remote Device
final Device d = gw.getDevice("00244600000f1472_1");
d.getProperties();

Updating Properties

...

Conclusion

...


  • No labels