projects
/
vaillant-thermostat
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
vani hlad battery change
[vaillant-thermostat]
/
serial.pl
diff --git
a/serial.pl
b/serial.pl
index
5dc5bda
..
c08a73e
100755
(executable)
--- a/
serial.pl
+++ b/
serial.pl
@@
-7,10
+7,12
@@
use Time::HiRes qw(time);
my $read_len = 255;
my $read_len = 255;
-my $path = shift @ARGV || '/dev/serial/by-path/platform-20980000.usb-usb-0:1.
3.1
:1.0-port0';
+my $path = shift @ARGV || '/dev/serial/by-path/platform-20980000.usb-usb-0:1.
2
:1.0-port0';
$|=1;
$|=1;
+connect_again:
+
my $s = new Device::SerialPort( $path ) || die $!;
$s->baudrate(2400);
$s->databits(8); # 7
my $s = new Device::SerialPort( $path ) || die $!;
$s->baudrate(2400);
$s->databits(8); # 7
@@
-28,22
+30,24
@@
my $sym;
sub _mqtt_pub {
my ( $t, $m ) = @_;
sub _mqtt_pub {
my ( $t, $m ) = @_;
- my $cmd = "mosquitto_pub -h rpi2 -t '
stat/rpi/
$t' -m '$m'";
+ my $cmd = "mosquitto_pub -h rpi2 -t '$t' -m '$m'";
#warn "# _mqtt_pub [$t] = [$m]\n";
#warn "# _mqtt_pub [$t] = [$m]\n";
- warn "## $cmd";
+
#
warn "## $cmd";
system $cmd;
}
while (1) {
my ($len, $string) = $s->read($read_len);
system $cmd;
}
while (1) {
my ($len, $string) = $s->read($read_len);
+ goto connect_again if ! defined $len;
my $ts = time();
if ( $len > 0 ) {
my $hex = unpack('H*',$string);
$hex =~ s/(..)/$1 /g;
my $ts = time();
if ( $len > 0 ) {
my $hex = unpack('H*',$string);
$hex =~ s/(..)/$1 /g;
- my $temp = `curl localhost:3000/temp.txt`;
+ my $temp = `curl
--silent
localhost:3000/temp.txt`;
$temp =~ s/\s+/ /gs;
$temp =~ s/\s+/ /gs;
+ $temp =~ s/^\s+//;
#printf "%s %2d %s\n", time(), $len, $hex;
printf "%8.4f %6.2f %2d %s | %s\n", $ts, $ts - $t, $len, $hex, $temp;
#printf "%s %2d %s\n", time(), $len, $hex;
printf "%8.4f %6.2f %2d %s | %s\n", $ts, $ts - $t, $len, $hex, $temp;
@@
-64,6
+68,13
@@
while (1) {
_mqtt_pub "stat/boiler/" . chr(ord('a') + $_) => $d[$_] foreach 0 .. $#d;
}
_mqtt_pub "stat/boiler/" . chr(ord('a') + $_) => $d[$_] foreach 0 .. $#d;
}
+ my @v = split(/\s+/, $temp, 4);
+ my @n = qw( DS18B20/temperature DHT22/temperature DHT22/humidity DHT22/errors );
+ @n = qw( DS18B20/temperature DHT22/temperature DHT22/humidity DHT22/errors ) if $#v == 1; # no DS18B20
+ foreach (@v) {
+ _mqtt_pub "stat/boiler/" . shift(@n) => $_;
+ }
+
}
}
}
}