Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

sensimilla

By: a guest on Dec 19th, 2010  |  syntax: Perl  |  size: 0.50 KB  |  views: 729  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  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. }