#!/usr/bin/perl -w # Reads data from a Current Cost device via serial port. use strict; use Device::SerialPort qw( :PARAM :STAT 0.07 ); use HTTP::Date "str2time"; my $PORT = "/dev/ttyUSB0"; local $| = 1; my $ob = Device::SerialPort->new($PORT); $ob->baudrate(57600); $ob->write_settings; open(SERIAL, "+<$PORT"); while (my $line = ) { if ($line =~ m# *([\-\d.]+)0[0-9]*10*(\d+) $now){ $r_stamp -= 86400; } system("/usr/local/bin/mosquitto_pub -q 1 -t sensors/cc128/ch1 -m \"$r_stamp $watts\""); } }