2017-02-15 328 views
0

使用Adafruit Ultimate GPS帽子和PPS使用最新的Jessie Lite Raspbian 2017年1月的RPI2,使用来自digitalbarbedwire.com的帖子中的信息。易于安装和PPS以及所有gps命令在本地非常有效。通过网络访问GPSD端口2947

我想让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作为守护,但我还没有想通出来呢Drivings我坚果

任何建议

相关文件:!?

$ 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 

任何想法

回答

2

Gpsd实际上并没有在端口2947上进行监听,systemd是。默认情况下,在Debian中,这只是本地的。当一个请求如果有必要,t进入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 

最好的做法是把这个覆盖文件在/ etc/systemd /和不要编辑/ lib/systemd /中的单元文件。在systemd.socket语法

文档:https://www.freedesktop.org/software/systemd/man/systemd.socket.html

0

另一种方法是做端口转发的终端较少SSH会话。

例如,假设您有PC1运行gpsd服务(通过systemd或独立运行)。

从PC2,可以做到这一点:

ssh -N -L 2947:localhost:2947 [email protected] 

-N标志防止实际的终端会话(没有命令执行)。 -L标志表示将端口2947转发到本地主机2947.

现在,如果由于某种原因会话丢失或终止,ssh将不会自动重新连接。解决的办法是安装autossh,可在大多数Linux发行版中使用。

然后可以使用autossh像这样:

autossh -N -M 0 -o "ServerAliveInterval 30" -o "ServerAliveCountMax 3" -L 2947:localhost:2947 [email protected] 

如果一切正常,加上-f让autossh在后台模式去。

您可以轻松地从rc.local或systemd单元运行autossh。这样做意味着你只需要在(22)中允许SSH端口,并且现在通过安全的加密连接传递GPS信息,这是gpsd套接字会话本身无法做到的。显然,如果您在PC1和PC2之间设置了密钥对,它将有所帮助,因为您不需要密码。

您可以在PC2上运行随其附带的任何gpsd工具,因为它会出现在本地。来自脚本/程序的API调用也将工作,就好像端口2947实际上在本地运行gpsd一样。

Look here for more detail on how to use autossh