GPSD无法在b上正常启动

2024-05-13 23:31:28 发布

您现在位置:Python中文网/ 问答频道 /正文

我用的是覆盆子派零W(Raspbian NOOBS v2.9.0)

  • GPS模块是Neo 6M GPS模块 https://www.amazon.it/ILS-navigazione-satellitare-posizionamento-Arduino/dp/B07911Z266/ref=sr_1_46?ie=UTF8&qid=1542095676&sr=8-46&keywords=gps+raspberry+pi

  • 我用以下命令安装了GPSD

    sudo apt-get install gpsd gpsd-clients python-gps
    
  • 我已经启用了硬件串行端口,并用raspi配置禁用了串行控制台
  • 我编辑了/etc/default/gpsd文件,如下所示:

    START_DAEMON="true"
    GPSD_OPTIONS="/dev/ttyS0"
    DEVICES=""
    USBAUTO="false"
    GPSD_SOCKET="/var/run/gpsd.sock"
    
  • 我在/etc中添加了以下行/rc.本地(在“退出0”之前)

    sudo gpsd /dev/ttyS0 -F /var/run/gpsd.sock
    sudo python /home/pi/code.py
    
  • 在代码.py我运行了以下代码:

    import os
    import sys
    from gps import *
    import threading
    from threading import Thread
    
    class GpsPoller(threading.Thread):
    
        # object needed to obtain GPS data
        gpsd = None
    
        def __init__(self):
            print "Initializing GPS poller..."
            global gpsd         
    
            threading.Thread.__init__(self)
            gpsd = gps(mode=WATCH_ENABLE)
            self.current_value = None
            self.running = True
    
        def run(self):
            print "Starting GPS loop..."
            global gpsd
    
            while self.running:
    
                # get the next set of data
                gpsd.next()
    
                # clear screen
                os.system("clear")
    
                print
                print 'GPS'
                print
                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 'mode      ' , gpsd.fix.mode
                print '----------------------------------------'
                print
    
    gpsp = GpsPoller()
    gpsp.run()
    
  • 我已经在启动时禁用了GPSD服务(以阻止系统启动它并让此任务通过rc.本地)使用以下命令:

    sudo systemctl stop gpsd.socket
    sudo systemctl disable gpsd.socket
    

结果是,当我打开Rpi时,代码和gpsd守护进程会正常启动,但无法获取数据,如果我随后杀死python代码并手动启动它,它就可以工作了。在


Tags: 模块run代码importselfmodesudofix