Reputation: 61
Have a RPI2 with latest Jessie Lite Raspbian Jan 2017 with Adafruit Ultimate GPS hat and PPS using info from a post at digitalbarbedwire.com. Easy setup and PPS and all gps commands work great locally.
I am trying to get gpsd to accept incoming requests over the network on port 2947 to export position info (OpenCPN). I edited /etc/default/gpsd to add the -G option GPSD_OPTIONS="-n -G" but external requests are not being allowed. If I stop gpsd (sudo service stop gpsd), and invoke gps in the foreground (/usr/sbin/gpsd -N -n -G /dev/ttyAMA0 /dev/pps0, all works fine! So I am guessing there is a permissions problem starting the gpsd as a daemon, but I haven't figured it out yet. Drivings me nuts!
Any suggestions?
Relevant files:
$ 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
Any ideas?
Upvotes: 6
Views: 14614
Reputation: 1
Install socat and use this command:
socat TCP4-LISTEN:2948,reuseaddr,fork TCP4:localhost:2947
And use port 2948 over network You can add this in crontab
Upvotes: 0
Reputation: 3807
After running down all the suggestions including the above, I ended up just following the instructions on the troubleshooting page for gpsd in gitlab, in the last section called "Real World Example". That's the only thing that worked for me.
Upvotes: 1
Reputation: 21
Linux Mint 19, I had to replace 127.0.0.1 with 0.0.0.0, then I could share GPS data on LAN
#/lib/systemd/system/gpsd.socket/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
ListenStream=0.0.0.0:2947
SocketMode=0600
[Install]
WantedBy=sockets.target
Upvotes: 2
Reputation: 303
Another way to do it is to do a terminal-less SSH session with port forwarding.
For example, let's say you have PC1 running a gpsd service (either via systemd or stand-alone).
From PC2, you can do this:
ssh -N -L 2947:localhost:2947 user@PC1
The -N flag prevents an actual terminal session (no commands executed). The -L flag means forward port 2947 to localhost 2947.
Now, ssh will not auto-reconnect if for some reason the session is lost or terminated. The work around is to install autossh, available in most linux distro repositories.
You can then use autossh like so:
autossh -N -M 0 -o "ServerAliveInterval 30" -o "ServerAliveCountMax 3" -L 2947:localhost:2947 user@PC1
If it works, add -f to let autossh go in background mode.
You can easily run autossh from rc.local or a systemd unit. Doing it this ways means you only have to allow SSH port in (22) and are now passing the gps info via a secure encrypted connection, something that a gpsd socket session alone can't do. Obviously, it helps if you have a key pair setup between PC1 and PC2 as you won't need a password.
You can run on PC2 any of the gpsd tools that come with it as it will appear local to it. API calls from scripts/programs will also work as if port 2947 was actually running gpsd locally.
Look here for more detail on how to use autossh.
Upvotes: 1
Reputation: 71
Gpsd is not actually listening on port 2947, systemd is. By default in Debian this is local only. When a request comes in systemd starts gpsd, if necessary, and redirects future requests to the daemon. So giving gpsd the -G parameter will not actually change anything.
You need to add an override for the systemd gpsd.socket unit, and tell it to listen on all addresses:
# /etc/systemd/system/gpsd.socket.d/socket.conf
[Socket]
# First blank ListenStream clears the system defaults
ListenStream=
ListenStream=2947
ListenStream=/var/run/gpsd.sock
Best practice is to put this override file in /etc/systemd/, and not to edit the unit files in /lib/systemd/.
Documentation on the systemd.socket syntax: https://www.freedesktop.org/software/systemd/man/systemd.socket.html
Upvotes: 7