cc128_read.pl 457 B

1234567891011121314151617181920212223
  1. #!/usr/bin/perl -w
  2. # Reads data from a Current Cost device via serial port.
  3. # Spawns
  4. use strict;
  5. use Device::SerialPort qw( :PARAM :STAT 0.07 );
  6. my $pubclient = "mosquitto_pub -t sensors/cc128/raw -q 1 -l";
  7. my $PORT = "/dev/ttyUSB0";
  8. local $| = 1;
  9. my $ob = Device::SerialPort->new($PORT);
  10. $ob->baudrate(57600);
  11. $ob->write_settings;
  12. open(SERIAL, "+<$PORT");
  13. open(MQTT, "|$pubclient");
  14. while (my $line = <SERIAL>) {
  15. print(MQTT "$line");
  16. }
  17. close(MQTT);