Background

This is a bag of bits post. It’s the stuff I messed with or found while trying to get a GP-20U7 GPS receiver connected to a Raspberry Pi B+. Here’s the first part which outlines how to get it working. You should only really need this if that hasn’t worked.

Raspberry Pi 3

UART (see below: ‘What the Hell is UART?’) is disabled by default on the Pi 3. You must enable it in /boot/config.txt by adding the following line and rebooting:

  enable_uart=true

The end of this long rambling thread starts to talk about differences with the Pi 3.

And have a look at this SO page too and this one explains why there are changes in Serial config on the Pi 3.

Using the gpsd systemd unit (service)

Journalctl. Use journalctl to see whether gpsd started correctly. Use it’s flags/options to control how much information is returned (e.g. --since yesterday) or pipe to tail to get the most recent log entries (journalctl | tail -n 100).

Not Disabling The Serial service

If you don’t stop and disable serial-getty@ttyAMA0.service, then you’ll get an error like this when running journalctl | tail -n 200.

  Feb 01 23:12:46 pibox0 systemd[1]: Starting GPS (Global Positioning System) Daemon...
  Feb 01 23:12:46 pibox0 systemd[1]: Started GPS (Global Positioning System) Daemon.
  Feb 01 23:12:48 pibox0 login[1803]: FAILED LOGIN (2) on '/dev/ttyAMA0' FOR 'UNKNOWN', Authentication failure
  Feb 01 23:12:49 pibox0 login[1803]: pam_unix(login:auth): check pass; user unknown
  Feb 01 23:12:49 pibox0 login[1803]: pam_unix(login:auth): authentication failure; logname=LOGIN uid=0 euid=0 tty=/dev/ttyAMA0 ruser= rhost=

Relevant Files

GPSD Unit Configuration File: Socket

This site says .socket files encodes information about an IPC or network socket or a file system FIFO controlled and supervised by systemd.

Filepath: /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.0:2947   # Note - I changed it to this from default.
  SocketMode=0600

  [Install]
  WantedBy=sockets.target

GPSD Unit Definition File: Service

Filepath: /lib/systemd/system/gpsd.service

  [Unit]
  Description=GPS (Global Positioning System) Daemon
  Requires=gpsd.socket

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

  [Install]
  Also=gpsd.socket

Defaults for the GPSD Service

Filepath: /etc/default/gpsd:

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

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

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

  # Other options you want to pass to gpsd
  GPSD_OPTIONS="D5”

The GPSD_OPTIONS in this file allows us to specify gpsd options that might help with debugging. D defines the debugging level (from 1 - 8 I think).

Baud Rate?

I saw some references to tweaking the baud rate of the serial connection. I didn’t have to change it, so didn’t explore much further.

Running gpsd not as a service

  $> gpsd -N (other options) /dev/serial0

Update

More recently (March 2017), I tried getting the gps + serial to work with a Raspberry Pi 3. I think I made hard work of it given that there are already some resources out there. The best thing I found was this post on Element14, which has a comment in which explains the options clearly. I decided to go with their option 1. Based on that, this is what I did:

  • Comment out the enable_uart=true. It will stop things working under this setup.
  • Still ensure the relevant part of /boot/cmdline.txt is removed.
  • Uncomment or add this line to /boot/config.txt, which will disable your bluetooth. If you don’t want to disable your bluetooth, then read the options in the Element14 post above.
    dtoverlay=pi3-disable-bt
    
  • Your firewall probably won’t make any difference; it’s a localhost connection which is invariably left alone by firewalls. I looked at it just in case.
  • Use ls -al /dev to get a feel for what devices are being symbolically linked. This was useful in seeing serial0 --> ttyAMA0 and serial1 --> ttyS0.
  • I used sudo cat serial0 and sudo cat serial1 to work out which one was streaming GPS data.
  • I used this to determine which serial value to put in /etc/default/gpsd.
  • GPS still needs to see the sky; things haven’t moved on much in 2 months.