微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何修复“网络无法访问”错误 - GPS Neo 7m?

如何解决如何修复“网络无法访问”错误 - GPS Neo 7m?

硬件和软件:GPS NEO 7m、RaspBerry PI3、ArchARM

我正在尝试使用此 Python 程序 [通过 UART] 读取 GPS 坐标:

    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))

我已经正确配置了所有内容,因为我通过 cgps -s 获得了坐标。 当我尝试运行上面的程序时,我得到:

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
    self.sock.connect(sa)
OSError: [Errno 101] Network is unreachable

我做的程序:

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

这很好用。

运行python程序给了我上面的错误

我不知道还能做什么。我错过了什么?

文件 gpsd.socket:

[Unit]
Description=GPS (Global Positioning System) Daemon Sockets

[Socket]
ListenStream=/var/run/gpsd.sock
#ListenStream=[::1]:2947
#ListenStream=127.0.0.1:2947
# To allow gpsd remote access,start gpsd with the -G option and
# uncomment the next two lines:
ListenStream=[::]:2947
ListenStream=0.0.0.0:2947
SocketMode=0600
BindIPv6Only=yes

[Install]
WantedBy=sockets.target

非常感谢

解决方法

好的,我发现问题了。 似乎 gps 模块只能在 Python2 上运行

所以,我用 Python2 和 pip2 做了一个干净的拱臂安装,使用 sudo pip2 install gps 安装了 gps,它的工作原理很迷人

如果我运行 python3,则找不到模块

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。