Sample Code To Kick-start Your ZigBee Development Work
Note The impAccelerator™ Fieldbus Gateway does not ship with an XBee module. To try these examples you will need to purchase an XBee (S2) or XBee Pro (S2C) module and mount it on the Wireless Communications Gateway yourself. You can either solder the module directly, or fit two 10mm, 2mm-pitch female headers to the board.
The following code accesses an XBee® module mounted onto the Fieldbus Gateway motherboard in order to retrieve basic module information. It makes use of Electric Imp’s XBee library.
This example runs uses various AT commands — “OI” (Operating 16-bit PAN ID), “ND” (Node Discovery) and “MP” (16-bit Parent Network Address) — to discover and list all the XBee modules on the local ZigBee® network. You should note that this code is intended to be run on an XBee configured as the ZigBee co-ordinator.
This example shows how XBees might be employed in locations where imp-based sensor devices need to be sited too far from the WiFi router for WiFi communications to be effective. Instead, ZigBee mesh networking can be employed to route sensor data from source to the Zigbee network Co-ordinator, which is integrated into an impAccelerator Fieldbus Gateway in range of the WiFi router. This imp might gather, package and relay the data from multiple ZigBee-connected sensors to an Internet-hosted database.
Here we have code for both Co-ordinator and End Device units. The example simulates real sensor data by simply reading the host imp’s on-board light sensor, packaging that value and sending to the Co-ordinator, which here logs the received value.
The data source code also makes use of the “AI” AT command (for “Association Indication”) which is used to check for the availability of a ZigBee network. Only if this is present does the device begin relaying data.