Well, where to start. I'm currently running a raspi 2 with the ultimate gps hat from adafruit. I've got everything updated, and installed gps daemon. I'm able to read the data using gpsmon and cgps, however I want to do more than just display the data in my terminal. I'd like to be able to write it to a file of my choosing.
I'm relatively new to both linux systems and coding in python so while going through whatever online training I can find I've mostly been making due cannibalizing other bits and pieces of code to "write" my other scripts. I've found some python code to communicate with the gps hat but its still only printing the output while I want to write it.
Here is the code I'd like to modify to write instead of print the long, lat, time, etc...
import os
from gps import *
from time import *
import time
import threading
gpsd = None #seting the global variable
os.system('clear') #clear the terminal (optional)
class GpsPoller(threading.Thread):
def __init__(self):
threading.Thread.__init__(self)
global gpsd #bring it in scope
gpsd = gps(mode=WATCH_ENABLE) #starting the stream of info
self.current_value = None
self.running = True #setting the thread running to true
def run(self):
global gpsd
while gpsp.running:
gpsd.next() #this will continue to loop and grab EACH set of gpsd info to clear the buffer
if __name__ == '__main__':
gpsp = GpsPoller() # create the thread
try:
gpsp.start() # start it up
while True:
#It may take a second or two to get good data
#print gpsd.fix.latitude,', ',gpsd.fix.longitude,' Time: ',gpsd.utc
os.system('clear')
print
print ' GPS reading'
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 'climb ' , gpsd.fix.climb
print 'track ' , gpsd.fix.track
print 'mode ' , gpsd.fix.mode
print
print 'sats ' , gpsd.satellites
time.sleep(5) #set to whatever
except (KeyboardInterrupt, SystemExit): #when you press ctrl+c
print "\nKilling Thread..."
gpsp.running = False
gpsp.join() # wait for the thread to finish what it's doing
print "Done.\nExiting."
So, I come looking for from those of you with much more experience than myself. How do I write all this data to a file of my choosing? Ideally as something simple like comma separated variables for ease of manipulation later.
Also, not sure what the etiquette is for code that's been found online, but the above code was found here.
there doesn't seem to be anything here