Skip to content

Arduino XBee Library for GroveStreams Wireless Sensor Network

License

Notifications You must be signed in to change notification settings

JChristensen/gsXBee

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

28 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Arduino XBee Library for GroveStreams Wireless Sensor Network

http://github.com/JChristensen/gsXBee
README file

License

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

Description

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/

Installation

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.

Constructor

gsXBee(void)

Description

Instantiates a gsXBee object.

Syntax

gsXBee myXBee;

Parameters

None.

Methods

begin(Stream &serial, bool forceDisassoc)

Description

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.

Syntax

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).

Returns

None.

read(void)

Description

Checks the XBee for incoming traffic and processes it.

Syntax

myXBee.read();

Parameters

None.

Returns

Type of traffic received, or various error indications. See the xbeeReadStatus_t enumeration in the gsXBee.h file (xbeeReadStatus_t).

Example
gsXBee myXBee;
xbeeReadStatus_t xbStat;
xbStat = myXBee.read();

waitFor(xbeeReadStatus_t stat, uint32_t timeout)

Description

Reads the XBee until a certain status is returned, or a certain amount of time elapses, whichever occurs first.

Syntax

myXBee.waitFor(stat, timeout);

Parameters

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).

Returns

Type of traffic received, or various error indications. See the xbeeReadStatus_t enumeration in the gsXBee.h file (xbeeReadStatus_t).

Example
gsXBee myXBee;
xbeeReadStatus_t xbStat;
xbStat = myXBee.waitFor(TX_ACK, 100);	//wait 100 ms for transmission to be acknowledged

sendCommand(uint8_t* cmd)

Description

Sends an AT command to the local XBee. The response is processed by read() or waitFor().

Syntax

myXBee.sendCommand(cmd);

Parameters

cmd: A two-byte array containing the ASCII command characters. (uint8_t*).

Returns

None.

Example
gsXBee myXBee;
uint8_t atCmd[] = { 'D', 'B' };
myXBee.sendCommand(atCmd);		//request rss for last packet received

sendData(char* data)

Description

Sends data to a remote node.

Syntax

myXBee.send(data);

Parameters

data: Zero-terminated char array containing the data to be transmitted (char*).

Returns

None.

Example
gsXBee myXBee;
char someData[] = "Hello, world!";
myXBee.sendData(someData);

mcuReset(uint32_t dly)

Description

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.

Syntax

myXBee.mcuReset(dly);

Parameters

dly: Delay in milliseconds before reset (unsigned long).

Returns

None.

Example
gsXBee myXBee;
myXBee.resetMCU(60000);		//reset after a minute

About

Arduino XBee Library for GroveStreams Wireless Sensor Network

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages