Create a gist now

Instantly share code, notes, and snippets.

Embed
What would you like to do?
python-gps sample codes
import gps, os, time
session = gps.gps()
while 1:
os.system('clear')
session.query('admosy')
# a = altitude, d = date/time, m=mode,
# o=postion/fix, s=status, y=satellites
print
print ' GPS reading'
print '----------------------------------------'
print 'latitude ' , session.fix.latitude
print 'longitude ' , session.fix.longitude
print 'time utc ' , session.utc, session.fix.time
print 'altitude ' , session.fix.altitude
print 'eph ' , session.fix.eph
print 'epv ' , session.fix.epv
print 'ept ' , session.fix.ept
print 'speed ' , session.fix.speed
print 'climb ' , session.fix.climb
print
print ' Satellites (total of', len(session.satellites) , ' in view)'
for i in session.satellites:
print '\t', i
time.sleep(3)
#! /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 "\nKilling Thread..."
gpsp.running = False
gpsp.join() # wait for the thread to finish what it's doing
print "Done.\nExiting."
@wolfg1969

This comment has been minimized.

Show comment
Hide comment
@wolfg1969

wolfg1969 Mar 26, 2013

Traceback (most recent call last):
  File "gps_demo.py", line 7, in <module>
    session.query('admosy') 
AttributeError: gps instance has no attribute 'query'
Owner

wolfg1969 commented Mar 26, 2013

Traceback (most recent call last):
  File "gps_demo.py", line 7, in <module>
    session.query('admosy') 
AttributeError: gps instance has no attribute 'query'
@wolfg1969

This comment has been minimized.

Show comment
Hide comment
@wolfg1969

wolfg1969 Apr 3, 2013

gpsdData.py works!

Owner

wolfg1969 commented Apr 3, 2013

gpsdData.py works!

@avapaulradej

This comment has been minimized.

Show comment
Hide comment
@avapaulradej

avapaulradej May 26, 2015

gpsData.py Line 25 in this line you are using variable 'gpsp' ('P' on the end) which is not defined in the scope.

Instead of "while gpsp.running:"
Shouldn't it be "while self.running:"?

avapaulradej commented May 26, 2015

gpsData.py Line 25 in this line you are using variable 'gpsp' ('P' on the end) which is not defined in the scope.

Instead of "while gpsp.running:"
Shouldn't it be "while self.running:"?

@jilkka

This comment has been minimized.

Show comment
Hide comment
@jilkka

jilkka Apr 11, 2016

@wolfg1916, got your gps_demo.py to work, see revisions:
https://gist.github.com/jilkka/1b5b9704ed8fd491e769897a0248e7cc/revisions

jilkka commented Apr 11, 2016

@wolfg1916, got your gps_demo.py to work, see revisions:
https://gist.github.com/jilkka/1b5b9704ed8fd491e769897a0248e7cc/revisions

@josmargoncal

This comment has been minimized.

Show comment
Hide comment
@josmargoncal

josmargoncal Apr 11, 2016

Hello, and Thank you for the information. I tried the new revision and I have the same error than before with the gps_demo.py.
What am I doing wrong?

gps instance has no attribute 'query'

josmargoncal commented Apr 11, 2016

Hello, and Thank you for the information. I tried the new revision and I have the same error than before with the gps_demo.py.
What am I doing wrong?

gps instance has no attribute 'query'

@NoelBroda

This comment has been minimized.

Show comment
Hide comment
@NoelBroda

NoelBroda Oct 22, 2016

Hi man!
I have this issue in RaspberryPi (Raspbian):

Traceback (most recent call last):
  File "gps_demo.py", line 7, in <module>
    session.query('admosy') 
AttributeError: gps instance has no attribute 'query'

NoelBroda commented Oct 22, 2016

Hi man!
I have this issue in RaspberryPi (Raspbian):

Traceback (most recent call last):
  File "gps_demo.py", line 7, in <module>
    session.query('admosy') 
AttributeError: gps instance has no attribute 'query'
@JakeTun

This comment has been minimized.

Show comment
Hide comment
@JakeTun

JakeTun Jan 25, 2017

no module name gps

JakeTun commented Jan 25, 2017

no module name gps

@yohanboniface

This comment has been minimized.

Show comment
Hide comment
@yohanboniface

yohanboniface Feb 5, 2017

@JakeTun sudo apt-get install python-gps

yohanboniface commented Feb 5, 2017

@JakeTun sudo apt-get install python-gps

@JakeTun

This comment has been minimized.

Show comment
Hide comment
@JakeTun

JakeTun commented Feb 7, 2017

thanks

@snlakshmi08

This comment has been minimized.

Show comment
Hide comment
@snlakshmi08

snlakshmi08 Feb 24, 2017

I m not getting the values of latitudes and longitudes and I used gpsdData.py..plz help me out

snlakshmi08 commented Feb 24, 2017

I m not getting the values of latitudes and longitudes and I used gpsdData.py..plz help me out

@gx07

This comment has been minimized.

Show comment
Hide comment
@gx07

gx07 Mar 6, 2017

I have this issue in RaspberryPi (Raspbian):

I did => sudo apt-get install python-gps and executed gpsdData.py script
I am getting the following error. Can someone please help?

Traceback (most recent call last):
File "/home/pi/Desktop/pythonGPSData.py", line 29, in
gpsp = GpsPoller() # create the thread
File "/home/pi/Desktop/pythonGPSData.py", line 19, in init
gpsd = gps(mode=WATCH_ENABLE) #starting the stream of info
NameError: global name 'gps' is not defined

gx07 commented Mar 6, 2017

I have this issue in RaspberryPi (Raspbian):

I did => sudo apt-get install python-gps and executed gpsdData.py script
I am getting the following error. Can someone please help?

Traceback (most recent call last):
File "/home/pi/Desktop/pythonGPSData.py", line 29, in
gpsp = GpsPoller() # create the thread
File "/home/pi/Desktop/pythonGPSData.py", line 19, in init
gpsd = gps(mode=WATCH_ENABLE) #starting the stream of info
NameError: global name 'gps' is not defined

@shafiqhafidz

This comment has been minimized.

Show comment
Hide comment
@shafiqhafidz

shafiqhafidz Mar 24, 2017

Hi. I do have similar problem on GPSData.py code.
Traceback (most recent call last):
File "/home/pi/Desktop/pythonGPSData.py", line 29, in
gpsp = GpsPoller() # create the thread
File "/home/pi/Desktop/pythonGPSData.py", line 19, in init
gpsd = gps(mode=WATCH_ENABLE)

can u help to troubleshoot this problem sir?

shafiqhafidz commented Mar 24, 2017

Hi. I do have similar problem on GPSData.py code.
Traceback (most recent call last):
File "/home/pi/Desktop/pythonGPSData.py", line 29, in
gpsp = GpsPoller() # create the thread
File "/home/pi/Desktop/pythonGPSData.py", line 19, in init
gpsd = gps(mode=WATCH_ENABLE)

can u help to troubleshoot this problem sir?

@rrase

This comment has been minimized.

Show comment
Hide comment
@rrase

rrase Feb 16, 2018

I m not getting the values of latitudes and longitudes and I used gpsdData.py..plz help me out

rrase commented Feb 16, 2018

I m not getting the values of latitudes and longitudes and I used gpsdData.py..plz help me out

@rrase

This comment has been minimized.

Show comment
Hide comment
@rrase

rrase Feb 16, 2018

pls somebody help out to get the values of longitude and latitudes

rrase commented Feb 16, 2018

pls somebody help out to get the values of longitude and latitudes

@rtennill

This comment has been minimized.

Show comment
Hide comment
@rtennill

rtennill Mar 8, 2018

What version of gpsd does this target? There is no query() in my gps object under Python 2.7 on Ubuntu 16.04 (arm64) .

rtennill commented Mar 8, 2018

What version of gpsd does this target? There is no query() in my gps object under Python 2.7 on Ubuntu 16.04 (arm64) .

@Ahmedeish11

This comment has been minimized.

Show comment
Hide comment
@Ahmedeish11

Ahmedeish11 Jun 19, 2018

11
how i can solve this problem?

Ahmedeish11 commented Jun 19, 2018

11
how i can solve this problem?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment