USB GPS dongles have come down significantly in price in recent years and I picked one up to play with recently.
Apart from using a GPS module to report your latitude, longitude, altitude and time for mapping applications, it’s also possible to feed the time information to ntpd as a back-up time source or as a highly accurate time source depending on the GPS module you end up getting.
The module that I use in this blog post is a Columbus v800 which was reasonably cheap (around 35USD of ebay), I had originally bought it for recording my GPS tracks on long haul flights on my laptop.
To add the USB GPS time source to ntpd, first install ntpd and the needed GPS related daemons and tools.
On a recent Ubuntu machine I did the following, this should work on a recent Debian machine as well.
apt-get install ntpd gpsd-clients gpsd gpsd-clients
Once the tools are installed, edit `/etc/default/gpsd` and modify the like that reads:
The above change will make the GPS look for satellites as soon as it starts up. Gpsd presents data to the user in a number of ways; in this case gpsd is already writing information out to a shared memory segment that ntpd understands as it usually follows the NMEA standard – some more information can be found here http://www.catb.org/gpsd/NMEA.html.
Once gpsd is restarted, verify that you are receiving data by running the `cgps` command from a terminal window. If it works, this would be the type of output that is expected:
Hit ctrl-c and exit from this application. Once the GPS module is functioning as expected, ntpd must be configured to use GPS dongle as a time source.
Add the following to `/etc/ntp.conf`
# GPS Serial data reference server 127.127.28.0 minpoll 4 maxpoll 4 fudge 127.127.28.0 time1 0.0 refid GPS # GPS PPS reference server 127.127.28.1 minpoll 4 maxpoll 4 prefer fudge 127.127.28.1 refid PPS
The above adds two sources – the GPS time source from the serial data reference, a generic time source available on almost all GPS dongles; and the PPS reference, not always available on the cheaper GPS dongles but it is far more accurate if it is available. See http://www.catb.org/gpsd/hardware.html for a list of recommended GPS modules that have PPS output.
Once the above lines have been added to ntp.conf, ntpd should be restarted. To further understand the configuration see http://doc.ntp.org/4.2.6/drivers/driver28.html
To verify that the GPS module is indeed feeding ntpd, run the command `ntpq -p` in a terminal
Here the GPS time source is selected as the primary time source as it has a small offset and no delay. Over time the V800 GPS module introduces jitter which is either large or not consistent with the other time servers, ntpd then flags this particular time source as being a falseticker and as a result it is not used.
There is not much advantage of using this particular GPS device as a time source due to its lack of a PPS time source and high or random jitter. However if the network is unreliable and drops out the gps time source will be promoted back to a valid time source as the networked time servers are not accessible.
This may be useful for applications where having accurate time important and the network connection is either unreliable or non-existent.
Ready to start getting insights from your applications? Sign up for a Logentries free trial today.