]> mj.ucw.cz Git - home-hw.git/blob - test-opencm3/logger
Auto: Meditation mode turned off
[home-hw.git] / test-opencm3 / logger
1 #!/usr/bin/perl
2 use common::sense;
3 use Device::SerialPort;
4 use Data::Dumper;
5 use Net::MQTT::Simple;
6
7 my $port = Device::SerialPort->new('/dev/ttyUSB0', 0);
8 $port->baudrate(115200);
9 $port->parity('none');
10 $port->databits(8);
11 $port->stopbits(1);
12 $port->handshake('none');
13 $port->stty_icanon(1);
14 $port->read_char_time(1);
15 $port->purge_all;
16
17 my $mqtt = Net::MQTT::Simple->new('micac.vojtech.kobylisy.czf') or die "Cannot connect to MQTT";
18
19 my @desc = qw(outside-exhaust inside-exhaust outside-intake chilled inside-intake bypass fan-pwm);
20
21 for (;;) {
22         my $line = $port->read(255);
23         chomp $line;
24         $line =~ s{\r}{}g;
25         next if $line eq "";
26         my @fields = split /\s+/, $line;
27         unless (@fields == @desc + 1 && $fields[0] eq '#') {
28                 print STDERR "Malformed line: $line\n";
29                 next;
30         }
31         # print join("|", @fields), "\n";
32
33         my $now = time;
34         for my $i (0..$#desc) {
35                 $mqtt->retain('burrow/air/' . $desc[$i], join(" ", $fields[$i+1], $now));
36                 print $desc[$i], '=', $fields[$i+1], " ";
37         }
38         print "\n";
39 }