I have some hacks to ensure that my USB GPS devices continues spitting data if disconnected, then reconnected. The devices are so flaky that they need restarting so as to continue transmitting data.
My hack is to have a cron job that runs every minute (I want quick recovery), invoking a script that keeps asking gpsd to continue WATCHing all configured devices every minute.
So, I added this line in /etc/crontab:
* * * * * username /usr/bin/python /usr/local/bin/keepalive.py
And the content of /usr/local/bin/keepalive.py:
import socket
from syslog import syslog, openlog
CMD = '?WATCH={"class":"WATCH","json":true}'
def main():
openlog(__file__)
syslog('connecting to gpsd socket')
try:
sock = socket.create_connection(('localhost', 2947))
except socket.error as e:
syslog('connection failure: {0}'.format(e))
else:
syslog('CMD: ' + CMD)
sock.sendall(CMD)
syslog('success')
finally:
if sock:
sock.close()
if __name__ == '__main__':
main()
I also added this line to /etc/udev/rules.d/custom.rules:
ATTRS{idVendor}=="1234", ATTRS{idProduct}=="5678", SYMLINK+="flaky%n"
That's because I can have more than one of those devices connected at the same time.
Is there some udev / gpsd magic I can do to avoid this hack?