通过网络访问GPSD端口2947

Mad*_*dox 2 gpsd systemd

使用digitalbarbedwire.com上发布的信息,将RPI2与2017年1月最新的Jessie Lite Raspbian搭配Adafruit Ultimate GPS帽子和PPS。易于设置,PPS和所有gps命令在本地都可以正常运行。

我正在尝试让gpsd在端口2947上通过网络接受传入请求以导出位置信息(OpenCPN)。我编辑了/ etc / default / gpsd以添加-G选项GPSD_OPTIONS =“-n -G”,但是不允许外部请求。如果我停止gpsd(sudo服务停止gpsd),然后在前台调用gps(/ usr / sbin / gpsd -N -n -G / dev / ttyAMA0 / dev / pps0,则一切正常!所以我猜有一个权限问题,将gpsd作为守护程序启动,但是我还没有弄清楚,真让我发疯!

有什么建议么?

相关文件:

$ cat /lib/systemd/system/gpsd.socket
[Unit]
Description=GPS (Global Positioning System) Daemon Sockets

[Socket]
ListenStream=/var/run/gpsd.sock
ListenStream=[::1]:2947
ListenStream=0.0.0.1:2947
SocketMode=0600

[Install]
WantedBy=socket

$ cat /etc/default/gpsd
# Default settings for the gpsd init script and the hotplug wrapper.

# Start the gpsd daemon automatically at boot time
START_DAEMON="true"

# Use USB hotplugging to add new USB devices automatically to the daemon
USBAUTO="true"


# Devices gpsd should collect to at boot time.
# They need to be read/writeable, either by user gpsd or the group dialout.
DEVICES="/dev/ttyAMA0 /dev/pps0"

# Other options you want to pass to gpsd
GPSD_OPTIONS="-n"

$ cat /lib/systemd/system/gpsd.service
[Unit]
Description=GPS (Global Positioning System) Daemon
Requires=gpsd.socket
# Needed with chrony SOCK refclock
After=chronyd.service

[Service]
EnvironmentFile=-/etc/default/gpsd
ExecStart=/usr/sbin/gpsd -N -G $GPSD_OPTIONS $DEVICES

[Install]
Also=gpsd.socket
Run Code Online (Sandbox Code Playgroud)

有任何想法吗?

小智 5

Gpsd实际上并未在端口2947上监听,systemd在监听。默认情况下,在Debian中这仅是本地的。当有请求进入时,systemd会在必要时启动gpsd,并将将来的请求重定向到守护程序。因此,给gpsd -G参数实际上并不会改变任何东西。

您需要为systemd gpsd.socket单元添加替代,并告诉它侦听所有地址:

# /etc/systemd/system/gpsd.socket.d/socket.conf
[Socket]
# First blank ListenStream clears the system defaults
ListenStream=
ListenStream=2947
ListenStream=/var/run/gpsd.sock
Run Code Online (Sandbox Code Playgroud)

最佳实践是将此替代文件放在/ etc / systemd /中,而不是在/ lib / systemd /中编辑单元文件。

有关systemd.socket语法的文档:https ://www.freedesktop.org/software/systemd/man/systemd.socket.html

  • 我不得不挣扎了大约 8 个小时才发现“ListenStream”的顺序很重要!反之亦然:清除后应该首先指定`/var/run/gpsd.sock` unix socket,因为它是systemd socket进程的默认通信方式。正确的顺序是`ListenStream= ListenStream=/var/run/gpsd.sock ListenStream=2947` (2认同)