Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python3
- from gpsdclient import GPSDClient # pip3 install gpsdclient
- client = GPSDClient()
- try:
- # using a with-statement will automatically close file when leaving the scope
- with open('GPS/gps.txt', 'w') as f:
- # get stream of messages from gpsd
- for msg in client.dict_stream():
- if msg['class'] == 'TPV': # time-position-velocity report
- # for a list of fields that may be available, see:
- # https://gpsd.gitlab.io/gpsd/gpsd_json.html#_tpv
- t = msg.get('time', None)
- let = msg.get('lat', None)
- lon = msg.get('lon', None)
- f.write( f"time={t}, lat={lat}, lon={lon}\n" )
- except KeyboardInterrupt:
- # exit gracefully on control-C
- pass
- finally:
- # cleanup
- client.close()
- print("Done and now exiting!")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement