Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

python gpsd client

#! /usr/bin/python
# Written by Dan Mandle http://dan.mandle.me September 2012
# License: GPL 2.0 
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 "
Killing Thread..."
    gpsp.running = False
    gpsp.join() # wait for the thread to finish what it's doing
  print "Done.
Exiting."
Comment

PREVIOUS NEXT
Code Example
Python :: convert numpy array to byteslist 
Python :: adding the first place value and second value in python 
Python :: pandas exploring dataframe 
Python :: “no such column” after adding a field to the model 
Python :: how to iterate a dictionary with minimum value in python 
Python :: how to insert files in tuple python 
Python :: django edit model without loading from db 
Python :: when was python 3.8 released 
Python :: Select a Column in pandas data Frame Using dot notation 
Python :: django rest serializer depth 
Python :: /var/www/html/flag 
Python :: reminder application with notification in python 
Python :: python identation 
Python :: checking if something is true. infinite 
Python :: permutation test python 
Python :: How to Remove Items in a Set in Python Using the remove() Method 
Python :: best python library to download files 
Python :: Python Tkinter Frame Widget Syntax 
Python :: difference() Function of sets in python 
Python :: csrf is not detected using sendbeacon django 
Python :: program to print areas in python 
Python :: Common elements in a list(comparing two lists.) 
Python :: change tag name using beautifulsoup python 
Python :: enter three numbers and find smallest number in python 
Python :: find element by partial link text selenium python 
Python :: djangorestframework install command 
Python :: Matrix Transpose using Nested List Comprehension 
Python :: reveal a defined function in python 
Python :: dalsports 
Python :: oauthlib python error 
ADD CONTENT
Topic
Content
Source link
Name
2+6 =