Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python3
- # coding=utf-8
- """TriviaL example using the thread triumvirate
- agps_thread = AGPS3mechanism()
- agps_thread.stream_data()
- agps_thread.run_thread()
- imported from the agps3threaded.py class AGPS3mechanism. The unordered associative array
- from the gpsd is then exposed as attributes of that 'data_stream'
- """
- from time import sleep
- import serial
- import os
- from gps3.agps3threaded import AGPS3mechanism
- __author__ = 'Moe'
- __copyright__ = 'Copyright 2016 Moe'
- __license__ = 'MIT'
- __version__ = '0.2'
- agps_thread = AGPS3mechanism() # Instantiate AGPS3 Mechanisms
- agps_thread.stream_data() # From localhost (), or other hosts, by example, (host='gps.ddns.net')
- agps_thread.run_thread() # Throttle time to sleep after an empty lookup, default 0.2 second, default daemon=True
- host = "/dev/ttyS2"
- def __init__():
- while True: # All data is available via instantiated thread data stream attribute.
- # line #140-ff of /usr/local/lib/python3.5/dist-packages/gps3/agps.py
- print('---------------------')
- print( agps_thread.data_stream.time)
- print('Lat:{} '.format(agps_thread.data_stream.lat))
- print('Lon:{} '.format(agps_thread.data_stream.lon))
- print('Speed:{} '.format(agps_thread.data_stream.speed))
- print('Course:{}'.format(agps_thread.data_stream.track))
- print('---------------------')
- sleep(5) # Sleep, or do other things for as long as you like.
- def make():
- while True:
- f = open('GPS/gps.txt', 'w')
- f.write(host)
- try:
- while True:
- lat = str('Lat:{} '.format(agps_thread.data_stream.lat))
- lon = str('Lon:{} '.format(agps_thread.data_stream.lon))
- f.write(',' + lat + ',' + lon)
- sleep(1)
- except(KeyboardInterrupt, SystemExit):
- print("Done and now exiting!")
- f.close()
- __init__()
- make()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement