【发布时间】:2019-04-16 00:48:05
【问题描述】:
我使用的是 Raspberry PI Zero 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-config 启用了硬件串行端口并禁用了串行控制台
-
我已将文件 /etc/default/gpsd 编辑如下:
START_DAEMON="true" GPSD_OPTIONS="/dev/ttyS0" DEVICES="" USBAUTO="false" GPSD_SOCKET="/var/run/gpsd.sock" -
我在 /etc/rc.local 中添加了以下几行(在“exit 0”之前)
sudo gpsd /dev/ttyS0 -F /var/run/gpsd.sock sudo python /home/pi/code.py -
在 code.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.local 完成),使用以下命令:
sudo systemctl stop gpsd.socket sudo systemctl disable gpsd.socket
结果是,当我打开Rpi时,代码和gpsd守护进程正常启动但无法获取数据,如果我随后杀死python代码并手动启动它,它可以工作。
【问题讨论】:
-
我认为您在
/etc/default/gpsd中将GPSD_OPTIONS和DEVICES的内容互换了 -
没有改变
-
您是否尝试将相关用户添加到
dialout组?sudo adduser <username> dialout -
@MarkSetchell 感谢您的建议,但是我尝试切换到 Rpi 3 B+ 并且它似乎工作......这不是一个真正的解决方案(因为我宁愿让它在 Rpi 零上工作)但现在已经足够了
标签: python raspberry-pi raspbian rc gpsd