I'm on a Raspberry PI Zero W (Raspbian NOOBS v2.9.0)
The GPS module is a Neo 6M GPS module https://www.amazon.it/ILS-navigazione-satellitare-posizionamento-Arduino/dp/B07911Z266/ref=sr_1_46?ie=UTF8&qid=1542095676&sr=8-46&keywords=gps+raspberry+pi
I've installed GPSD with the following command
sudo apt-get install gpsd gpsd-clients python-gps
- I've enabled the hardware serial port and disabled the serial console with raspi-config
I've edited the file /etc/default/gpsd as follows:
START_DAEMON="true" GPSD_OPTIONS="/dev/ttyS0" DEVICES="" USBAUTO="false" GPSD_SOCKET="/var/run/gpsd.sock"
I've added the following lines to /etc/rc.local (BEFORE the "exit 0")
sudo gpsd /dev/ttyS0 -F /var/run/gpsd.sock sudo python /home/pi/code.py
In the code.py I have this code running:
import os import sys from gps import * import threading from threading import Thread class GpsPoller(threading.Thread): # object needed to obtain GPS data gpsd = None def __init__(self): print "Initializing GPS poller..." global gpsd threading.Thread.__init__(self) gpsd = gps(mode=WATCH_ENABLE) self.current_value = None self.running = True def run(self): print "Starting GPS loop..." global gpsd while self.running: # get the next set of data gpsd.next() # clear screen os.system("clear") print print 'GPS' print print '----------------------------------------' print 'latitude ' , gpsd.fix.latitude print 'longitude ' , gpsd.fix.longitude print 'time (utc) ' , gpsd.utc,' + ', gpsd.fix.time print 'altitude (m)' , gpsd.fix.altitude print 'eps ' , gpsd.fix.eps print 'epx ' , gpsd.fix.epx print 'epv ' , gpsd.fix.epv print 'ept ' , gpsd.fix.ept print 'speed (m/s)' , gpsd.fix.speed print 'mode ' , gpsd.fix.mode print '----------------------------------------' print gpsp = GpsPoller() gpsp.run()
I've disabled the GPSD service at startup (to prevent the system from starting it and let this task to be achieved by rc.local) with the following commands:
sudo systemctl stop gpsd.socket sudo systemctl disable gpsd.socket
The result is that when i power on the Rpi, the code and the gpsd daemon start properly but the data cannot be obtained, if I then kill the python code and start it manually, it works.