in reply to Re: Total fault tolerance for perl GPS program
in thread Total fault tolerance for perl GPS program

Thank you for the reply! I was wondering about gpsd at the time of my question and appreciate your good advice. Here's what I've got from a very lazy sort of Perl-programmer mentality :^)
perl -MJSON::XS -le '$_=`gpspipe -n 5 -w|grep TPV`;$_=decode_json$_;pr +int"$_->{lon} $_->{lat} $_->{alt} $_->{time}"'
Result: -123.456789012 12.345678901 123.1234 2024-05-03T12:34:56.000Z

My application requires the automated determination of timezone from GPS:

perl -MJSON::XS -e '$_=`gpspipe -n 5 -w|grep TPV`;$_=decode_json$_;pri +nt`timezonefinder $_->{lon} $_->{lat}`'
Result: Your/Timezone
sudo apt install libopenblas-dev pip3 install timezonefinder export PATH=/home/user/.local/bin:$PATH

Wait for GPS:
perl -MJSON::XS -e 'RE:while(){$_=`gpspipe -n 5 -w|grep TPV`;last if$_ +;sleep 1}eval{$_=decode_json$_};if($@){sleep 1;goto RE};print`timezon +efinder $_->{lon} $_->{lat}`'
Now my computer magically knows the time zone:

sudo ln -s /usr/share/zoneinfo/Your/Timezone /etc/localtime

Replies are listed 'Best First'.
Re^3: Total fault tolerance for perl GPS program
by NERDVANA (Priest) on May 04, 2024 at 03:52 UTC
    That'll do the trick :-) but there isn't much in the way of detection and remediation in that code, which is what I thought you were aiming for. If you want a rock-solid solution you should probably use a non-blocking socket/pipe and then restarts gpsd if it goes too long without reporting anything. Maybe also add a software-controlled electrical disconnect on the USB port so that you can power-cycle the device :-)
        If you want a rock-solid solution you should probably use a non-blocking socket/pipe

      I was just messing around. Net::GPSD3 uses IO::Socket::INET6 to handle it:

      #!/usr/bin/perl use Net::GPSD3; my $g = Net::GPSD3->new or die $!; $g->addHandler(\&tpv); $g->watch; sub tpv{ $t = shift; return unless $t->class eq 'TPV'; print join ' ', $t->timestamp, $t->lat, $t->lon, $t->alt; exit }
      perl -MNet::GPSD3 -le '$g=Net::GPSD3->new;$g->addHandler(\&tpv);sub tp +v{$t=shift;return unless$t->class eq"TPV";print join" ",$t->timestamp +,$t->lat,$t->lon,$t->alt;exit}$g->watch'
        and then restarts gpsd if it goes too long without reporting anything. Maybe also add a software-controlled electrical disconnect on the USB port so that you can power-cycle the device

      Those are cool ideas but I have to trust the GPS, and GPSD seems very robust, to prevent me from creating a race condition that bricks the device :-)