Hardware and Software: GPS NEO 7m, Raspberry PI3, ArchARM

I'm trying to read GPS coordinates [via UART] using this Python program:

    from sys import argv
    import gps
    import requests
    #Listen on port 2947 of gpsd
    session = gps.gps("localhost", "2947")
    session.stream(gps.WATCH_ENABLE | gps.WATCH_NEWSTYLE)
    while True :
    #Read GPS Coordinates
            report = session.next()
            try :
                    if report["class"] == "TPV" :
                            print(str(rep.lat) + "," + str(rep.lon))
            except Exception as e :
                    print("Got exception " + str(e))

I have configured everything correctly, because I get the coordinates doing cgps -s. When I try to run the program above I get:

Traceback (most recent call last):
  File "/home/alarm/program_python/testGPS.py", line 14, in <module>
    session = gps.gps("localhost", "2947")
  File "/usr/lib/python3.9/site-packages/gps/gps.py", line 580, in __init__
    gpscommon.__init__(self, host=host, port=port,
  File "/usr/lib/python3.9/site-packages/gps/client.py", line 66, in __init__
    self.connect(self.host, self.port)
  File "/usr/lib/python3.9/site-packages/gps/client.py", line 92, in connect
OSError: [Errno 101] Network is unreachable

The procedure I made:

  • sudo killall gpsd
  • sudo gpsd /dev/ttyS0 -F /var/run/gpsd.socket
  • cgps -s

This works fine.

Running the python program gives me the error above

I don't know what to do more. What am I missing?

file gpsd.socket:

Description=GPS (Global Positioning System) Daemon Sockets

# To allow gpsd remote access, start gpsd with the -G option and
# uncomment the next two lines:


Thanks a lot

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.