Python – Read from gpsd/gpsfake with python-gps

gpspython

I've been trying very hard to get gpsfake to work with python-gps for the last days.
I execute gpsfake with the following example sentences, which I found on the internet:

gpsfake test_data.log

test_data.log:

$PMGNST,05.40,2,T,961,08.3,+04583,00*4C
$GPGLL,5036.9881,N,00707.9142,E,125412.480,A*3F
$GPGGA,125412.48,5036.9881,N,00707.9142,E,2,04,20.5,00269,M,,,,*17
$GPRMC,125412.48,A,5036.9881,N,00707.9142,E,00.0,000.0,230506,00,E*4F
$GPGSA,A,2,27,04,08,24,,,,,,,,,20.5,20.5,*12
$GPGSV,3,1,10,13,81,052,,04,58,240,39,23,44,064,,24,43,188,36*75
$GPGSV,3,2,10,02,42,295,,27,34,177,40,20,21,113,,16,12,058,*7F
$GPGSV,3,3,10,08,07,189,38,10,05,293,,131,11,117,,120,28,209,*76

Once it's running, I execute a Python script I found here:

import gps
import os
import time

if __name__ == '__main__':
    session = gps.gps(verbose=1)

while 1:
    os.system('clear')
    session.next() 
    # 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.strftime("%H:%M:%S")

    print
    print ' Satellites (total of', len(session.satellites) , ' in view)'
    for i in session.satellites:
        print '\t', i

    time.sleep(3)

I gets a connection, but then it gets locked in class gpscommon, method read() on line 80:

frag = self.sock.recv(4096)

which tells me that no data is received or even sent.

When I try to connect over the terminal with

connect 127.0.0.1 2947

the only response is

{"class":"VERSION","release":"3.4","rev":"3.4","proto_major":3,"proto_minor":6}

and nothing else.

Does anyone have an idea how to get the correct data? I tried various NMEA log files, so I think that's not the reason.

Best Solution

To get location reports you'll have to start 'Watching' the devices gpsd/gpsfake is monitoring, try sending:

?WATCH={"enable":true,"json":true};

Which will enable updates from all devices in JSON format.

To stop updates:

?WATCH={"enable":false};

Once watching is enabled you'll get 'TPV' responses containing location data and 'SKY' responses with satellite data.

More information about clients: http://www.catb.org/gpsd/client-howto.html

GPSd JSON format: http://www.catb.org/gpsd/gpsd_json.html