The UK Home Automation Archive

Archive Home
Group Home
Search Archive


Advanced Search

The UKHA-ARCHIVE IS CEASING OPERATIONS 31 DEC 2024


[Message Prev][Message Next][Thread Prev][Thread Next][Message Index][Thread Index]

RE: Current Cost data extract



I used this Perl script on a Linux box a while back (not got round to
re-configuring after Google ditched the Windows app). Very rough &
ready,
looks like it was cobbled together from a snippet of someone else's example
code, but you should be able to drop on a Perl interpreter make a few
tweaks
and you'll be running again.

#!/usr/bin/perl -w

use strict;

use Device::SerialPort;
use XML::Parser;
use XML::XPath;
use DBI;

my $port = Device::SerialPort->new("/dev/ttyUSB0");
my $dbh = DBI->connect("dbi:mysql:ccost:localhost:3306",
"ccost", "ccost");

$port->baudrate(57600);
$port->parity("none");
$port->handshake("none");
$port->databits(8);
$port->stopbits(1);
$port->read_char_time(0);
$port->read_const_time(1);

print "\nStart\n";
# read data until new data is not found five times in a row
while (1)
{
my $readData = &read(5);
if ($readData ne "")
{
#print $readData;
eval
{
my $xml = XML::XPath->new(xml => $readData);
my $date = $xml->find('//msg/time');
my $watts =  $xml->find('//msg/ch1/watts');
#print $date, "," , $watts, "\n";
# prepare the query
my $sth = $dbh->prepare("insert into readings(date, reading)
values(now(), $watts)");

# execute the query
$sth->execute();
}
}

}

$port->close();
print "\nEnd\n";

sub read()
{
my $maxCnt = shift;
my $notFndCnt = 0;

# clear the read buffer variables
my $readChars = 0; my $readBytes = ""; my $readBuffer =
"";


while ($notFndCnt < $maxCnt) {
# Read serial port data
($readChars, $readBytes) = $port->read(1);

#print $readBytes;



$readBuffer .= $readBytes;

if ($readChars == 0) {
$notFndCnt++;
} else {
$notFndCnt = 0;


}
}

#print "\n";

$readBuffer;
}


-----Original Message-----
From: ukha_d@xxxxxxx [mailto:ukha_d@xxxxxxx] On Behalf Of
peter_church
Sent: 12 February 2012 08:26
To: ukha_d@xxxxxxx
Subject: [ukha_d] Current Cost data extract

Hi all,

I've searched the web on this and cannot find anything suitable, but was
wondering if anyone here has a homebrew solution to this (or a pointer to
something I missed).

I was using Google to gather the data from my CurrentCost unit, but was
ignoring their web part but instead pulling out my own values from the
local
database that Google was creating on my machine.

Since Google discontinued their monitoring service their software no longer
seems to be working (obviously I suppose).

Does anyone have a simple solution to retriveing the CurrentCost info into
a
local database? All the ones ont the web contain a fancy front end or
upload
to the web which I don't want.

I've tried writing my own in VB (my only language) but it uses all
resources
of the processor which is a bit of a problem - down to my limitations I
guess.

Many thanks in advance

Pete



------------------------------------



UKHA_D Main Index | UKHA_D Thread Index | UKHA_D Home | Archives Home

Comments to the Webmaster are always welcomed, please use this contact form . Note that as this site is a mailing list archive, the Webmaster has no control over the contents of the messages. Comments about message content should be directed to the relevant mailing list.