From 7c6887eaaf812b63bab6c5e134f80a2ef36aeb31 Mon Sep 17 00:00:00 2001 From: fishsoupisgood Date: Tue, 12 Jan 2021 16:58:31 +0000 Subject: works --- heating-cgi/boiler_rx | 65 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100755 heating-cgi/boiler_rx (limited to 'heating-cgi/boiler_rx') diff --git a/heating-cgi/boiler_rx b/heating-cgi/boiler_rx new file mode 100755 index 0000000..777b3ee --- /dev/null +++ b/heating-cgi/boiler_rx @@ -0,0 +1,65 @@ +#!/usr/bin/env perl + +use Net::Telnet; +use IO::File; + +sub dump_file($$) { + my ( $name, $guts ) = @_; + + my $fh = new IO::File ">" . $name; + return unless defined $fh; + $fh->print($guts); + $fh->close; + undef $fh; +} + +my $timeout = 60; + +my $host = $ARGV[0]; + +my $path = "/var/run/boiler_" . $host; + +mkdir( $path, 0755 ); + +while (1) { + my $telnet = new Net::Telnet( + Timeout => 10, + Telnetmode => 0, + Binmode => 1, + Host => $host, + Port => 2001 + ); + + #$telnet->open($bits[1]); + + my $nodata = 0; + + while ( ( not $telnet->eof ) and ( $nodata < $timeout ) ) { + my $line = $telnet->getline( Timeout => 1, Errmode => 'return' ); + + if ( not defined $line or ( length($line) == 0 ) ) { + $nodata++; + } + else { + $nodata = 0; + } + + chomp $line; + chomp $line; + + $line = uc($line); + + next unless $line =~ /^([TB])(.)(.)(..)(....)/; + + my $fn = $1 . $2 . "x" . $4; + my $c = $1 . $2 . $3 . $4 . $5; + + dump_file( $path . "/" . $fn, $c ); + + } + + $telnet->close; + +} + +exit(0); -- cgit v1.2.3