http://github.com/JChristensen/gsXBee
README file
Arduino XBee Library for GroveStreams Wireless Sensor Network Copyright (C) 2015 Jack Christensen GNU GPL v3.0
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License v3.0 as published by the Free Software Foundation.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program. If not, see https://www.gnu.org/licenses/gpl.html
This library is derived from Andrew Rapp's XBee library to provide additional functionality for a GroveStreams wireless sensor network. See my GroveStreams library for more information, example sketches and schematics for gateway and sensor nodes.
Prerequisites
Andrew Rapp's XBee library
http://github.com/andrewrapp/xbee-arduino
Mikal Hart's Streaming library
http://arduiniana.org/libraries/streaming/
To use the gsXBee library:
- Go to https://github.com/JChristensen/gsXBee, download the code as a ZIP file and save it to a convenient location on your PC.
- Uncompress the downloaded file. This will result in a folder containing all the files for the library, that has a name that includes the branch name, usually gsXBee-master.
- Rename the folder to just gsXBee.
- Copy the renamed folder to the Arduino sketchbook/libraries folder.
Instantiates a gsXBee object.
gsXBee myXBee;
None.
Initializes the gsXBee library. Verifies serial communication with the XBee, gets its Node ID, ensures that it's associated, and optionally forces disassociation for end devices (this causes initialization to take several seconds longer but allows an end device to associate with an optimal parent, e.g. if it was moved). If communication with the XBee fails, the initialization routine waits one minute, then resets the microcontroller.
myXBee.begin(Serial, false);
serial: Serial port to use for XBee communications (Stream&).
forceDisassoc: Optional argument that defaults to true. For end devices only, causes the XBee to disassociate during the initialization sequence. Coordinators and routers are not affected (bool).
None.
Checks the XBee for incoming traffic and processes it.
myXBee.read();
None.
Type of traffic received, or various error indications. See the xbeeReadStatus_t
enumeration in the gsXBee.h file (xbeeReadStatus_t).
gsXBee myXBee;
xbeeReadStatus_t xbStat;
xbStat = myXBee.read();
Reads the XBee until a certain status is returned, or a certain amount of time elapses, whichever occurs first.
myXBee.waitFor(stat, timeout);
stat: The status to wait for. See the xbeeReadStatus_t
enumeration in the gsXBee.h file (xbeeReadStatus_t).
timeout: Time to wait in milliseconds. (unsigned long).
Type of traffic received, or various error indications. See the xbeeReadStatus_t
enumeration in the gsXBee.h file (xbeeReadStatus_t).
gsXBee myXBee;
xbeeReadStatus_t xbStat;
xbStat = myXBee.waitFor(TX_ACK, 100); //wait 100 ms for transmission to be acknowledged
Sends an AT command to the local XBee. The response is processed by read()
or waitFor()
.
myXBee.sendCommand(cmd);
cmd: A two-byte array containing the ASCII command characters. (uint8_t*).
None.
gsXBee myXBee;
uint8_t atCmd[] = { 'D', 'B' };
myXBee.sendCommand(atCmd); //request rss for last packet received
Sends data to a remote node.
myXBee.send(data);
data: Zero-terminated char array containing the data to be transmitted (char*).
None.
gsXBee myXBee;
char someData[] = "Hello, world!";
myXBee.sendData(someData);
Resets the microcontroller after a given number of milliseconds. The minimum is 4 seconds (4000 ms). If a number less than 4000 is given, the delay will be approximately 4 seconds.
myXBee.mcuReset(dly);
dly: Delay in milliseconds before reset (unsigned long).
None.
gsXBee myXBee;
myXBee.resetMCU(60000); //reset after a minute