Tweet-a-Watt
------------------------------------This project involved hacking a common Kill-a-Watt power meter to transmit data wirelessly usign an Xbee to my computer (Mac), and then upload the data to two different websites (Pachube.com & Google App Engine) to display graphically.
Google App Engine
The tutorial on how to hack the meter is very well documented (and there is even a kit) at Ladyada's site. Included in the tutorial is also the python scripts and info on getting the data to plot using the Google App Engine. My plot for the past week is below. There are different plot styles available, this one is a time plot just like Google uses for stock prices. You can slide and change the time scale which I think is very nice.
Pachube
A much simpler and more useful alternative to plotting with Google is to use Pachube. Pachube allows you to upload your live data and share it with others. Likewise, you can use other people's data feeds to control something locally or use many feeds to make composite plots, etc. The data is submitted using a fairly simple protocol called Extended Environments Markup Language (EEML) which you can learn about at Pachube. The only downside is that currently you can only access data from the past 24 hours, but that will change eventually.
To upload my data, I used one of the basic python scripts available on ladyada's site and modified it to send the data tagged in EEML using this python library python-eeml from petervizi. Here is my resulting Pachube data feed and a Flash plot below which updates every 15 minutes (the data feed however can be as frequent as 5 seconds).
Python Code for Pachube
You can dowload my python code to interface the tweet-a-watt with Pachube here. You will have to modify a few lines of the code for your specific project in addtion to that needed for the original script following ladyada's tutorial. My suggestion is to get your Tweet-a-Watt working with the original ladyada scripts first, and then add these lines of code to interface with Pachube. The lines you will have to add are as follows:
# For Pachube
import eeml
# parameters
API_KEY = 'YOUR API KEY'
API_URL = 'http://www.pachube.com/api/YOUR FEED.xml'
At the top of the scropt you will have to import the eeml library, then you will have to define your unique API key and feed address both of which you will get when you sign up with Pachube and start a new feed.
# Send Data to Pachube
pac = eeml.Pachube(API_URL, API_KEY)
pac.update(eeml.Data(0, sensorhistory.avgwattover5min(),minValue=0, maxValue=None, unit=eeml.Unit(name='watt', type='derivedSI', symbol='W')))
try:
  pac.put()
except:
  print "pachube update failed"
Later in the script there is a loop where the power is averaged over the past 5 minutes. Here you will insert the above code which will send that average power value to update your Pachube feed as well as properly tag in eeml with unit name, symbol, min and max values etc. I had to include the try and except operators because sometimes the put command fails and kills the whole script unless they are included. At this time I have not figured out how to change the update frequency from 5 minutes, but I'm sure it isn't very difficult.
Just to be complete, there are two other variables you will have to define to get your script working properly, though if you go through the ladyada tutorial you will already have done it. The two parameters are your serial port that your Xbee is communicating on and the calibration value for your specific meter, both of which are explained in the tutorial. The code looks like the following:
SERIALPORT = "YOUR SERIAL PORT" # the com/serial port the XBee is connected to
vrefcalibration = [0,481] # Calibration for sensor #0 & #1
You will have to change that value of 481, which is the calibration value for my meter, to whatever your meter calibration value is. The value should be in the 500 range. Please note that the readings will jump around a bit (~10% see forum) and not exactly match the display. It's a limitation of the hardware.