If you’re interested in building wireless sensor networks, Digi’s XBee Series 2 radios are a great starting point. In some cases, you can connect analog sensors directly to an XBee radio and relay that data wirelessly to an XBee connected to an Internet Gateway such as the ConnectPort X2 or ioBridge Pro Internet Gateway. This tutorial covers how to use the ConnectPort X2 to allow web services to be accessed over a wireless network formed by XBee Series 2 radios.
In order to retrieve web data, you need to upload the XIG Python script to your ConnectPort X2. The XIG script allows you to fetch websites and URLs by using HTTP GET. We can take full advantage of that and use XIG to get ThingSpeak URLs to data log sensor data, parse data from any website using ThingHTTP, get data from SSL secured APIs, and send Tweets via ThingSpeak’s ThingTweet App. Here’s an instance where support for HTTP GET allows the XIG to perform cloud-based data logging without having to run a PHP script or write any new software. If you are following along using the Building Wireless Sensor Networks book by Rob Faludi, you can replace all of the custom PHP scripts with a ThingSpeak app.
Parts:
- ConnectPort X2 – ethernet to XBee gateway
- Building Wireless Sensor Networks book by Rob Faludi
- BWSN Basics Kit (XBee Series 2 radios and misc. electronic components)
- Microcontroller – Arduino, Freetronics, or Parallax
Setting up the ConnectPort X2
- Connect the ConnectPort X2 to a network connection using an Ethernet Cable
- Connect the ConnectPort X2 to 2.1mm +5v DC power supply
- Register at Developer.iDigi.com
- Sign In to Developer.iDigi.com
- Click the “+” icon in the toolbar
- Select your ConnectPort
- Click OK
Your ConnectPort will display in the Devices list and show a status of “Connected” if everything is working correctly. It may take a few minutes for the status to show that it’s connected.
Notes:
- For easier setup, make sure you are connected to a computer on the same network as the ConnectPort X2.
- The install requires Java to be installed on the computer.
Setting up XIG on the ConnectPort
In order to access external web services over a wireless XBee network, you need to add XIG to the ConnectPort. XIG is an XBee Internet Gateway for the Digi ConnectPort devices. XIG will allow you to fetch URLs and ultimately connect to ThingSpeak web services and apps. You will be able to do sensor data logging, send tweets, or get data from any web page or resource using the ThingHTTP app.
The following steps are based on the ConnectPort firmware version of 2.9.0.11 and is newer than the version covered in the book, “Building Wireless Sensor Networks” by Rob Faludi. The differences for the most part is a that all of the setting are consolidated to the Management -> Devices area of the iDigi interface.
- Download latest release of XIG
- Unzip xig-X.X.X.bin.zip
- Right-click on your ConnectPort, select Administration, and Upload Python Files…
- Select Browse…
- Select “xig.py” from where you unzipped XIG
- Click OK
- Right-click on your ConnectPort, select Administration, and Upload Python Files…
- Select Browse…
- Select “_xig.zip” from where you unzipped XIG
- Click OK
- Right-click on your ConnectPort and select Properties
- Select Python option
- Check enable on first line
- Type “xig.py” in the Auto-start Command Line box
- Click Save
- Disconnect power to the ConnectPort X2
- Reconnect power to the ConnectPort X2
Notes:
- Once you have uploaded the Python scripts for XIG make sure you cycle the power for the changes to take effect.
Applications
- Add Data to a ThingSpeak Channel
- Send Tweets using ThingTweet
- Fetch and Parse Web Sites with ThingHTTP
- Get Data from a ThingSpeak Channel
Connecting a Series 2 XBee to an Arduino
There are 4 lines that you need to connect together: TX / RX serial lines and the 3.3V DC / Ground power lines. Use the hardware serial lines of the Arduino.
Pinouts:
XBee | Arduino | |
VCC or 3.3 V | 3V3 | |
TX DOUT | RX or Pin 0 | |
RX or DIN | TX or Pin 1 | |
GND | GND |
Notes:
I used the components from the BWSN Basics Kit from SparkFun. The items I used were the XBee breakout board and the solderless breadboard. The XBee breakout board converts the small headers of the XBee modem to standard spacing for plugging into a breadboard.
Sensor Data Logging
- Create a ThingSpeak Channel and note your Write API Key
- Connect an XBee Series 2 radio to a micontroller such as the Arduino development board
- Connect an analog sensor to an analog pin
- From the microcontroller send your ThingSpeak Channel Update URL to the XBee via the hardware serial lines
Love this concept…
So is the XIG code/lib looking for “http://” on the serial stream and then routing it to the associated URL?
Any idea if this would be possible from a python script in the gateway?
I did some experiments last week where I used an arduino for a PIR setup then sent the output on the serial stream (not unlike what you’re doing in this tutorial). There was a python script that grabbed the raw serial data, parsed it and sent it on to twillio for SMS delivery. That was fun.
Yeah, you have the idea. XIG just relays the requests to the specified URL and passes the whole response back through.
I imagine that you could write your own Python gateway and install it on the ConnectPort. Too bad it’s not Ruby 🙁
How would you do this with “standalone” xbees as Sensors?
What I’d like to do is use standard xbee modules as temperature/light sensors through the house. To keep things standard, I thought simply building them the same way as the “LTH Sensor” that is provided in the Digi starter kit.
Now, I can ask that sensor to periodically wake up and send his data to the X2/X4 Gateway. But… the XIG won’t be able to translate that into http requests. I think I need an additional python script on the Gateway that would receive the Xbee data updates and then send them over to XIG? Or should I better modifiy XIG? Or am I on the completely wrong track?
I forwarded your request to Digi. I am not sure how to use the XBee as a standalone sensor. I will let you know if I get any info.
The latest version of the XIG software now handles IO samples, by passing them to a URL as configured on the gateway side. It’s actually a pretty slick, flexible solution. Check item “E. I/O Sample HTTP Trigger” on this page: http://code.google.com/p/xig/wiki/UserDocumentation
Hi,
Did you find out how to use XIG on “standalone” xbees as Sensors?
“What I’d like to do is use standard xbee modules as temperature/light sensors through the house. To keep things standard, I thought simply building them the same way as the “LTH Sensor” that is provided in the Digi starter kit.”
I don’t think you need XIG to do this
If you send a
/ws/DataStream
to your X2 via the divi API explorer, you’ll get and XML packet will all of your data.
I used this technique to replicate the data being returned from the “Simple Sensor Network” example in Faludi’s book.
I just want to add that the Arduino buffers only 60 characters or so. If your URL gets really long (if you report like 5 fields) than some fields will not be updated. For my weather station I had to split up the URL in two parts:
Serial.print(URLpart1); delay(60); Serial.println(URLpart2);
The delay can be shorter, if you increase the baud rate of the Xbee connected to the Arduino.
Hope this helps.
Hi,
This a great service but I wonder why my sensor data is not being updated on my charts but the number of entries keeps increasing..Can someone help?
And are there example of code (.pde) that show the proper way to setup sending data to thingspeak?
Thanks again.
When you edit the Channel settings, you can turn on / off fields in the channel. If they are all off, the feed will not display. Charts also only show numeric data. First, see if the field is enabled, and second if there is data in your channel.
http://api.thingspeak.com/channels/(Your Channel ID)/field/1/last.txt
Replace (Your Channel ID)
By the way, the current version of the XBee Internet Gateway (XIG) can run on a standard PC (Windows, Mac, *nix) with an XStick or XBee in a USB/serial adapter. So you don’t need to buy a dedicated ConnectPort X2 if you already have a computer that’s on all of the time (like a file server).
http://code.google.com/p/xig/
On issue with the Internet Gateway is you cannot send http through this Gateway it seems…
My gateway is working fine but I cannot update my ThingSpeak channel. I’ve ordered an X2 to hopefully solve the problem.
By bad… You can send data from Arduino through Xbee zigbee to Windows Gateway… this test script works fine.
if(Serial.available() > 0 ){
String s = “http://api.thingspeak.com/update?key=keyNumber&fieldNumber=”
+ String(adjustedLightLevel);
Serial.println(s);
delay(60000);
}
Hello,
I am doing a small arduino based project using a eHealth shield made by the folks at Cooking-Hacks.
I am using a ZB Series 2 Pro radio on the main device (Arduino+ eHealth Shield + ZB S2 Pro + ZB shield) and a ConnectPort X4 as gateway.
After struggling for 3 weeks, I finally stumbled upon XIG and I feel like I may just pull it off. However I would also like to have back-up.
How can I use an Zigbee + USB adapter board with XIG? . And is it the same as the interface board (apologies for the numerous questions, I am REALLY struggling here).
Any sort of help will be greatly appreciated,
Thanks.
Have you downloaded xig for windows? https://code.google.com/p/xig/downloads/detail?name=xig-windows-1.5.1b19.zip
Install instructions here.
https://code.google.com/p/xig/wiki/Windows_Installation
You’ll also need a account for Device Cloud. If you are just doing testing you can get a developer account. http://www.etherios.com/products/devicecloud/developerzone
If you get stuck let me know… Just went though this. I’m now connected via web, desktop and android.
Hey everyone. Can anyone help me with my capstone project involving wireless communication over Xbee radios through ConnectPort X4? I do not know how to configure the ConnectPort or have the Xbees send traffic through it. Thank you!