Advertisement
ChloeRed

current cost

Jul 9th, 2013
345
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 0.64 KB | None | 0 0
  1. #!/usr/bin/perl -w
  2.  
  3. # Reads data from a Current Cost device via serial port.
  4.  
  5. use strict;
  6. use Device::SerialPort qw( :PARAM :STAT 0.07 );
  7.  
  8. my $PORT = "/dev/ttyUSB0";
  9.  
  10. my $ob = Device::SerialPort->new($PORT);
  11. $ob->baudrate(57600);
  12. $ob->write_settings;
  13.  
  14. open(SERIAL, "+>$PORT");
  15. while (my $line = <SERIAL>) {
  16.     #if ($line =~ m!<ch1><watts>0*(\d+)</watts></ch1>.*<tmpr> *([\-\d.]+)</tmpr>!) {
  17.     if ($line =~ m!<tmpr>([\d.]+)</tmpr>.*<ch1><watts>0*(\d+)</watts></ch1>!) {
  18.        my $watts = $2;
  19.        my $temp = $1;
  20.        #print "$watts, $temp\n";
  21.        system ("rrdtool update /home/chloe/bin/powertemp.rrd N:$watts:$temp");
  22.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement