mosquitto/misc/currentcost/cc128_read.pl

24 lines
463 B
Perl
Raw Normal View History

2014-05-07 22:27:00 +00:00
#!/usr/bin/perl -w
# Reads data from a Current Cost device via serial port.
# Spawns
use strict;
use Device::SerialPort qw( :PARAM :STAT 0.07 );
2015-08-26 19:59:19 +00:00
my $pubclient = "mosquitto_pub -t sensors/cc128/raw -q 1 -l";
2014-05-07 22:27:00 +00:00
my $PORT = "/dev/ttyUSB0";
local $| = 1;
my $ob = Device::SerialPort->new($PORT);
$ob->baudrate(57600);
$ob->write_settings;
open(SERIAL, "+<$PORT");
open(MQTT, "|$pubclient");
while (my $line = <SERIAL>) {
print(MQTT "$line");
}
close(MQTT);