I can't really give you an example because there's many ways of doing
it. It's all up to the programming languages you are most
familiar with
(and those that run on the Raspberry Pi). It's also not exactly a
one
or two line script although there are some very rough ways of
doing it
in a small script, they're not very robust.
But in general you need to write a small program that connects to
gpsd,
sends the WATCH command so that data streams from the attached GPS
receiver and then detect if that data stops flowing (because gpsd
crashed) or the data isn't updating (because the GPS receiver
failed or
disconnected). In that case you send a system call to kill the
PID of
the gpsd process then start a new copy.
The small script version would be something like (this is completely
untested, don't use it)
#!/bin/bash
GPSDPID=$(ps ax | grep gpsd | grep -v grep | awk '{print $1}')
GPSDSTATE=$(ps ax | grep gpsd | grep -v grep | awk '{print $3}'
GPSDCMD="/path/to/gpsd --with-parameters"
if [ "$GPSDSTATE" == 'Z' ] || [ -z "$GPSDPID" ];
then
echo 'gpsd is a zombie or it's completely missing, kill it'
if [ -n "$GPSDPID" ];
then
kill -KILL $GPSDPID
sleep 1
fi
$GPSDCMD
fi
Basically that script would look at the process list to see if
gpsd was
there, pull out the PID and the state and then see if the state is
a Z
(zombie process) or an empty string (the -z) in which case it died
and
needs to be restarted. This is a bad script because it can't
catch many
problems that might leave gpsd running but not really functioning.
You are better off using something else to connect directly to gpsd's
TCP port and taking action if the data isn't there, the port
closes or
some other detail you don't like.
On 2016-03-14 23:51, bruno suarez wrote:
Hello,
Thank you for the reply and the idea of chemical heat packs.
The watchdog is expected.
On monitoring GPSD, ok for the principle, but a sample script would
help
me (I am not a man of script!).
Thank you for your answers and tips
cordially
Bruno
Le 15/03/2016 07:36, Alexander Carver a écrit :
On 2016-03-14 12:06, bruno suarez wrote:
Hello,
For a stratospheric balloon project, I usea raspberry Rasbian
Jessie and
a USB GPS receiver.
Everything is OK with gpsd and my GPS receiver.
When I plug everything works correctly, gpsd start on the correct
port
/dev/ttyUSB0.
However, I want to make sure that everything works properly during
2/3
hours to extremely cold temperature
What is the easiest way to automatically control the operation of
GPSD
and relaunch it(on the same port detected ) if it is stopped or if
it is
in error.
Thank you for your answers and tips
Cordially
Bruno
First, pack your payload with heaters. You can use chemical heat
packs
from a pharmacy that are normally used for heating muscles and
joints
(these are the plastic bags that you smash to mix the chemicals and
they
get warm.) In an insulated container you should stay within your
operating limits of the Pi (the lower limit is approximately -20
Celsius).
After that, just set up a script that watches for data coming from
gpsd
and, if there is no data, issue a kill for the PID of gpsd and
restart
it. Since gpsd can support more than one connection you can get
data
for your recording/telemetry program and have a completely separate
program running to watch for a loss of communication.
Also make sure to enable the watchdog timer in the Pi so that it
will
reboot if the whole system fails. Make sure gpsd will start at
boot as
well as your data logging/telemetry program and the monitoring
script.