<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>killswtch.net &#187; Source Code</title>
	<atom:link href="http://www.killswtch.net/category/software/source-code/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.killswtch.net</link>
	<description>A geek's thoughts on various stuff</description>
	<lastBuildDate>Mon, 17 May 2010 20:58:48 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Power monitoring with CurrentCost</title>
		<link>http://www.killswtch.net/2009/01/03/power-monitoring-with-currentcost/</link>
		<comments>http://www.killswtch.net/2009/01/03/power-monitoring-with-currentcost/#comments</comments>
		<pubDate>Sat, 03 Jan 2009 14:45:20 +0000</pubDate>
		<dc:creator>killswtch</dc:creator>
				<category><![CDATA[Geeky]]></category>
		<category><![CDATA[Hardware]]></category>
		<category><![CDATA[Home Automation]]></category>
		<category><![CDATA[Monitoring]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[Source Code]]></category>
		<category><![CDATA[currentcost]]></category>
		<category><![CDATA[electricity]]></category>

		<guid isPermaLink="false">http://www.killswtch.net/?p=341</guid>
		<description><![CDATA[
The CurrentCost power monitor has become very popular amongst amateur home automators and those technically-savvy who want to keep an eye on how much electricity they are using (and ultimately how much they are going to have to pay in bills). A couple of months ago I purchased the CurrentCost device and a USB cable [...]]]></description>
			<content:encoded><![CDATA[<p><img class="aligncenter size-full wp-image-346" title="CurrentCost monitor" src="http://www.killswtch.net/wp-content/uploads/img_3607.jpg" alt="CurrentCost monitor" width="420" height="315" /></p>
<p>The <a href="http://www.currentcost.co.uk/" onclick="javascript:urchinTracker ('/outbound/article/www.currentcost.co.uk');">CurrentCost power monitor</a> has become very popular amongst amateur home automators and those technically-savvy who want to keep an eye on how much electricity they are using (and ultimately how much they are going to have to pay in bills). A couple of months ago I purchased the CurrentCost device and a USB cable to connect it to a computer <a href="http://stores.ebay.co.uk/Current-Cost-Ltd" onclick="javascript:urchinTracker ('/outbound/article/stores.ebay.co.uk');">from eBay</a>. Having just seen their eBay store, it looks like they&#8217;ve got a fantastic new model on the way, but this article is about the older version.</p>
<p><span id="more-341"></span></p>
<p>By itself the device works very well, providing an at-a-glance view of current power use and a history over several periods of time. There is a simple bar chart showing the relative amounts of power used in the previous day, split into day time, evening and night. However if you want a clearer understanding of how power use changes day-to-day or even over a decade, connecting the device to a computer will provide the ability to store every reading in a database and/or produce live graphs of usage.</p>
<p><a href="http://andypiper.wordpress.com/2008/04/27/current-cost/" onclick="javascript:urchinTracker ('/outbound/article/andypiper.wordpress.com');">Several</a> <a href="http://gibbalog.blogspot.com/2008/07/graphing-current-cost.html" onclick="javascript:urchinTracker ('/outbound/article/gibbalog.blogspot.com');">people</a> <a href="http://rooreynolds.com/2008/05/09/current-cost-charting-fun/" onclick="javascript:urchinTracker ('/outbound/article/rooreynolds.com');">have</a> <a href="http://knolleary.net/2008/05/05/power-graphing/" onclick="javascript:urchinTracker ('/outbound/article/knolleary.net');">written</a> articles on how to do the logging, each using a slightly different method (and language) to do so. Most of them are for linux though, but any programmer should be able to port the ideas across to a different platform such as Windows or Mac OS. For my implementation, I followed <a href="http://www.jibble.org/currentcost/" onclick="javascript:urchinTracker ('/outbound/article/www.jibble.org');">this guide on jibble.org</a>.</p>
<p>This is what my perl script turned out like:</p>
<pre>#!/usr/bin/perl -w
# Reads data from a Current Cost device via serial port.

use strict;
use Device::SerialPort qw( <img src='http://www.killswtch.net/wp-includes/images/smilies/icon_razz.gif' alt=':P' class='wp-smiley' /> ARAM :STAT 0.07 );

my $PORT = "/dev/ttyUSB1";
my $ob = Device::SerialPort-&gt;new($PORT);

$ob-&gt;baudrate(9600);
$ob-&gt;write_settings;

open(SERIAL, "+&gt;$PORT");
while (my $line = &lt;SERIAL&gt;) {
    if ($line =~ m!&lt;ch1&gt;&lt;watts&gt;0*(\d+)&lt;/watts&gt;&lt;/ch1&gt;.*&lt;tmpr&gt;([\d.]+)&lt;/tmpr&gt;!) {
        my $watts = $1;
        my $temp = $2;
        print `/usr/bin/rrdtool update /var/scripts/currentcost/powertemp.rrd N:$watts:$temp`
    }
}</pre>
<p>Note that because I&#8217;m connecting via a USB port, the serial port name is different. The baud is also 9600 rather than 2800. I have set this script to run at startup (detatched from the console) so that it is always running in the background.</p>
<p>I have also produced another simple script, which is run every minute as a cron job.  The script generates the graphs from the data stored in the RRD file, and uploads them to my web server via SSH.</p>
<pre>#!/bin/sh

rrdtool graph /var/scripts/currentcost/power-10min.png --start end-10m --width 323 --end now --slope-mode --no-legend --vertical-label Watts --lower-limit 0 --alt-autoscale-max DEF:Power=/var/scripts/currentcost/powertemp.rrd:Power:AVERAGE LINE1:Power#0000FF:"Average" &gt; /dev/null
rrdtool graph /var/scripts/currentcost/power-60min.png --start end-60m --width 323 --end now --slope-mode --no-legend --vertical-label Watts --lower-limit 0 --alt-autoscale-max DEF:Power=/var/scripts/currentcost/powertemp.rrd:Power:AVERAGE LINE1:Power#0000FF:"Average" &gt; /dev/null
rrdtool graph /var/scripts/currentcost/power-day.png --start end-24h --width 323 --end now --slope-mode --no-legend --vertical-label Watts --lower-limit 0 --alt-autoscale-max DEF:Power=/var/scripts/currentcost/powertemp.rrd:Power:AVERAGE LINE1:Power#0000FF:"Average" &gt; /dev/null
rrdtool graph /var/scripts/currentcost/power-week.png --start end-1weeks --width 323 --end now --slope-mode --no-legend --vertical-label Watts --lower-limit 0 --alt-autoscale-max DEF:Power=/var/scripts/currentcost/powertemp.rrd:Power:AVERAGE LINE1:Power#0000FF:"Average" &gt; /dev/null
rrdtool graph /var/scripts/currentcost/power-month.png --start end-1months --width 323 --end now --slope-mode --no-legend --vertical-label Watts --lower-limit 0 --alt-autoscale-max DEF:Power=/var/scripts/currentcost/powertemp.rrd:Power:AVERAGE LINE1:Power#0000FF:"Average" &gt; /dev/null
rrdtool graph /var/scripts/currentcost/power-year.png --start end-1years --width 323 --end now --slope-mode --no-legend --vertical-label Watts --lower-limit 0 --alt-autoscale-max DEF:Power=/var/scripts/currentcost/powertemp.rrd:Power:AVERAGE LINE1:Power#0000FF:"Average" &gt; /dev/null

#Copy locally
cp /var/scripts/currentcost/*.png /var/www/currentcost/

#Upload to mars
/usr/bin/scp /var/scripts/currentcost/*.png root@192.168.2.3:/var/www/vhosts/currentcost.elemental.killswtch.net</pre>
<p>You can see the result on the <a href="/power/">Power</a> page of this site. The graphs at the moment are fairly basic. The Jibble article includes some extra data in the graphs, which I will probably add at some point. For the moment though it does the job very well.</p>
<p><img class="aligncenter size-full wp-image-347" title="img_3599" src="http://www.killswtch.net/wp-content/uploads/img_3599.jpg" alt="img_3599" width="420" height="315" /></p>
<p>The CC device is located downstairs, in the living room. Thanks to the serial output connector being an RJ45 socket, it was very easy to plug it into the exising CAT5 network (which I&#8217;m very glad I did) and run the signal to the cabinet in my room where it is then broken out through the RJ45 patch panel, through the RS232/USB cable and into the fileserver <em>boron</em>, which hosts the scripts.</p>
<p><img class="aligncenter size-full wp-image-348" title="USB cable" src="http://www.killswtch.net/wp-content/uploads/img_3601.jpg" alt="USB cable" width="420" height="315" /></p>
]]></content:encoded>
			<wfw:commentRss>http://www.killswtch.net/2009/01/03/power-monitoring-with-currentcost/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Source code for the VAMS-0808 serial interface</title>
		<link>http://www.killswtch.net/2008/08/23/source-code-for-the-vams-0808-serial-interface/</link>
		<comments>http://www.killswtch.net/2008/08/23/source-code-for-the-vams-0808-serial-interface/#comments</comments>
		<pubDate>Sat, 23 Aug 2008 07:13:24 +0000</pubDate>
		<dc:creator>killswtch</dc:creator>
				<category><![CDATA[A/V]]></category>
		<category><![CDATA[Home Automation]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[Source Code]]></category>

		<guid isPermaLink="false">http://www.killswtch.net/?p=312</guid>
		<description><![CDATA[As promised, here&#8217;s the source code for my VAMS-0808 interface. It&#8217;s in C#, with C# projects included, and can be opened in Visual C# Express or full Visual Studio 2005 or greater. There are two test projects included &#8211; one which just writes status changes out to the console, and a WinForms project (which runs [...]]]></description>
			<content:encoded><![CDATA[<p>As promised, here&#8217;s the <a href="http://www.killswtch.net/files/HALibs.VAMS0808.zip" >source code for my VAMS-0808 interface</a>. It&#8217;s in C#, with C# projects included, and can be opened in Visual C# Express or full Visual Studio 2005 or greater. There are two test projects included &#8211; one which just writes status changes out to the console, and a WinForms project (which runs in mono) for full interaction.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.killswtch.net/2008/08/23/source-code-for-the-vams-0808-serial-interface/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
