CurrentCost Power Monitor Software

cc128-large_01 I recently bought a device to monitor our household energy consumption. After looking at a few I lumped for a CurrentCost Envi. this is a great little device that comes in two parts – a transmitter with jaws that wrap around the main power cable coming into your home and a desktop display unit. The communication is all wireless and I have found that it works okay through two thick brick walls.

the reason for going with this particular unit was that it has a data port that can connect to a USB port and feed it’s readings to a PC – I wanted to be able to monitor the readings on my PC and chart/analyse them at will.

imageThe communication to the PC is basically via USB, but emulating a serial port COM connection – the CurrentCost website has links to the drivers you’ll need for this.

I wanted to, not only, record the readings but to chart them (on my website), get regular updates via various notification methods and a few other bits. Unfortunately, none of the software applications listed on their website covered all the items that I wanted – so I set about writing something myself…

My initial thoughts were around just sending the data to Google PowerMeter, but at that stage the API was not public and their forums/groups were not very active (6 posts in about 18 months), so I abandoned that and decided a ‘DIY’ approach was needed.
UPDATE: It looks like there may be some substance to it now, so that is another area to look at (another plugin)…

imageThe requirements were pretty simple – I wanted a service that grabbed the readings as they came in, decoded them into something intelligible and then pushed them out to a number of ‘modules’ that would do something with the reading. the ‘modules’ would be self contained and new modules could be added at any time. The initial modules would be :-

  • Tweet the reading at a regular interval
  • Record the reading (in a database, Xml file or the like)
  • Send the reading to a website / webservice

It seemed a simple Windows Service with a COM port would be enough to grab the reading, the readings are all in Xml so another class to parse the Xml would be needed and then for the ‘modules’ a ‘plugin’ type architecture was called for. I came up with an interface that all plugins would implement and a method of loading them in dynamically.

Each plugin would inherit from the IPowerMonitorPlugin interface and to load the plugins, each one would be specified in the app.config file with a filename and classname. The service would look at each plugin entry, load the DLL and create an instance of the plugin class :-

    private void LoadPlugins()
    {
        plugins = new ArrayList();

        NameValueCollection appSettings = ConfigurationManager.AppSettings;
        foreach (string key in appSettings.AllKeys)
        {
            if(key.ToLower().StartsWith("plugin"))
            {
                string path = AppDomain.CurrentDomain.BaseDirectory;
                string[] config = appSettings.Get(key).Split(':');
                Assembly ass = Assembly.LoadFile(path + config[0]);
                IPowerMonitorPlugin plugin = (IPowerMonitorPlugin)ass.CreateInstance(config[1]);
                if (null == plugins)
                {
                    plugins = new ArrayList();
                }
                if (!plugins.Contains(plugin))
                {
                    plugin.Init();
                    plugins.Add(plugin);
                }

            }
        }
    }

When the service was working and decoding the readings correctly, I started adding plugins – first was a simple ‘RawXmlWriterPlugin’ – this simple wrote the raw Xml reading data (Reading.RawXml) out to a text file – just to make sure it was working and we were decoding the Xml correctly.

imageThe next service was posting the data to a website – I found this great website (pachube.com) which allows you to track environmental data measurements, have multiple feeds, multiple measurements and has a lot of options for getting data in and out. The API that they provide is pretty simple to push data into and their website allows plenty of ways to visualize the data – for example here is a link to my last 24 hours energy consumption in a chart format, here is my latest temperature reading and here is an archive of all the energy data I have ever posted. there are also mash up to things like iGoogle widgets, Google’s Visualization API, Google Sketchup, iPhone Apps, Android Apps and this rather neat gauge.

From there I started the Twitter service….

 

imagePachubePosterPlugin

The plugin for posting to Pachube requires that you have already create a feed with two datastreams (datastream 0 is energy and datastream 1 is temperature). You will need an API Key and the feed id. Both these items are configured in the app.config file also.

TwitterPlugin

The plugin for ‘tweeting’ to twitter is also pretty simple – all you need is an account (username and password) and the ‘handle’ of the person/account you want to send the message to (if you want to send a direct message). You also specify the message text you wish to send (with placeholders for the energy and temperature values) an the interval (in minutes) of how frequently you wish to send the tweets.

SQL / Xml Storage Plugin

Watch this space … 😉

Source and Package

For the time being either send me an email or post in the comments if you’d like access to the source code.

If you want to run this software yourself then here is a link to a zip file containing the full package. To get it installed, do the following :

  • imageUnzip the package contents into a folder (“C:Program FilesPowerMonitorService” would be good)
  • Open a command prompt and change to the folder above
  • Run the following command line…

“C:WindowsMicrosoft.NETFramework64v2.0.50727InstallUtil.exe” PowerMonitorService.exe (if you are running a 64 bit machine… or)
“C:WindowsMicrosoft.NETFrameworkv2.0.50727InstallUtil.exe” PowerMonitorService.exe (if you are running a 32 bit machine… or)

 

  • Open the PowerMonitorService.exe.config file (in Notepad) and edit your configuration as needed – save when done.
  • Now start the service (Windows..Run..services.msc, find the one named PowerMonitorService, right click and choose “Start”)

Enjoy…

GEO 51.4043388366699:-1.2875679731369
  • Great post, awesome app – thanks! I came across your article when looking for a com port virtualisation tool which *would* allow me to run the current cost software + another application and pull the data from (virtual) COM ports.
    I’ve also been struggling with the limitations of the CurrentCost Google Power Meter application – just wondering if you’ve looked back into pushing data up to GPM now that the API has been released? The location I must use for my data logging appliance means that the wireless network is marginal at best, something the CurrentCost software does not handle at all well (but yours appears to be far more graceful in times of non connectivity).

    I’ll be most interested in how you continue to use and/or develop this nice wee piece of functionality…

    Cheers,

    @NZRob

  • (Not sure if this already posted for moderation, the for is looking a wee bit weird at this end)

    Great post, awesome app – thanks! I came across your article when looking for a com port virtualisation tool which *would* allow me to run the current cost software + another application and pull the data from (virtual) COM ports.
    I’ve also been struggling with the limitations of the CurrentCost Google Power Meter application – just wondering if you’ve looked back into pushing data up to GPM now that the API has been released? The location I must use for my data logging appliance means that the wireless network is marginal at best, something the CurrentCost software does not handle at all well (but yours appears to be far more graceful in times of non connectivity).

    I’ll be most interested in how you continue to use and/or develop this nice wee piece of functionality…

    Cheers,

    @NZRob

  • Ken

    Spotted your site for the Pachube currentcost app..

    Thanks it works a treat and does what it says..

    Keep up the good work. Would love to see the SQL bit as im intrested in keeping the data myself and trying to make sence of it.

    thanks again

    Rob

  • Carl Malley

    Hi Great work, I would love a copy of the source so i can add my own features, SQL database web service etc.

    Carl

  • Very interesting work! I’m currently trying to get an academic study underway with a number of the current cost bridges (data stored to pachube/cosm) but the bridges are notoriously unreliable which makes a robust study impossible. Your service sounds like the beginning of a good solution but I would need the SQL storage part.

    Carl, did you ever implement the SQL database side yourself as posted?

    cheers!
    Derek

    • kjhughes

      Derek,

      Not sure if I ever implemented the SQL option – but there is a Pachube storage option (doesn’t require CC Bridge)
      Hope that helps – let me know how it goes…

      .. Ken

  • Thank for the reply Ken, am just about to have a go with it.

    cheers!
    Derek

    • kjhughes

      Excellent – I might crack open the code again myself, as I just got a CC “Individual Appliance Monitor”, which sends data on another channel – not sure I pick that up yet…

      Let me know if you need anything…

      .. Ken

      • Got the service up and running and now seeing what I can do with it, nice work again Ken 🙂 To put you in the picture I’m designing an energy intervention for a large office – very different from the domestic setting – and have built a desktop widget for my university’s corporate desktop. The widget will display energy data from current cost IAM’s (around 20 of them!). I only use the IAM feeds, there is no main feed aggregate feed i.e. clamp on main meter.

        So far I’ve been experimenting with the current cost bridge and it’s very unreliable on corporate networks (looks like DHCP issues). I’ve ran several studies in domestic settings with around 10 of the bridge and they work ok’ish but still need rebooting from time to time.

        My plan is go ahead and try the bridge in a pilot office study but really now looking for an alternative and more reliable solution that also allows the use of pachube (now cosm). Your service seems ideal, just need to ensure I can get to the IAM feed data, sure this isn’t too much of a problem!

        If it’s ok I could probably use your source code to build this in if it isn’t already.

        cheers!
        Derek

  • Hi again all, I’ve had a go at it for few hours and everything appears to work for a standard setup, however when you add IAM’s into the mix it doesn’t work as expected, which is a shame! I’m pretty sure IAM’s weren’t around when Ken originally posted on this topic so that’s probably why.

    As a start the code uses the old v1 API, now deprecated, the new one (v2) with documentation is here http://cosm.com/docs/v2/

    I tested with 2 IAM’s (no main clamp) and the xml data comes out labelled as sensor 1, sensor 2 etc:

    CC128v1.290050408:59:4925.1201861100180

    CC128v1.290050408:59:5225.4100801100038

    What this does is post each line to pachube/cosm in quick succession to the same feed and to the same datastreams giving you a graph that looks like this:

    https://dl.dropbox.com/u/10138924/images/pachube%20test.PNG

    A fix might be posting to the datastream in the main feed corresponding to each unique sensor (1-9) in the xml output. I’m currently looking at the source code on codeplex http://energymonitor.codeplex.com/ but development isn’t my day job and could take me some time to figure it out!

    cheers
    Derek

    • kjhughes

      Derek,

      Looking at the code again, it seems that it just picks up the reading data (ignores the sensor number) and uses it.

      Let me have a noodle around and see if I can incorporate the sensor ID into the reading / parsing and how that can be brought through to the plugins…

      .. Ken

      • kjhughes

        Derek,

        Emailed you some updates that should allow you to post individual sensor data to individual Pachube feeds…

        .. Ken