O'Reilly logo

Building Wireless Sensor Networks by Robert Faludi

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Simple Sensor Network Pachube Code in Processing

Here’s the source code for the Processing sketch. The comments shown in bold about the serial port, API key, and feed ID highlight essential changes. Other commented instructions are only important if you didn’t download the source from the website listed in the Preface:

/*
 * Draws a set of thermometers for incoming XBee Sensor data
 * by Rob Faludi http://faludi.com
 */

// used for Pachube connection http://pachube.com
// JPachube library available at http://code.google.com/p/jpachube/
import Pachube.*;

// used for communication via xbee api
import processing.serial.*;

// xbee api libraries available at http://code.google.com/p/xbee-api/
// Download the zip file, extract it, and copy the xbee-api jar file
// and the log4j.jar file (located in the lib folder) inside a "code"
// folder under this Processing sketch's folder (save this sketch, then
// click the Sketch menu and choose Show Sketch Folder).
import com.rapplogic.xbee.api.ApiId;
import com.rapplogic.xbee.api.PacketListener;
import com.rapplogic.xbee.api.XBee;
import com.rapplogic.xbee.api.XBeeResponse;
import com.rapplogic.xbee.api.zigbee.ZNetRxIoSampleResponse;

String version = "1.04";

// *** REPLACE WITH THE SERIAL PORT (COM PORT) FOR YOUR LOCAL XBEE ***
String mySerialPort = "/dev/tty.usbserial-A1000iMG";

// *** REPLACE WITH YOUR OWN PACHUBE API KEY AND FEED ID *** String apiKey="your_api_key_here"; int feedID=your_feed_id_here; // create and initialize a new xbee object ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required