]> mj.ucw.cz Git - home-hw.git/commitdiff
Air tests: logger
authorMartin Mares <mj@ucw.cz>
Wed, 10 Jul 2019 08:17:57 +0000 (10:17 +0200)
committerMartin Mares <mj@ucw.cz>
Wed, 10 Jul 2019 08:17:57 +0000 (10:17 +0200)
test-opencm3/logger [new file with mode: 0755]

diff --git a/test-opencm3/logger b/test-opencm3/logger
new file mode 100755 (executable)
index 0000000..f117960
--- /dev/null
@@ -0,0 +1,39 @@
+#!/usr/bin/perl
+use common::sense;
+use Device::SerialPort;
+use Data::Dumper;
+use Net::MQTT::Simple;
+
+my $port = Device::SerialPort->new('/dev/ttyUSB0', 0);
+$port->baudrate(115200);
+$port->parity('none');
+$port->databits(8);
+$port->stopbits(1);
+$port->handshake('none');
+$port->stty_icanon(1);
+$port->read_char_time(1);
+$port->purge_all;
+
+my $mqtt = Net::MQTT::Simple->new('micac.vojtech.kobylisy.czf') or die "Cannot connect to MQTT";
+
+my @desc = qw(outside-exhaust inside-exhaust outside-intake chilled inside-intake bypass fan-pwm);
+
+for (;;) {
+       my $line = $port->read(255);
+       chomp $line;
+       $line =~ s{\r}{}g;
+       next if $line eq "";
+       my @fields = split /\s+/, $line;
+       unless (@fields == @desc + 1 && $fields[0] eq '#') {
+               print STDERR "Malformed line: $line\n";
+               next;
+       }
+       # print join("|", @fields), "\n";
+
+       my $now = time;
+       for my $i (0..$#desc) {
+               $mqtt->retain('burrow/air/' . $desc[$i], join(" ", $fields[$i+1], $now));
+               print $desc[$i], '=', $fields[$i+1], " ";
+       }
+       print "\n";
+}