Admin

Search

Mar

4

There’s been quite a bit of interest in my electricity usage dial like the one below so I’m going to go through how I did it with you. The first thing you’ll need is the XML/SWF Gauge and a web server with PHP. It’s possible to do this on a web server running Perl or ASP but you’ll need to do that yourself. For this example I’m also using a Pachube account to grab the data. My feed, the one for my gauge on the top right, is 1498 but you will want to create your own account and start updating your own data. Using the gauge is as simple as a simple thing.

There are a number of things we need to get this simple display working,

1. The .SWF file

2. An gauge.html page to show the gauge

3. A data fetch PHP script

1. The .SWF file

We’ll come to that at the very end of the article.

2. The gauge.html file.

Open your favourite text editor and cut and paste the following into it.

Copy the .swf file that you downloaded from the XML/SWF Gauge site and put it on your web server along with your gauge.html and getdata.php files. Point your browser at your website and the gauge.html page and bask in your glorious meter display.

I should point out that this is using the historic feed data from pachube which has a 15 minute lag. The reason for this is simply because it does not require authentication with the pachube servers. If you want to use your live feed you will need to change the url used and the management of the data returned as well as adding

1

curl_setopt($curl, CURLOPT_USERPWD,"username:password");

just before the ob_start(); on line 16. Replace username:password with your actual username and password, don’t forget the colon in between. When changing the url you might want to use the secure https rather than just http.

Feb

13

My UnbioctiumCurrent Cost CC128 arrived on Thursday and although I’m not going to actually get a chance in install it for a couple of weeks I did have a play. The first thing to do once it was all up and paired with the base was get the output into my laptop. To do this you will need to buy the data cable or make up your own…

At first I tried to be smart with reading from the serial port, as that seems to be a bit unreliable I fell back on the old tried and tested method. I also decided from the outset that I was going to parse the XML that the the CC128 spat out rather than just filter the bits needed with regexp.

You will need to make sure you have the perl modules Device::SerialPort and XML::Simple installed. If you don’t have them then as root on your linux box do the following:

perl -MCPAN -e shell

then install each module, for example Device::SerialPort,

install Device::SerialPort

and here’s the script which is also available for download.Updated to make it more reliable.

#!/usr/bin/perluse Device::SerialPortqw(:PARAM :STAT 0.07);use XML::Simple;$port="/dev/ttyUSB0";$ob= Device::SerialPort->new($port)ordie"Can not open port $port\n";$ob->baudrate(57600);$ob->write_settings;$ob->close;# using XML::Parser speeds xml parsing up lots!$backend='XML::Parser';$ENV{XML_SIMPLE_PREFERRED_PARSER}=$backend;# we use this to only do 1 iteration (or not)$escape=0;open(SERIAL,"<$port");while($escape<=0){sleep(2);while($line=<SERIAL>){# for debug#print $line;$isValid=(index($line,"<msg>")!=-1);if(!$isValid){last;}print"This data is".($isValid==1?"":" not")." valid\n";# force XML::Simple to see this as a string not as a file# since XML::Simple is stupid and needs to be shot$line="<fakeTag>$line</fakeTag>";$isHistoric=(index($line,"<hist>")!=-1);$nref= XMLin($line,forcearray =>0);$ref=$nref->{msg};# just for reference, show if data is historic or notprint"This data is".($isHistoric==1?"":" not")." historic\n";if(!$isHistoric){$dsb=0+$ref->{dsb};$recordTime=$ref->{time};$ccname=$ref->{src};$temp=$ref->{tmpr};$ch1watts=0+$ref->{ch1}->{watts};$sensor=0+$ref->{sensor};$id=$ref->{id};$type=0+$ref->{type};if(defined$ref->{whatever}){# do something based on whatever}print"This $ccname was born $dsb days ago as at $recordTime - temperature is: $temp :: Current Watts in use on channel 1 are $ch1watts :: Sensor is $sensor, with an id of $id and a type of $type\n";# for cacti you'd probably just want to output CC_Temperature:$temp CC_Watts1:$ch1watts # insert data into db# if you want to exit after a 'good' iteration set this to 1 otherwise set it to 0 (or don't change it to 1 :) );$escape=1;}else{#process or ignore historic data}}}close(SERIAL);

and here’s some example output, remember that I haven’t actually connected the loop around my electrical cable as yet.

This data is not historic
This CC128-v0.11 was born 1 days ago as at 21:16:44 - temperature is: 23.7 :: Watts used on channel 1 are 0 :: Sensor is 0, with an id of 02835 and a type of 1

Historic data isn’t processed at the moment but it would be trivial to do. I’m not processing it since I don’t really see the point if you’re going to store the results in a database.

Feb

4

For a very long time now I’ve been playing with the Arduino boards but it wasn’t until I recently discovered some DS1820 1-wire chips in my parts box that I started even thinking about 1-wire stuff. Connecting 1-wire devices to the Arduino is, well, amazingly simple. Using the sample circuit from the datasheet we can see the connections are few and far between.

Please note that this is the corrected circuit, previously the VDD was not tied to ground. While the circuit would work it would only give reliable results on very short runs. This circuit allows longer runs to the sensor.

Coding this up is also made extremely easy with the OneWire library. I’ve put together a little application below that will read all of the 1-wire devices on a bus. If you press L in the Arduino IDE serial monitor it will list all the 1-Wire device id’s and if you press T you’ll get the id and temperature reading.

There’s also a copy of the .pde file that you can download if you feel more inclined. It’s not an exact copy, I removed the commented out xml for the above version. It’s worth pointing out that this circuit is using what is called parasitic power, which means your cable run should be shortish. If you want to use an external power supply then pin 3 (VDD) on the DS18S20 should go to your external supply. This would allow for much longer runs of cable. Below is an example graph generated by cacti with 2 DS1820’s connected the the arduino. As you can see the temperatures aren’t exactly the same but this is to be expected since the accuracy of the DS1820 is +/- 0.5 ° C

The breaks in the graph were caused my me removing the USB plug from the PC it was connected to so that I could make some minor alterations to the circuit.

Josh asked how I was getting the input for Cacti, here’s the perl script I use

This outputs Temperature_x:n where x is the 1-Wire id and n is the temperature. It could probably do with tidying up and if you wanted to you could pass the 1-Wire id to the script to and only output the temperature for that particular 1-Wire device. A copy of the exported Cacti template can be downloaded, I’m hoping that you just need to import that into your Cacti after placing the script in the scripts directory. Just remember, under linux, if you unplug and replug in your Arduino you may need to set the tty port speed to 9600 (or whatever you put in your Serial.begin(); ). You can use the following command for that;

Jan

12

Tweetbacking, it sounds like some sort of deviant sport or something but isn’t. The idea behind Tweetbacks, similar to pingbacks, is that you can see who is commenting (tweeting) about your blog on Twitter. There are a number of plugins available for use in the end I went for Joost de Valk‘s version. While it worked nicely I decided that I really wanted to approve the tweets before they appeared in my blog so I modified the code a little. The diff is available for download. It allows you to enable and disable the automatic approval of Tweets form the plugin’s admin page. Hopefully Joost will add this option in the official version sometime.

Tweetbacks are saved in the comments table and can be displayed however you like for example, in my comment loop I have:

A word or two of caution about the plugin. Personally I’ve removed the bit.ly url shortening link parsing because it just didn’t work properly – I ended up with bogus tweetbacks until I did. The other issue is with the date saving from the tweetback, it doesn’t work properly either giving dates in the 1970’s!!!

Sep

22

Last night I tried a little experiment on my jailbrokeniPhone. Since I’d already started poking about playing with my own Winterboard themes and have been tracking my iPhone’s location for a while now, I thought I’d see what happened if I mixed the two. So, how about wallpaper that followed you? It turns out that combining the two is relatively straight forward. Google now provide a mechanism for getting what they call static maps which will allow you to get an image centered on a set of coordinates. You can also add your own markers if you want.

There are some limitations on the number and size of the maps that you can retrieve so I employed a very simple caching mechanism to ensure I didn’t annoy Google. This certainly helps speed things up when testing and also enabled me to identify a small issue I was having.Read more…