SHARE
TWEET

sensimilla

a guest Dec 19th, 2010 754 Never
  1. #!/usr/bin/perl -w
  2.  
  3. # Reads data from Current Cost and e.on energy monitor devices 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!<tmpr> *([\-\d.]+)</tmpr>.*<watts>0*(\d+)</watts>!) {
  17.         my $temp = $1;
  18.         my $watts = $2;
  19.         print "$watts, $temp\n";
  20.     }
  21. }
RAW Paste Data
Top