Skip to content

Instantly share code, notes, and snippets.

@zeffii
Forked from kgleeson/gist:3403209
Created August 20, 2012 11:34
Show Gist options
  • Save zeffii/3403397 to your computer and use it in GitHub Desktop.
Save zeffii/3403397 to your computer and use it in GitHub Desktop.
#!/usr/bin/perl -w
# Reads data from a Current Cost device via serial port.
use strict;
use Device::SerialPort qw( :PARAM :STAT 0.07 );
my $PORT = "/dev/ttyUSB0";
my $ob = Device::SerialPort->new($PORT);
$ob->baudrate(57600);
$ob->write_settings;
open(SERIAL, "+>$PORT");
while (my $line = <SERIAL>) {
if ($line =~ m!<tmpr>\s*(-*[\d.]+)</tmpr>.*<ch1><watts>0*(\d+)</watts></ch1>!) {
my $watts = $2;
my $temp = $1;
exec "rrdtool update /etc/cron.cc/rrd/powertemp.rrd N:$watts:$temp";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment