wiki:ZigbeeGateway

Version 7 (modified by Sensei, 14 years ago) (diff)

--

Zigbee to SENSEI Gateway Cookbook

This document includes instructions about installing and running the Zigbee to SENSEI Gateway in a computer.

Table of Contents

  1. Introduction
  2. Installation
    1. Requirements
    2. Package Content
    3. Compilation
  3. Specification
  4. Configuration
    1. Zb2SenseiGw.exe.config file
    2. rpi.xml file
  5. User manual
  6. Troubleshooting
  7. Mobility
    1. Mobility format interchanged between gateways
  8. RAI interface
    1. Subscriptions

Introduction

The Zigbee to SENSEI gateway is a software that allows connecting a Zigbee WS&AN island into the SENSEI framework. The gateway implements the REP (Resource End Point) of the resources in the island publishing into the RD (Resource Directory) and implements the RAI (Resource Access Interface) that allows a client to get, actuate and subscribe over the resources.

This software runs under Windows Operating System. There are two ways of connecting to a Zigbee island:

  1. Through a Zigbee USB dongle attached to the PC. In this case the PC needs to be in the rario coverage of the Zigbee island.
  2. Through IP connection to an external concentrator. This concentrator is an element that simple translates the Zigbee binary message into IP and transports it using a TCP/IP socket.

Installation

There is not an installation package available. To run this software just copy and paste the files contain in the package in a directory and run the exe file "Zb2SenseiGw.exe". Prior to that, it is convenient to adjust the configuration file (see Configuration section).

Requirements

The package requires:

  • Windows XP operating system version or upper.
  • No special computer performance requirements are needed.
  • External Hardware:
    • Zigbee dongle. It has been tested the Zigbee dongle of "Integration" model "IA DAUB-DK1 2400".
      • Drivers of this dongle should be properly installed before running the package.
    • External concentrator, that convert the Zigbee messages into IP for transmitting using TCP/IP protocol.
  • IP connection. Make sure that the firewall allows the package to establish a TCP server.

Package Content

  • Main executable file:
    • ZB2SenseiGW.exe
  • Resource files:
    • connect.bmb, disconnect.bmp, linked.bmp
  • Configuration files:
  • Libraries of Zigbee dongle:
    • STKUSB.dll, ZB.dll

Compilation

The sources are written in C# language. Microsoft Visual Studio 2010. Open "ZB2SenseiGW.sln" solution and compile the project. The executable files will be located on ".\bin\release" or ".\bin\debug" (depending on the configuration) directory.

Specification

The two ways of connecting to a Zigbee island (dongle or concentrator) are quite similar, the dongle and external concentrator have primitives for connecting to a Zigbee island and for interchanging messages. In the case of dongle it is done through a library (*.dll). In the case of the external concentrator it is done using a TCP/IP messaging.

The software engage to the island, discovers nodes, and for each node it discovers sensors and actuators. This software operates under the following Zigbee configuration:

  • It has been tested upon Zigbee 2007. Zigbee Pro should work depending on the Zigbee dongle or concentrator
  • It is needed to known a priori physical Zigbee parameters
    • Frequency channel number (1 to 26)
    • Zigbee net password
    • extended PAN Identification helps but not needed.
  • Not all the Zigbee profiles are detected. It have been tested under temperature, light, human presence, acceleration sensors and electricity on/off actuator.

The Gateway has the following features regarding Resource End Point implementation

  • Allows publication against a Resource Directory
  • Allows getting data from sensor and acting over an actuator using RESTful access
  • Allows subscription to resources. Notification can be requested upon one or several of the following conditions:
    • Periodic time. If active, it sends a new notification after the period time passes without having sent a notification.
    • Value change. If active, it sends a notification when detected that the value has changed
    • Threshold. When the value goes beyond a threshold a notification is sent.
  • Allows mobility. Several gateways can be located in the vicinity and in case the Zigbee island allows nodes to move, both gateway communicates each other to properly handle the mobility.

In order to not saturate the islands with possible huge requests coming from the internet world, the gateway do not bypass the entire requests to the island. For that reason the gateways stores the last value of the resources in order to respond by itself to requests targeting the same resource that arrives in a short period of time.

Configuration

Two xml files need to be edited for configuring properly the software package before running it. These configuration files allows to establish most of the behaviour of the package without the needed of compile the software.

Remember that these files are read when application starts. If you change a value, it will not be considered after restarting the application.

It is not needed special editor for changing these files. Whichever text editor used is enough. But special care should be followed for not modifying the overall xml structure, and the rest of the tags. Read this manual before proceed to edit the files.

Do not worry if you are not familiar with xml basis. Look for the target name that follow "key=", and you must edit only the text between double apostrophes after the "value=" text.

Zb2SenseiGw.exe.config file

The "Zb2SenseiGw.exe.config" file allows establishing:

"autoConnectType" and "autoConnectIndexCh": Indicates if you want to connect to the Zigbee island automatically when the application starts. It is very useful for non attended servers if the computer or application restarts for whatever reason. The possible values of "autoConnectType" are:

  • "off": do not connect automatically. Manually connection needed after application start. "autoConnectIndexCh" value is ignored.
  • "ch": connect automatically using Zigbee dongle. "autoConnectIndexCh" indicates the frequency channel; allowed values are from 11 to 26.
  • "ip": connect automatically to a ip Zigbee gateway. "autoConnectIndexCh" indicates the index "<netConn>" list to be used. The first index is 0.

"<netConn>" list. It contains a list of ip address that the gateway can connect to an external concentrator. Each element in the list contains:

  • "idNet": description or name that appears in the application.
  • "remoteip": ip adress.
  • "remoteport": remote server tcp port.
  • "localport": local server tcp port to be used when connected. Used for receiving responses. Beware not to use local ports used by other software in the computer.

"netPassword": Zigbee net key in hexadecimal format. Leave empty if this security options is not used.

"netExtPANid": target Zigbee extended PAN identifier in hexadecimal format: leave empty for any (example: "20DB765432144010").

"Sensei_RPI_ProxiHost","Sensei_RPI_ProxiPort","Sensei_RPI_ProxiBypass": If proxy is used for accessing internet both for publication and notification, proper configuration is needed here. If not, leave empty. Insert Host as name or IP address, TCP port to be used and bypass contains local IP address ranges that do not use the proxy, as for example "192.168.0.0/192.168.255.255"

"Sensei_RAI_BaseURL": Base URL for the SENSEI RAI Resource Access Interface server. For example "http://myIP:8081/sensei/rai/resources/ ". If empty, the application will not implement the RAI server. It is mandatory to include the port event if the default port is used. It is also mandatory to end in "/". "myIP" text will be replaced by first real computer IP address. If the computer has several IP address and you want to use another, put it explicitly. Each resource is acceded throw BaseURL/ nodeID/[s or a]/number (see RAI Interface? for more details).

"Sensei_RPI_URL": SENSEI Target Resource Directory URL for Publishing. Leave Empty for not publishing resources into Resource Directory. End with "/". Application will add "rpi", "rli" or "rd" suffix when needed. For example "http://sensei-dev1.grid.pub.ro:8184/ ".

"Sensei_RPI_RAIBaseURL": URL published in "<Rai-Description> <REP-Locator>" into Resource Directory for each resource. If empty it will take Sensei_RAI_BaseURL, but it can be different if needed for example if the gateway access through a proxy or a router that changes the local IP into a public IP. End with "/". Application will append "nodeID/[s or a]/number" to this URL. "myIP" text will be replaced by first real computer IP address.

"Sensei_RPI_ExpirationTime": Expiration date for each resource published into the Resource Directory, in hours from first publication. If empty, one week will apply.

"ZB2SenseiGw_Password": This is used in case of mobility. It contains a text password that is needed to provide credentials between gateways. The gateways that take part in the mobility of a node need to have the same password.

rpi.xml file

The rpi.xml file indicates what exactly format should be sent to the resource directory for publishing a resource. In that way format can be completely changed for new versions without the need of compilation.

In addition " rpi.xml " is a generic file for all the resources, but you can specify individual files for each resource. Simple insert a file with the same structure in the package directory and with the name equals to "nodeIDsnumber.xml" for a sensor or "nodeIDanumber.xml" for an actuator. Where "nodeID" is the node MAC address in hexadecimal format, (16 characters), and "number" is the index of the sensor or actuator starting by 0. If an individual file is present it will be considered, if not, the generic one is considered.

The "*.xml " file can include the following text variables that will be replaced with the proper values by the application (case sensitive):

  • "_ResT": name of the resource, for example temperature, light, etc.
  • "_NODE": node id, that is, the MAC address in hexadecimal format with capital letters (16 characters).
  • "_NET": net id, that is, coordinator MAC address in hexadecimal format with capital letters (16 characters).
  • "_RES": will be replaced by "a" for an actuator or "s" for a sensor.
  • "_NUMBER": number of the sensor or actuator, starting by 0. If the node contains several, the order of appearance is considered.
  • "_TYPE": will be replaced by "actuator" for an actuator or "sensor" for a sensor.
  • "_TIME": expiration time contained in the "Sensei_RPI_ExpirationTime" variable of the "Zb2SenseiGw.exe.config" file.
  • "_ RAI": value of the " Sensei_RPI_URL " variable of the "Zb2SenseiGw.exe.config" file.

User manual

Figure shows the main screen of the application.

On the upper side, appears the type of connection to the Zigbee island. The "USB" is through a dongle and the "IP" through an external concentrator. The "IP/Ch" select box contains the Zigbee channel for USB or the connection name (see <netConn> idNet in Configuration) for IP. The button "Connect" and "Disconnect" allows to attach or detach to the Zigbee island.

The connection process takes a while, firtsly it engages in the Zigbee island. Secondly it discovers the nodes and resources. The node list appears on the "Tree of nodes" tree box.

Details of a node selected in the tree box are shown on the right side of the screen:

  • Short and MAC address, father node (for sleeping nodes).
  • Number of resources or devices.
  • Model and version.
  • Power transmission, Link Quality Indicator (LQI).
  • Relative position.

For every sensor, actuator or counter (sensor) additional details are shown in the corresponding tags on the "Node Description"

The upper side tags are used for debugging. It contains traces about orders receives from SENSEI, events receives from WS&AN, and commands that can be raised manually to the island.

Troubleshooting

Appears the message error "Error while connecting to Zigbee dongle": Ensure that a zigbee dongle is properly inserted in the PC. Ensure that no other application is using the dongle. Remove and insert again.

The gateway do not connect to the Zigbee net: Ensure that you have enter right extender PAN id, password, and channel frequency.

Not all the resources appear in the "tree list": Ensure you have properly dimensioned the timeout variables in the configuration file according with the nodes latency. It can also happen that nodes have profiles or attributes not recognize by this version of application.

No publish the resources in the Resource Directory: Ensure the proxy variables are properly adjusted depending on your internet connection, and the resource directory URL is properly adjusted.

Mobility

Zigbee gateway resolves the mobility of a node between several gateways. In the case of Zigbee there is no possibility of storing information in nodes that helps to the mobility. So gateways need to resolve the problem by themselves. Figure shows how mobility is resolved by Zigbee gateways.

Put figure

Resource identification formed by the gateway is always the same as depend on node parameters only as MAC address. In that way Resource Directory can be used for knowing if this resource was previously attached to other gateway, and the old URL. No replication of the same resource is found in the Resource Directory. If it exists, it is updated. The all gateway is informed about the new location of the resource. In the response, the all gateway sends all the subscription information that these resource had, and these are implemented by the new gateway. The all gateway in addition will redirect access this resource to the new URL using the http redirect response. This redirection is transparent to applications. The result is that applications do not notice if they do not want that a resource has been moved. For optimization, mobility commands interchanged between gateways are not resource by resource, but for all the resources of a node.

Mobility format interchanged between gateways

The new gateway informs the all gateway with a PUT http method addressing node id (not resource id) with the following xml content

<Mobility>
        <newREP-Locator> newURL </newREP-Locator>
        <Credentials>
                <URL ZB2SENSEI_PASSWD> password </URL ZB2SENSEI_PASSWD>
        </Credentials>
</Mobility>

In the response, if the credentials are accepted, the old gateway informs about all the subscriptions that the resources of the node contains, with the following format:

<SubscriptionNodeInfo>
        <SubscriptionInfo sensor="0">
                <Subscription>
                         … Subscription info
                <Subscription>
                <Subscription>
                         … Subscription info
                <Subscription>
        </SubscriptionInfo>
        <SubscriptionInfo actuator="0">
                <Subscription>
                         … Subscription info
                <Subscription>
                …
        </SubscriptionInfo>
</SubscriptionNodeInfo>

RAI interface

This Gateway uses a REST interface for iterate with the Zigbee island. This interface is defined here (PUT LINK to the xml specification). Each resource has its one URL, which format is "BASE_URL/nodeMAC/X/number"

  • nodeMAC is the node MAC address in hexadecimal capital letters (16 characters).
  • X is the letter "s" for a sensor or "a" for an actuator.
  • number is the number of sensor or actuator, starting with "0".

Over this URL the following operations can be done: GET http method is used for getting a sensor or actuator value PUT http method is used for changing a value; logically it works only in actuators.

Subscriptions

A POST http method over the resource URL is used for adding a new subscription. In this case it should be add at the end of the resource URL the subscription identity: "BASE_URL/nodeMAC/X/number/SubscriptionID"

  • SubscriptionID is whatever text allowed in the URL names. The xml format for a subscription is (PUT A LINK TO XML SUBSCRIPTION FORMAT)

A PUT http method over this subscription URL is used for modify it. A GET http method over this subscription URL returns the subscription xml information. A DELETE http method over this subscription URL is used for deleting it. A POST http method over this subscription URL returns an error.

GET over "BASE_URL/nodeMAC/X/number?Subscription" for getting the list of subscriptions of a resource. GET over "BASE_URL/nodeMAC " returns an html page with node information, sensors and actuators, and links for the subscriptions. Ideally for a browser

Attachments (3)

Download all attachments as: .zip