4

I'm having troubles with GPS output. When i type:

$ cat /dev/ttyUSB0

i have NMEA sentences coming out (it's what i want)

$GPGGA,134131.000,4548.0018,N,01557.1026,E,1,06,1.5,123.8,M,42.4,M,,0000*56

$GPGSA,A,3,12,15,24,17,22,18,,,,,,,2.3,1.5,1.8*30

$GPGSV,3,1,12,24,76,320,29,12,49,254,44,15,42,195,17,17,38,057,15*7A

$GPGSV,3,2,12,25,15,249,,09,12,112,,26,11,162,,18,09,267,19*75

$GPGSV,3,3,12,22,08,297,23,14,08,323,,04,06,114,,28,03,061,*78

$GPRMC,134131.000,A,4548.0018,N,01557.1026,E,1.71,291.64,210513,,,A*67

But, when i try to see output with python (this is basic code):

import gps
session=gps.gps('localhost','2947')
session.stream()
print session

i got this:

Time:      (nan)
Lat/Lon:  0.000000 0.000000
Altitude: ?
Speed:    ?
Track:    ?
Status:   STATUS_NO_FIX
Mode:     MODE_NO_FIX
Quality:  0 p=0.00 h=0.00 v=0.00 t=0.00 g=0.00
Y: 0 satellites in view:

I tried someone else's code but it always say NaN or 0:

    #! /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$

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

Output:

 GPS reading
----------------------------------------
latitude     0.0
longitude    0.0
time utc       +  nan
altitude (m) nan
eps          nan
epx          nan
epv          nan
ept          nan
speed (m/s)  nan
climb        nan
track        nan
mode         1

sats         []

So does somebody know why is this all zeros and unknown?

Please help, i'm trying to fix it for a week now.

Thanks

la lluvia
  • 705
  • 3
  • 10
  • 20
  • maybe gpsd is not running, try opening localhost:2947 in a browser – xuanji May 21 '13 at 14:07
  • it's running: root@beagleboard:~# ping localhost:2947 PING localhost:2947 (127.0.0.1): 56 data bytes 64 bytes from 127.0.0.1: seq=0 ttl=64 time=0.428 ms 64 bytes from 127.0.0.1: seq=1 ttl=64 time=0.274 ms 64 bytes from 127.0.0.1: seq=2 ttl=64 time=0.213 ms 64 bytes from 127.0.0.1: seq=3 ttl=64 time=0.214 ms 64 bytes from 127.0.0.1: seq=4 ttl=64 time=0.183 ms – la lluvia May 21 '13 at 14:28
  • I didn't know ping could do that, according to this SO question you can't specify ports for ping - http://serverfault.com/questions/309357/ping-a-specific-port – xuanji May 21 '13 at 14:35
  • do you know how to check localhost? i don't have browser on beagleboard – la lluvia May 21 '13 at 14:50
  • I don't know how to work with beagleboards and embedded systems, perhaps you could describe your setup more fully (eg is python running on the beagleboard? is there a gps receiver connected to it) and add a beagleboard tag. Maybe you need to install and run gpsd on the board, or try reading /dev/ttyUSB0 from python directly. The serverault link has some tools that can test specific ports. – xuanji May 21 '13 at 14:55
  • i've installed python on beagleboard, gps dongle is connected to begleboard. i've installed gpsd, pygps and add all libraries. I'm new in python, so i don't know is it possible to read from /dev/ttyUSB0 – la lluvia May 21 '13 at 15:31
  • Found it:ser = serial.Serial('/dev/ttyUSB0', 4800) – la lluvia May 21 '13 at 16:12
  • how did you solve the problem, i am encountering the same issue – user998316 Jan 31 '16 at 03:18
  • I didn't use gps library for python, simply got the data with: ser = serial.Serial('/dev/ttyUSB0', 4800, timeout=1). and then parsed the line to get needed data (line = ser.readline()) – la lluvia Jan 31 '16 at 17:15

1 Answers1

1

I had a similar problem with python-gps package on . Switching to gps3 did the trick for me:

from time import sleep
from gps3.agps3threaded import AGPS3mechanism

agps_thread = AGPS3mechanism()
agps_thread.stream_data()
agps_thread.run_thread()

while True:
    print('{},{}'.format(agps_thread.data_stream.lat, agps_thread.data_stream.lon))
    sleep(2)

That being said, the first item is always n/a,n/a for some reason, but subsequent values show correct data, which was not the case eariler.

Szymon Jednac
  • 2,969
  • 1
  • 29
  • 43