Python – Read from gpsd/gpsfake with python-gps


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



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:
    # a = altitude, d = date/time, m=mode,  
    # o=postion/fix, s=status, y=satellites

    print ' GPS reading'
    print '----------------------------------------'
    print 'latitude    ' , session.fix.latitude
    print 'longitude   ' , session.fix.longitude
    print time.strftime("%H:%M:%S")

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


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 2947

the only response is


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:


Which will enable updates from all devices in JSON format.

To stop updates:


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

More information about clients:

GPSd JSON format: