Yo Gary!
Thank you for your patience with me.
Some background on what I want to do. Maybe I should have explained this to begin with. Would have saved you trouble.
I want to get latitude and longitude information out of my gps. I wrote a small client and tested it with gpsfake. This client was based on the one in
https://pypi.org/project/gps/ (see end of gps.py). The input to gpsfake was a nmea file generated via
nmeagen.org. I can see the following information every half-second
{'class': 'TPV', 'device': '/dev/pts/9', 'mode': 3, 'time': '2021-04-26T09:58:52.573Z', 'ept': 0.005, 'lat': 18.516816667, 'lon': 73.834533333, 'alt': 0.0, 'epv': 23.0, 'track': 198.4, 'speed': 15.999, 'climb': 0.0, 'epc': 46.0}
Now that I have access to a real physical gps, I'd like to get lat/lon out of it using the same (or similar) client I wrote for use with gpsfake. Notice that in response to your comments, I have added
gps.WATCH_NMEA in the client.
Based on your suggestions, here is what I am doing now, in sequence:
1) as root, Kill all previous gpsds
2) as root, gpsd -n -N -D3 /dev/ttyS0
3) as root, run the script to power on
4) as non root-user, start the client
Detailed output follows
1) As root, begin with
a) killall -9 gpsd
b) service gpsd stop
c) rm /run/gpsd.sock
2) As root, gpsd -n -N -D3 /dev/ttyS0 which yields
gpsd:INFO: launching (Version 3.17)
gpsd:INFO: listening on port gpsd
gpsd:INFO: stashing device /dev/ttyS0 at slot 0
gpsd:INFO: SER: opening GPS data source type 2 at '/dev/ttyS0'
gpsd:INFO: SER: speed 115200, 8N1
gpsd:INFO: SER: speed 9600, 8O1
gpsd:INFO: SER: speed 115200, 8N1
gpsd:INFO: SER: speed 9600, 8N1
gpsd:INFO: SER: speed 115200, 8N1
gpsd:INFO: gpsd_activate(2): activated GPS (fd 6)
gpsd:INFO: KPPS:/dev/ttyS0 RFC2783 path:/dev/pps0, fd is 7
gpsd:INFO: KPPS:/dev/ttyS0 pps_caps 0x1133
gpsd:INFO: KPPS:/dev/ttyS0 have PPS_CANWAIT
gpsd:INFO: KPPS:/dev/ttyS0 kernel PPS will be used
gpsd:INFO: PPS:/dev/ttyS0 ntpshm_link_activate: 1
gpsd:INFO: device /dev/ttyS0 activated
gpsd:INFO: KPPS:/dev/ttyS0 kernel PPS timeout Interrupted system call
gpsd:INFO: KPPS:/dev/ttyS0 kernel PPS timeout Interrupted system call
gpsd:INFO: KPPS:/dev/ttyS0 kernel PPS timeout Interrupted system call
gpsd:INFO: running with effective group ID 20
gpsd:INFO: running with effective user ID 115
gpsd:INFO: startup at 2021-06-24T11:09:19.000Z (1624532959)
gpsd:INFO: KPPS:/dev/ttyS0 kernel PPS timeout Connection timed out
gpsd:INFO: KPPS:/dev/ttyS0 kernel PPS timeout Connection timed out
gpsd:INFO: KPPS:/dev/ttyS0 kernel PPS timeout Connection timed out
gpsd:INFO: KPPS:/dev/ttyS0 kernel PPS timeout Connection timed out
gpsd:INFO: KPPS:/dev/ttyS0 kernel PPS timeout Connection timed out
gpsd:INFO: KPPS:/dev/ttyS0 kernel PPS timeout Connection timed out
gpsd:WARN: PPS:/dev/ttyS0 unchanged state, ppsmonitor sleeps 10
3) As root, run the power on script in a separate terminal. gpsd identifies the gps device and outputs
gpsd:INFO: /dev/ttyS0 identified as type NMEA0183, 79 sec @ 115200bps
gpsd:INFO: KPPS:/dev/ttyS0 kernel PPS timeout Connection timed out
gpsd:WARN: can't use GGA time until after ZDA or RMC has supplied a year.
gpsd:WARN: can't use GGA time until after ZDA or RMC has supplied a year.
gpsd:INFO: KPPS:/dev/ttyS0 kernel PPS timeout Connection timed out
gpsd:INFO: KPPS:/dev/ttyS0 kernel PPS timeout Connection timed out
gpsd:INFO: KPPS:/dev/ttyS0 kernel PPS timeout Connection timed out
gpsd:INFO: KPPS:/dev/ttyS0 kernel PPS timeout Connection timed out
gpsd:WARN: can't use GGA time until after ZDA or RMC has supplied a year.
gpsd:WARN: can't use GGA time until after ZDA or RMC has supplied a year.
gpsd:WARN: can't use GGA time until after ZDA or RMC has supplied a year.
gpsd:INFO: KPPS:/dev/ttyS0 kernel PPS timeout Connection timed out
gpsd:INFO: KPPS:/dev/ttyS0 kernel PPS timeout Connection timed out
gpsd:WARN: PPS:/dev/ttyS0 unchanged state, ppsmonitor sleeps 10
4) As non-root user, start the client. gpsd detects that a client has connected because it outputs the following
gpsd:CLIENT: => client(0): {"class":"VERSION","release":"3.17","rev":"3.17","proto_major":3,"proto_minor":12}\x0d\x0a
gpsd:CLIENT: <= client(0): ?WATCH={"enable":true,"json":true}\x0a
gpsd:CLIENT: => client(0): {"class":"DEVICES","devices":[{"class":"DEVICE","path":"/dev/ttyS0","driver":"NMEA0183","activated":"2021-06-24T11:10:54.712Z","flags":1,"native":0,"bps":115200,"parity":"N","stopbits":1,"cycle":1.00}]}\x0d\x0a{"class":"WATCH","enable":true,"json":true,"nmea":false,"raw":0,"scaled":false,"timing":false,"split24":false,"pps":false}\x0d\x0a
gpsd:CLIENT: <= client(0): ?WATCH={"enable":true,"nmea":true}\x0a
gpsd:CLIENT: => client(0): {"class":"DEVICES","devices":[{"class":"DEVICE","path":"/dev/ttyS0","driver":"NMEA0183","activated":"2021-06-24T11:10:54.712Z","flags":1,"native":0,"bps":115200,"parity":"N","stopbits":1,"cycle":1.00}]}\x0d\x0a{"class":"WATCH","enable":true,"json":true,"nmea":true,"raw":0,"scaled":false,"timing":false,"split24":false,"pps":false}\x0d\x0a
The client gets the following data
connected to tcp://
127.0.0.1:2947----------------------------------------
{'class': 'VERSION', 'release': '3.17', 'rev': '3.17', 'proto_major': 3, 'proto_minor': 12}
----------------------------------------
{'class': 'DEVICES', 'devices': [{'class': 'DEVICE', 'path': '/dev/ttyS0', 'driver': 'NMEA0183', 'activated': '2021-06-24T11:10:54.712Z', 'flags': 1, 'native': 0, 'bps': 115200, 'parity': 'N', 'stopbits': 1, 'cycle': 1.0}]}
----------------------------------------
{'class': 'WATCH', 'enable': True, 'json': True, 'nmea': False, 'raw': 0, 'scaled': False, 'timing': False, 'split24': False, 'pps': False}
----------------------------------------
{'class': 'DEVICES', 'devices': [{'class': 'DEVICE', 'path': '/dev/ttyS0', 'driver': 'NMEA0183', 'activated': '2021-06-24T11:10:54.712Z', 'flags': 1, 'native': 0, 'bps': 115200, 'parity': 'N', 'stopbits': 1, 'cycle': 1.0}]}
----------------------------------------
{'class': 'WATCH', 'enable': True, 'json': True, 'nmea': True, 'raw': 0, 'scaled': False, 'timing': False, 'split24': False, 'pps': False}
'nmea': True in the last data received by the client.
Notice there is no TPV information sent to the client, which was present when I was faking the gps using gpsfake. I would like TPV classes or something else that holds latitude/longitude information.
Finally, if gpsd is not running, I get sentences like the following using cat /dev/ttyS0. If gpsd is running I do not get output from cat /dev/ttyS0, presumably because gpsd is reading it.
$GPGGA,112736.947,1829.7791,N,07349.0327,E,1,4,1.64,582.6,M,-64.7,M,,*75
$GPGGA,112737.947,1829.7837,N,07349.0297,E,1,5,1.50,585.3,M,-64.7,M,,*79
$GPGGA,112739.000,1829.7767,N,07349.0256,E,1,6,1.14,581.4,M,-64.7,M,,*7A
$GPGGA,112740.000,1829.7803,N,07349.0281,E,1,7,1.03,585.8,M,-64.7,M,,*7C
$GPGGA,112741.000,1829.7821,N,07349.0285,E,1,8,0.88,585.6,M,-64.7,M,,*7A
I'd like for gpsd to make available latitude/longitude information in some form on
127.0.0.1:2947.
Scripts used in this work follow.
Again, thank you for your help and time.
Nachiket
######## Script to power on GPS begins ################
from time import sleep
import serial
ser = serial.Serial(
port='/dev/ttyS0', #Replace ttyS0 with ttyAM0 for Pi1,Pi2,Pi0
baudrate = 115200,
parity=serial.PARITY_NONE,
stopbits=serial.STOPBITS_ONE,
bytesize=serial.EIGHTBITS,
timeout=1,
exclusive=False
)
bool_power_up = False
print ("Turn ON GPS Power (AT+CGPSPWR=1)")
ser.write(bytes("AT+CGPSPWR=1\n", 'utf-8')) #turn on the GPS module
# Reading response has been commented because
# gpsd might be reading at the same time and this causes
# serial.serialutil.SerialException
# device reports readiness to read but returned no data
# rx = ser.readline()
# print (rx.decode('utf-8'))
# sleep(30) # Wait till the module gets a fix. This typically takes between 20-60s.
sleepsecs = 15
print ("Waiting for {}s to get a GPS fix...".format(sleepsecs))
while sleepsecs:
mins, secs = divmod(sleepsecs, 60)
timer = '{:02d}:{:02d}'.format(mins, secs)
print(timer, end="\r")
sleep(1)
sleepsecs -= 1
#
print ("\nGPS output set to GGA (AT+CGPSOUT=2)")
ser.write(bytes("AT+CGPSOUT=2\n", 'utf-8'))
# readline turned off - see notes above
# rx = ser.readline()
# print (rx.decode('utf-8'))
#print ("\n")
try:
while True:
print('Staying alive')
sleep(5)
except KeyboardInterrupt as e:
print('Caught KeyboardInterrupt....turning off GPS')
print ("Turn OFF GPS Power (AT+CGPSPWR=0)")
ser.write(bytes("AT+CGPSPWR=0\n", 'utf-8'))
#readline turned off - see notes above
#rx = ser.readline()
#print (rx.decode('utf-8'))
print ("\n")
ser.close() # close serial port
sleep(5)
####### Script to power on GPS ends ###############################
####### Client to read data from
127.0.0.1:2947 begins #################
import gps
import sys
import argparse
import time
def getargs():
parser = argparse.ArgumentParser(description='args for fake_gps')
parser.add_argument('--host',help='address of host',
required=False,type=str,default='127.0.0.1'
)
parser.add_argument('--port',help='listening port',
required=False,type=int,default=2947
)
args = parser.parse_args()
return args
if __name__ == '__main__':
args = getargs()
host = args.host
port = args.port
opts = {}
opts['verbose'] = True
opts['host'] = host
opts['port'] = port
session = gps.gps(**opts)
session.stream(gps.WATCH_ENABLE)
session.stream(gps.WATCH_NMEA)
ictr = 0
while True:
dd = next(session)
dd = dict(dd)
print('-'*40)
print(dd)
time.sleep(0.5)
####### Client to read data from
127.0.0.1:2947 ends #################