Recording CurrentCost Data & Viewing It On The Web

Overview

I have (finally) got my project to a working stage so I thought I’d write a bit about it. After buying a CurrentCost CC128 device I was not happy with the software on the Internet for extracting the data. The FDI chip used on the USB cable to the device did not support 64 bit Windows 7 so it crashed on me and the Linux alternatives were basic and look fairly complicated to set up.

Planning

Architecture Diagram

I want the data to be accessed via a web page. I decided to use JavaScript to implement the graphing and AJAX to do a client – server architecture. Also it’s the most popular way of generating dynamic web page which I hope the graph would be done in near real time.

I have not decided what technology for the server side script which would handle the AJAX requests but I ended up using PHP. The PHP script retrieves data from the database, formats it and sends it back to the web page to be graphed.

I have a LAMP stack configuration so I’m using an Apache web server with a MySQL database. All the device data will be stored in the database by a another script which I wanted to use Python for.

The Python script listened for the XML strings sent via a USB cable from the CurrentCost device. The script would then extract the data from XML and store it into the database.

From the start I wanted my software to run on a Linux based system because I want a server at home running on Linux 24/7. This would allow my other devices to be freely turn it self off etc. Also most of other services were on Linux.

Implementation

The FDI chip from the USB cable takes care of the USB to Serial conversion which makes reading data a lot easier but also it uses an up to date connection. Using a terminal and example XML documents found on the web I could see what the XML format looks like. All data is sent every 6 seconds over USB to a serial port. Ever 1 minutes past the hour e.g 15:01 historical data is sent over the cable or by pressing a button on the device.

Once received the Python script parses the XML, extracts data it needs and inserts it into the database.

When a user views the web page, an asynchronous request is sent to the PHP server side script, gets the data from the database and returns it to the web page. The web page then formats it correctly to be parsed into a JavaScript Graph. The web page is currently set to refresh every 10 seconds but this may change depending on how the server holds up.

Graph

Problems

At the moment there are loads of problems and improvements that can be done. This is just a brief post of what I have so far. The Python script can’t handle the historical data and falls over so it won’t run longer than 1 hour.

The AJAX response returns a formatted string. I want to convert this to an XML response so it’s easier / cleaner to retrieve multiple data.

I want to limit the data by date / time because the graph will look tiny / there would be a lot of information being sent back and forth every 10 seconds refresh.

I’m not happy with the scaling of the graphs. It’s using dual axis for energy and temperature.

Some sort of statistics besides a graph like total engery consumed for x days/months/years, etc.

Eventually the Python script will become a Linux Daemon but this is only once it’s stable enough.

Twitter Integration would be nice. I would use the Python script to post a tweet every hour with a simple message. The profile will be protected so that only I can see what it says.

Summary

Still got ways to go but it’s getting there. It’s nice to finally see something from my days of work. Especially if I have never used Python or PHP from scratch before.


CurrentCost previous post

CurrentCost Website

CurrentCost XML Specification

Dale Lane’s Blog on how to get data from a CurrentCost device

About Danny

I.T software professional always studying and applying the knowledge gained and one way of doing this is to blog. Danny also has participates in a part time project called Energy@Home [http://code.google.com/p/energyathome/] for monitoring energy usage on a premise. Dedicated to I.T since studying pure Information Technology since the age of 16, Danny Tsang working in the field that he has aimed for since leaving school. View all posts by Danny → This entry was posted in Linux, Software, Website and tagged , , , , , , , , , . Bookmark the permalink.

3 Responses to Recording CurrentCost Data & Viewing It On The Web

  1. Pingback: Current Cost Web Linux Software - Digivation Info

  2. Eugene says:

    Hi, I’m rather new in php & javascript. I saw the graph you had done and it was amazing. I’m currently doing a school project that is somewhat similar to your project (energy monitoring). Could you teach me how to create the graph? Thank you!!

Leave a Reply

Your email address will not be published. Required fields are marked *.

All comments must go through an approval and anti-spam process before appearing on the website. Please be patience and do not re-submit your comment if it does not appear.

This site uses Akismet to reduce spam. Learn how your comment data is processed.