Raspberry Pi as an Xbee Wireless Sensor Network Gateway

Notes about Raspberry Pi, an ARM based pc about the size of a deck of cards which costs $35. I might use it as a replacement for the Asus WL520 GU wifi modems I’ve been using as an Xbee WSN Gateway.

RaspberryPi.jpg

General References

OS

I started out with the 4G SD Card from Newark that was pre-loaded with wheezy-debian. Now I’m using the distro from Adafruit called Occidentalis v0.2.  It includes ssh and other features that makes it easier to confugure.

Copy the image to a 4G SD Card using Win32DiskImager.  Basically you download an OS image to a windows machine and copy it to an SD Card.  When using WinDiskImager, pay close attention to your read/write actions because it’s possible to overwite the wrong drive.

Before selecting an SD Card, look at the list in Verified Peripherals.  Not all SD Cards work the same, and I spent a lot of time trying to launch the OS even though the image copy was successful.  If you get to the point where you’ve successfully copied the image but it won’t boot up, cut your losses and try another SD Card.

  • login as: pi, password: raspberry
  • I set up a root account and did most of the installation as root

Expanding the partition on the sccard

Once installed, expand the SD Card partition to fill the 4G memory space. The image on the 4G sdcard is 1.8G. This describes how to expand the partition to fill the entire 4G.

SSH

Set up SSH so you can access the Raspberry Pi from a terminal program of via Putty and/or WinSCP.

ssh-keygen -t rsa -C "your_email@youremail.com"

XBee connection

I used the CISECO daughter board kit which costs about $6 which has a GPIO connector and a place to hook up an xbee to the serial port on the GPIO.  It derives the 3.3V from the GPIO and it includes an array of through holes for misc prototyping.

  • XBee Radio PCB daughter board– by CISECO – basically a breakout board for the GPIO connections with access to the serial port and 3.3V.
  • Getting started with GPIO and PythonThis is the first of two articles showing basic GPIO on the Raspberry-Pi using the prototype area of the Slice of Pi. This covers basic details on the GPIO pins, setting up a Python library to allow access to the GPIO. There is an example circuit to build on the Slice and some code to get the outputs working. This was originally a blog post on Matts blog at http://lwk.mjhosting.co.uk

pi_001th.jpg

Raspberry Pi with XBee daughterboard, Slice of Pi

Raspberry Pi with XBee daughterboard, Slice of Pi

On the Adafruit distro, Occidentalis v0.2, I was having some issues with reading the serial port in my python code.  I kept getting erros related to the serial port being in use.  Some research got me to this article on the RaspberryPi.org site and this article from Clayton’s Domain.  I edited a file, /boot/cmdline.txt, and this is what it came down to (all on one line):

/boot/cmdline.txt
dwc_otg.lpm_enable=0 rpitestmode=1 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 rootwait

Install Apache on Raspberry Pi

Eventually I will want to set up a web interface to allow users to edit the gateway config items, like the network protocol and to manage the various sensors, python scripts, etc.  For now, I’m just going to manage it it by ssh command line.

  • http://tinkernut.com/wiki/page/Episode_320
  • Webmin– “Webmin is a web-based interface for system administration for Unix. Using any modern web browser, you can setup user accounts, Apache, DNS, file sharing and much more. Webmin removes the need to manually edit Unix configuration files like /etc/passwd, and lets you manage a system from the console or remotely.”
  • Raspcontrol– PHP based Dashboard application. More about status then configuring.

Installing Python components

Rasberry Pi, default linux install, has python already installed.

I needed these modules to allow me to access various web services like Cosm (pachube), Thing Speak, Open.Sen.se, and my own SOAP based service that I wrote in C#.

pyserial

We need some extra libs to run the sensor programs.

Check if python is installed and what version is installed

python -V

Change directory:

cd /home/tinaja/downloads/

WGet the file then unpack it:

wget http://sourceforge.net/projects/pyserial/files/pyserial/2.5/pyserial-2.5.tar.gz/download
tar -zxvf pyserial-2.5.tar.gz

cd pyserial-2.5
python setup.py install

simplejson 2.6.1

simplejson 2.6.1 is compatible with python 2.5.

Change directory:

cd /home/tinaja/downloads/

WGet the file then unpack it:

wget http://pypi.python.org/packages/source/s/simplejson/simplejson-2.6.1.tar.gz
tar -zxvf simplejson-2.6.1.tar.gz

cd simplejson-2.6.1
python setup.py install

suds

The suds libs provide services for SOAP calls.

Need to install python’s setup tools:

apt-get install python-setuptools

Change directory:

cd /home/tinaja/downloads/

wget https://fedorahosted.org/releases/s/u/suds/python-suds-0.4.tar.gz
tar -zxvf python-suds-0.4.tar.gz

cd python-suds-0.4/
python setup.py install

eeml

Used by Cosm (pachube)

http://pypi.python.org/pypi/python-eeml/1.1.0
? git clone git://github.com/petervizi/python-eeml.git

# cd /home/tinaja/downloads/
# wget http://pypi.python.org/packages/source/p/python-eeml/python-eeml-1.2.0.tar.gz
# older version - wget http://pypi.python.org/packages/any/p/python-eeml/python-eeml-1.1.0.linux-i686.tar.gz
# tar python-eeml-1.2.0.tar.gz
# python setup.py install

Code

I’ve loaded the python code I’m using on GitHub:
https://github.com/TinajaLabs/gateway_raspi

Wifi

The Raspberry Pi can be wifi enabled with a USB based wifi device. The main concern would be with power consumption; the raspberry pi runs off of a 5V (currently 700mA) supply (like a cell phone charger) and a wifi device might strain the load.

For now (8.26.2012) the wired ethernet configuration works great.  It can just plug into a IP provider modem.

To change the boot-up text

Did this to brand the OS as one I set up.  Only for show…

edit /etc/moto.tail

The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.

Type 'startx' to launch a graphical session

This version, from Adafruit's Occidentalis v0.2, set up by:
 _____ _              _         _          _         
|_   _(_)_ __   __ _ (_) __ _  | |    __ _| |__  ___ 
  | | | | '_ \ / _` || |/ _` | | |   / _` | '_ \/ __|
  | | | | | | | (_| || | (_| | | |__| (_| | |_) \__ \
  |_| |_|_| |_|\__,_|/ |\__,_| |_____\__,_|_.__/|___/
                   |__/ TinajaLabs.com, Summer 2012
-----------------------------------------------------

To set a program to start at boot-up

To automatically run the main python script, allsensors.py, when the computer starts…

Edit /etc/rc.local and add the python line shown below:

#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.

# Print the IP address
_IP=$(hostname -I) || true
if [ "$_IP" ]; then
  printf "My IP address is %s\n" "$_IP"
fi

# add this for Tinaja Labs sensor tracking
python /home/tinaja/allsensors.py &

exit 0

To set up Tomcat Server

At some point I might want to set up a Tomcat server and use it with some Java apps.  Later.

Java

To watch the message log file

This allows you to see the system messages generated by the script as it sends various sensor readings to the web services.

cd /var/log/
tail -f messages

To kill the Tinaja python script

Look for the process id of the python script with this command:

ps aux # for a full list
ps aux | grep python  # to see only python processes

Take note of the process id number and issue this command:

kill 9999 # where 9999 is the process id number

That’s all I have for now, hope you found something useful here.

Maker Faire 2012

Come visit us at Maker Faire!

I just got the confirmation email that I’ve been accepted to have a booth at this year’s Maker Faire.  The booth is called A Sense of Things, as it was last year, and is numbered 7443.   I hope to visit with all my sensor friends on Saturday and Sunday, May 19th, 20th.

I’ll be showing our latest development on a low cost wireless sensor network designed for the “everyman” or “everywoman” who wants to track things in and around their homes.  Please stop by for a visit.

To sign up for the maker Faire:  http://makerfaire.com/be-a-maker.csp

 

The new Nest Learning Thermostat – $250

A friend sent me a link to this article  about the new Nest Thermostat and I got very excited; went to the site to put in my order… rrrrP!  (that’s the sound of me hitting the brakes)

$250?  Why does cool have to cost so much?

I have been building my own home wireless sensor network for the last 2 years. Temperature, light, hall effect, gas detection, FSRs, the Tweet-a-watt, etc. using XBee modules and a wifi gateway that uses an open source OS (OpenWRT) and Python scripts to send data to web services (like Pachube.com, ThingSpeak, Open.Sen.se).  I’ve been studying home energy automation for a couple of years now and I’m beginning to understand the various aspects of what it takes to put together components to collect and communicate meaningful, actionable information.

The Nest Learning Thermostat has some cool features.  It learns… and that’s fantastic.  As I understand it, you can set the thermostat up or down at different times and it will remember what you set and build a schedule that repeats your preferences. That’s very cool. It has a motion detector to sense the presence of people in the house and turns the system down/off. That’s cool, too. But there are some serious issues that I see over and over in this field.

First off this device costs too much. It should be priced at somewhere below $50 for the thermostat. That would put it at a price point to get it into the homes of many more people. The more consumers use it, the more we can reduce our dependence, as a nation, on foreign sources of energy. That’s a national, heck, a global goal, right?

Next, I don’t see any way to help consumers understand meaningful and detailed results of the savings they create by using the thermostat. They might see an overall drop in their gas or electric bill, but how much can be attributed to the thermostat as opposed to the incandescent bulbs they replaced with CFLs, or by the shading of a porch, or by being more diligent in turning off the entertainment system (including the STB) and vampire loads.

Also, the designers have created a thermostat in a very traditional form. IOW, they’re not “thinking different”. The learning aspect is interesting, but I’d rather just go to my android app, or the web site and just start with a default profile for my region, house size, etc, and adjust to taste. Otherwise, I’ll not look at it again unless there is an exception to the rules, like going on a long weekend vacation.

Similarly, the designers are stuck with the concept that we need a thermostat on the wall and that we would ever want to get up off the couch and go look at it. Why spend the effort in a device that shouldn’t even require a UI. IOW, the phone app or web page should be the preferred UI.

A “think different” approach might have a temperature sensor and a motion detector in each room and these very cheap components can inform the HVAC controls how to adjust for optimum comfort vs cost. The display and controls don’t need to be on a wall in the hallway… That’s as old as the the round Honeywell thermostats people were referencing in the comments on the Wired Magazine article.

I also believe that the display devices that you get with most home automation system, perhaps in the style of elaborate refrigerator magnets with displays, are destined, too soon, for garage sales and Goodwill stores. Let’s extend the devices that we already have for control surfaces, like tablets, smart phones, game consoles. For those who don’t have smart phones in their homes, how about something like a cheap android phone form (w/o the phone functions), music players, remote controls, wifi tether devices; any devices that can support apps.

I believe profit is deserved by all who work but how much is enough? If you look at Chris Anderson’s approach describing how to make a profit on your products (), you would sell at 2.3 times the cost of parts; and that’s a good profit margin. If I did my math right, it looks like the BOM costs about $108.

I suppose they might be adding in some of the costs of running a free web service that stores all the data so clients can see the ongoing history of their thermostat settings correlated to the temperature of their house and the local weather.

Lastly, my impression is that the design isn’t finished. Design doesn’t stop until you’ve optimized the functionality, the design, and the cost. In this era of programmable microcontrollers, arduino shields, MEMS sensors, surface mount components, standard protocols, inexpensive cloud based web services, the Internet of Things… we need to delight consumers by making the products attractive, pervasive, and affiordable…  for everybody.

http://nest.com

http://www.wired.com/gadgetlab/2011/10/nest_thermostat

http://blog.ponoko.com/2010/11/16/ten-rules-for-maker-businesses-by-wireds-chris-anderson/

Tendril's Hybrid-HAN

Tendril has a post on their blog that talks about an emerging style of energy monitoring connectivity that they are calling a Hybrid-HAN (home area network).  It envisions a dual network, one that utilizes a the Utility’s smart meter and a second provided b y the consumer; a wifi router, for example.  They figure this is a good thing because it will unburden the smart meter from the growing list of sensors and controls that will become more popular as consumers learn to understand the benefits of monitoring their home environment.

The consumer side of the system uses something called the ZigBee Smart Energy Profile.  Not sure about the Smart Energy Profile but Zigbee is a well known low power wireless protocol that I’ve been experimenting with for a low power, inexpensive monitoring system.  Each Zigbee (aka xBee) module can transmit or receive signals that cover most residential buildings and costs about $20.

Interestingly the image shows the data from the consumers gateway (basically a specialized router) being fed back to the utility company but I’m not sure that’s the way it will play out.

In the future, data locality will not be so crucial.  There are always concerns about this or that silo of data that stands alone and unaccessible from external sites.  But as we grow to understand the benefits of shared data, any system will be able to aggregate date from any other system (with proper authentication of course).

Fun with Google Charts

I was working on some Google Charts and came across this one.  Here’s my new business card:

Tinaja Labs Blog

Tinaja Labs Blog

http://chart.apis.google.com/chart?cht=qr&chs=300x300&chl=https://tinajalabs.wordpress.com

As they say, “read ’em and weep”.

From the overview of Google’s QR codes charts:

“QR codes are a popular type of two-dimensional barcode. They are also known as hardlinks or physical world hyperlinks. QR Codes store up to 4,296 alphanumeric characters of arbitrary text. This text can be anything, for example URL, contact information, a telephone number, even a poem! QR codes can be read by an optical device with the appropriate software. Such devices range from dedicated QR code readers to mobile phones.”

Anyone have a laser reader? Here’s one:

http://www.quickmark.com.tw/En/basic/index.asp

Here’s a sample app to read a QR code from your smartphone:

Knitting QR codes:

Earth Hour

Today was Earth Hour day where people from all over the world call for action on climate changing policies by turning out as many lights as possible for at least one hour of the evening.  Check out their video:

Visit their site: http://www.myearthhour.org/

Bloom Box

Bloom Energy's "Energy Server"

Bloom Energy's "Energy Server"

I’m not sure I’m convinced that the Bloom Box, featured on CBS’ 60 Minutes last week, is a reasonable answer to our power issues, but is sounds interesting.  And, after 8 years in development and $400m in VC funding and some actual systems in place at Google and Wal-Mart (customers), it seems there’s no looking back for the Bloom Energy’s Bloom Box.

What is the Bloom Box.  It is essentially a fuel cell that uses natural gas and special low cost components.  The fuel cell itself looks like an 8″ stack of CDs but the power unit, the Bloombox or Energy Server, is about the size of 2 refrigerators; and costs about $700,000-$800,000.  Each!  The installation at Google’s campus looked like they had about 20-30 units.  That’s a good start against the $400m investment.

Of course the outrageous price might be likened to the $10,000 PCs that are now many times more powerful and cost on the order of $500.  So what costs hundreds of thousands of dollars now might be a few thousand dollars in, oh, perhaps 20 years?

The promise of a Bloombox is that someday we can have our own Bloombox next to the AC unit on the side of our house and be completely free of the grid; except…  we will still need natural gas to power the fuel cell.

Call me cynical, but for now I’m a bit skeptical.  We will still need to pay for natural gas (the old fuel), we still need to pay for a bloombox (whenever it comes down to being affordable by people like me), and because of the VC investment, they’re sure to have all the patents locked down.  It’s unlikely therefore that we can go buy a knock-off “Boombox”.

I think it’s interesting that they’re calling the box a “Power Server”.  Great marketing.

Here’s a flash presentation from Bloom Energy’s site about how the fuel cell works:
http://bloomenergy.com/products/solid-oxide-fuel-cell-animation/

Good Review: blog.mapawatt.com/2010/02/21/bloom-box-an-unveiling-of-the-fuel-cell-future/

Another view: cleantechblog.com/2010/02/saving-cleantech-bloom-town-silicon.html

The Fuel of Life, ATP?

Perhaps research on how ATP, is broken down in cells might lead to a new energy source.

Researchers determine how ATP, molecule bearing ‘the fuel of life,’ is broken down in cells

March 1, 2010

Researchers at the Louisiana State University Health Sciences Center have figured out how ATP is broken down in cells, providing for the first time a clear picture of the key reaction that allows cells in all living things to function and flourish.

http://www.physorg.com/news186584297.html

Who owns your thermostat?

Once the smart meters have replaced your old analog power meters the next step is access to the appliances in your house allowing your power provider to control when you use those appliances.

Interesting to think about….

Here’s an interesting post on Home Energy:
http://www.homeenergy.org/blog.php?id=30&blog_title=Who_controls_your_thermostat?

Home Energy Saver – Our Government at Work

Developed for DOE by the Environmental Energy Technologies Division at Lawrence Berkeley National Laboratory this site is a preliminary test version of a new web-based energy efficiency calculator, designed for residential home energy auditors and inspectors.

Interestingly, Microsoft has licensed the technology for their energy calculator application known as HOHM.

Apparently they have a service based API.  I’m going to research that and see what it looks like.