Merewether Weather, Merewether Tides and Solar Power Monitoring for Merewether, NSW, Australia - Newcastle Weather

Twitter Contact Login Search

Main

Currentcost update to Pachube

Date:
By Mangrove Mike

The code below is the first attempt at getting my original CurrentCost Classic (or WattsClever) energy monitor connected to my only Fedora Core 5 box and updating the data to Pachube.

The Classic connected without any problems (although occasionaly would swap USB ports with my Davis Station connection(???).  

Use 'lsusb' or simply 'ls -la /dev/ttyUSB*/' to find out how the Prolific Serial port drivers map your USB to serial port.

You can also tail or head the ttyUSBn port to see what is there.

Obviously you need to setup a pachube account. It all is pretty straightforward.

OK, the first cut of code to populate to Pachube is a simple bash/shell scriptas follows:

 

#!/bin/sh

APIKEY="your pachube api key"
PACHUBEURL="http://www.pachube.com/api/feeds/YOURFEED.csv"

echo "Getting Readings.."
export WATTS=`head /dev/ttyUSB0 -n1 | /bin/grep '<ch1><watts>' | /bin/sed -e s/\<ch1\>\<watts\>/\ / | /bin/cut -d' ' -f2 | /bin/cut -c1-5`
export TMPR=`head /dev/ttyUSB0 -n1 | /bin/grep '<tmpr>' | /bin/sed -e s/\<tmpr\>/\ / | /bin/cut -d' ' -f2 | /bin/cut -c1-4`

/bin/echo Power: $WATTS
/bin/echo Temp : $TMPR

if [ "$WATTS" = "" ]
then
 echo "No Watts."
 break
else
  /usr/bin/curl --request PUT --header "X-PachubeApiKey: $APIKEY" --data "$WATTS,$TMPR" "$PACHUBEURL"

echo "Updated OK."
fi
#


 

Save this script somewhere sensible and if it works OK, make it a cron job abd run it every 5 minutes (or what ever the interval you need).

 

1 comment

This original code was based upon the Gadget Man's code: http://martgadget.blogspot.com/2009/09/putting-your-watts-on-web.html

Posted by Mangrove Mike, 31/08/2010 9:59:01 am