Jamie Bennett Speaks

Thoughts from Jamie Bennett

CurrentCost and Ubuntu

Written by Jamie Bennett on December 15th, 2008 at 8:46 pm in Uncategorized

I received my CurrentCost unit today from the Eco Gadget Shop. I’m impressed with their service, it only took a few days to arrive. Anyway, as soon as I unpacked the unit and installed the cable grip, it was time to have a play.

As any self-respecting Linux geek would do, the first thing I did was try to hook the unit up to my Ubuntu Intrepid Ibex box. Theres quite a bit of information out there on logging the data that the CurrentCost unit spits out but most of it tends to lean towards the Windows/Mac OS X side or concentrates on the serial port interface of the older cables. What I wanted was a Linux and USB serial cable solution.

The first thing you need to do is setup the USB serial cable. This is pretty trivial if you know what you are doing but can be quite daunting if you don’t. First plug in the USB cable and verify that it has indeed been recognised.

A lsusb should show something along the lines of this (your output will vary but the important bit is the part that reads:


Bus 004 Device 002: ID 067b:2303 Prolific Technology, Inc. PL2303 Serial Port

Take note of the ID, its in two parts, the 067b bit and the 2303 (your numbers will most likely be different). Then its time to modprobe the USB serial driver in.

Notice that the two numbers from the previous command have been used with a ’0x’ added to the front of them. Issuing the dmesg command should show you that the USB serial driver has been loaded (look near the end of the output) and that /dev/ttyUSB0 is now available for you to read.

From this point on I really recommend you read the excellent how-to by Paul Mutton over on his website. The perl script he supplies only needs two lines changing. Change:

my $PORT = "/dev/ttyS0";

to

my $PORT = "/dev/ttyUSB0";

and

$ob->baudrate(2400);

to

$ob->baudrate(9600);


The first change is to point to the USB serial port and the second to set the baud rate to the newer units speed of 9600.

The rest of Pauls how-to will get you up and running, logging the data and producing nice looking graphs.

16 Responses to 'CurrentCost and Ubuntu'

Subscribe to comments with RSS or TrackBack to 'CurrentCost and Ubuntu'.

  1. [...] on the web. Connecting under Linux is fairly straight forward, there is fantastic article at http://www.linuxuk.org/2008/12/currentcost-and-ubuntu/. This explains how make the USB device available to read from as a device. Next you can use a Perl [...]

  2. [...] CurrentCost and Ubuntu « linuxuk.org A couple of interesting commands to run when setting up the CC128 with the data cable. (tags: currentcost serial ubuntu) [...]

  3. Hi there, just to say thanks! Your post saved me from pulling my hair out :)

    My data now logging nicely to cacti server!

    JeremyG

    18 Dec 09 at 9:52 pm

  4. That’s great to hear!

    JamieBennett

    18 Dec 09 at 10:26 pm

  5. Very useful thanks. I’ve just followed your procedure to set up reading of data from the new Current Cost model, the CC128. The only change needed was to use a baud rate of 57600 instead of 9600. Thanks.

    skyewright

    4 Feb 10 at 7:05 pm

  6. There is another change needed to use the script on http://www.jibble.org/currentcost/.

    The regexp has to be changed to

    m! *([\-\d.]+).*0*(\d+)!

    since the CC128 sends the temperature before the power not the other way around like the older devices do.

    I had a lot of problems before I disabled the regexp and could see what was actually coming out.

    Tomas

    25 Mar 10 at 7:37 pm

  7. Sorry, the regexp was filtered by this commenting function since it contained xml-tags. Hope you understand what I meant anyway…

    Tomas

    25 Mar 10 at 7:39 pm

  8. im trying to get this to work on osx 10.5.8. i know perl quite well and the script appears to connect to whatever port i point it at, but no output. I can only assume that im using the wrong port or i need to pre-configure the port somehow?
    thanks

    nick fox

    24 Jul 10 at 6:32 pm

  9. Nick – you might want to comment out the if line and everything inside the nested brackets afterward, and just use a plain old print command to see if there’s any output – as Tomas mentioned the newer CC128 gives a very different output and the regex in the given script simpy does not match, and so outputs nothing at all.

    Kristan

    29 Aug 10 at 1:46 am

  10. Just as a comment, instead of using CPAN to install the SerialPort module, you can, if you’ve got admin rights on the box, install it nicely with package manager:
    package “libdevice-serialport-perl” offers the module with short description of “emulation of Win32::SerialPort for Linux/POSIX”.

    Myrtti

    3 Sep 10 at 4:26 pm

  11. I’m not getting this working as yet .. no response, and am printing the $line out as per Paul’s example .. nothing. However, if I press the OK & down button, it goes a bit mental.
    Would love to update his script to also post to Google Powermeter, but stuck at the first hurdle …

    (Ubuntu 10.04).

    Thanks

    Nick

    29 Sep 10 at 6:14 pm

  12. [...] Avec pour l’adaptation du code au modèle USB -> http://www.linuxuk.org/2008/12/currentcost-and-ubuntu/ [...]

  13. I made a modified version of the script which works with the CC128 which is rebranded as the E.ON energy monitor currently being given free with new accounts in the UK.

    http://pastebin.com/eksBABuD

    sensimilla

    19 Dec 10 at 11:38 pm

  14. [...] that same poster as to which cable to buy and also a perl script to read from the device. Thanks to Jamie’s post for getting the USB-Serial cable [...]

  15. Many thanks to everyone for producing the code, Sensimilla’s modifications got the script working but when I try to incorporate the rrd update command it fails, is this the correct syntax? -

    rrdtool update powertemp.rrd N:$watts:$temp;

    Steve

    26 Mar 11 at 10:49 am

  16. Hello,
    With Envir (new CC128) you may need to set the parity, stopbit etc. like this :
    $ob->baudrate(57600);
    $ob->parity(“none”);
    $ob->databits(8);
    $ob->stopbits(1);
    $ob->write_settings;

    It wasn’t working for me until I added this piece of code.

    David

    31 Oct 12 at 10:19 pm

Leave a Reply