Some successful CurrentCost hacking
Posted by james on August 22nd, 2008After a bit of work, I've finally got my CurrentCost meter working in Ruby, and I now have a power monitor sitting in my system tray! There were a few stages involved...
Serial comms: The ruby-serialport library that already existed for Ruby was no good to me. Firstly, it didn't seem to be in a working state, but more importantly, the license it is under (GPL) is no good to me. So, I had to write my own. I've created a nice simple serial library (including a gem) for Ruby called RB232, which is available on GitHub. It only supports reading at the moment, and only works on Linux systems, but it's a start. Next!
Reading CurrentCost data: Once RB232 was in place, this was pretty easy. Just create a couple of classes to wrap up the process of getting data from the meter, and away you go. Easy. Also released as a Ruby gem on Github.
User interface: Last step was to make a simple user interface for the meter, which you can see in the picture above. It's a simple tray icon that changes colour based on power usage. It's based heavily on another very useful tool called cctrayrb, so many thanks to Daniel Parnell for doing the heavy GUI lifting there. The app is included as part of the currentcost-ruby gem mentioned above.
Anyway, it's all freely available, so if you have a CurrentCost meter and a serial cable for it, you can grab the code and get going. Enjoy :)
August 31st, 2008 at 08:55 PM
Very cool software. I like the idea.
Your ruby library assumes that you have a 9600 baud current cost, it would be nice to have an option for 2400 baud ones.
I love the idea of having an observer too. I have so many ideas of different apps that would like the latest data, I was wondering about making a system where other apps could register for the observing events, even better, on different computers.
This would mean that I could run a server that parses the events from the serial port on the machine that it is plugged into at home. I could then run your desktop app at work, and have another service that puts it in a database for long-term analysis, and one that backs a website showing the current values in real time.
September 2nd, 2008 at 08:49 AM
Thanks! I didn’t realise there was a 2400 baud CurrentCost, I will change the software to allow that as an option.
The Observer stuff is a nice way of delivering notifications within the same program, for sure. Getting a more distributed approach is definitely something I want to do – the newer article talks about integrating with Pachube, which might work for this, and I want to look at getting it into AMEE as well, to enable exactly the sort of things you mentioned.