connect again on serial error
authorDobrica Pavlinusic <dpavlin@rot13.org>
Mon, 20 Mar 2017 09:23:54 +0000 (10:23 +0100)
committerDobrica Pavlinusic <dpavlin@rot13.org>
Mon, 20 Mar 2017 09:23:54 +0000 (10:23 +0100)
serial.pl

index 5dc5bda..06a1d15 100755 (executable)
--- a/serial.pl
+++ b/serial.pl
@@ -11,6 +11,8 @@ my $path = shift @ARGV || '/dev/serial/by-path/platform-20980000.usb-usb-0:1.3.1
 
 $|=1;
 
+connect_again:
+
 my $s = new Device::SerialPort( $path ) || die $!;
 $s->baudrate(2400);
 $s->databits(8); # 7
@@ -36,6 +38,7 @@ sub _mqtt_pub {
 
 while (1) {
        my ($len, $string) = $s->read($read_len);
+       goto connect_again if ! defined $len;
        my $ts = time();
 
        if ( $len > 0 ) {