1. Synopsis

Name: nmea
Reference ID: GPS
Serial Port: /dev/gpsu; 4800-115200bps, 8N1
Serial Port: /dev/gpsppsu; for PPS
Features: tty_clk

2. Description

This driver supports GPS receivers with the $GPRMC, $GPGLL, $GPGGA, $GPZDA and $GPZDG NMEA sentences by default. Note that Accord’s custom NMEA sentence $GPZDG reports using the GPS timescale, while the rest of the sentences report UTC. The difference between the two is a whole number of seconds which increases with each leap second insertion in UTC. To avoid problems mixing UTC and GPS timescales, the driver disables processing of UTC sentences once $GPZDG is received.

The driver expects the receiver to be set up to transmit at least one supported sentence every second.

The accuracy depends on the receiver used. Inexpensive GPS models are available with a claimed PPS signal accuracy of 1 ┬Ás or better relative to the broadcast signal. However, in most cases the actual accuracy is limited by the precision of the timecode and the latencies of the serial interface and operating system.

If the operating system supports PPSAPI (RFC 2783), the flag1 1 option enables its use.

If there is a /dev/gpsppsu it is tried first for PPS, before /dev/gpsu.

The various GPS sentences that this driver recognises look like this (others are quietly ignored):

Table 1. Accepted NMEA sentences
Sentence Vendor







Important caveats: If your NMEA device does not ship GPZDA, you cannot use it to run autonomously without a check peer, or expect recovery from a trashed system clock. Also, dates from old NMEA devices are vulnerable to era wraparound; the NMEA driver has an internal trick that attempts to detect this, but one or more "g" suffixes on your time1 option may be useful as a workaround.

Table 2. NMEA data items
Symbol Meaning and Format


Time of day on UTC timescale. Hours, minutes and seconds [fraction (opt.)]. (hhmmss[.fff])


Position status. (A = Data valid, V = Data invalid)


Latitude (llll.ll)


Latitude direction. (N = North, S = South)


Longitude (yyyyy.yy)


Longitude direction (E = East, W = West)


Speed over ground. (knots) (x.x)


Heading/track made good (degrees True) (x.x)


Date (ddmmyy)


Magnetic variation (degrees) (x.x)


Magnetic variation (E = East, W = West)


Position Fix Mode (0 = Invalid, >0 = Valid)


Number of Satellites used in solution


Horizontal Dilution of Precision


Antenna Altitude


Altitude Units (Metres/Feet)


Geoid/Elipsoid separation


Geoid units (M/F)


Age of last DGPS Fix


Reference ID of DGPS station


Time of day on GPS timescale. Hours, minutes and seconds [fraction (opt.)]. (hhmmss[.f])


Day of the month (1-31)


Month of the year (1-12)




Denotes the signal strength (should be < 05.00)


GPS sync status 0 ⇒ INVALID time, 1 ⇒ accuracy of +/- 20ms, 2 ⇒ accuracy of +/- 100ns




Sentence terminator.

3. The 'mode' byte

Specific GPS sentences and bitrates may be selected by setting bits of the 'mode' in the refclock configuration line:

Table 3. mode byte bits and bit groups
Bit Decimal Hex Meaning




process $GPRMC




process $GPGGA




process $GPGLL




process $GPZDA or $GPZDG




Write the sub-second fraction of the receive time stamp to the clockstat file for all recognized NMEA sentences. This can provide a useful value for fudge time2 Caveat: This will fill your clockstat file rather fast. Use it only temporarily to get the numbers for the NMEA sentence of your choice.




process $PGRMF



reserved - leave 0




Append extra statistics to the clockstats line. Details below.

The default (mode 0) is to process all supported sentences at a linespeed of 9600 bps, which results in the first one received and recognized in each cycle being used. If only specific sentences should be recognized, then the mode byte must be chosen to enable only the selected ones. Multiple sentences may be selected by adding their mode bit values, but of those enabled, only the first received sentence in a cycle will be used. Using more than one sentence per cycle is impossible, because

  • there is only the time2 option available to compensate for transmission delays but every sentence would need a different one


  • using more than one sentence per cycle overstuffs the internal data filters.

The driver uses 9600 bps by default, unless NTPsec was built in Classic strict-compatibility mode, in which case the old default of 4800 bps is used. Faster bitrates can be selected using the baud option.

Caveat: Using higher line speeds does not necessarily increase the precision of the timing device. 9600 bps is useful to accommodate an amount of data that does not fit into a 1-second cycle at 4800 bps; some GPSes (especially when emitting skyview sentences) emit more than this. Any device that is exclusively used for time synchronisation purposes should be configured to transmit the relevant data only, e.g. one $GPRMC or $GPZDA per second; this will slightly reduce jitter by reducing variation in transmission times.

For backwards compatibility with NTP Classic, some bits of the mode byte can be used to set the device baud rate. This is deliberately left undocumented here, as new configurations should use the "baud" keyword. In future releases the compatibiility shim may be removed.

4. Monitor Data

The last GPS sentence that is accepted or rejected is written to the clockstats file and available with ntpq -c clockvar. (Logging the rejected sentences lets you see/debug why they were rejected.) Filtered sentences are not logged.

If the 0x10000 mode bit is on and clockstats is enabled, several extra counters will be appended to the NMEA sentence that gets logged. For example:

56299 76876.691 nmea(0) $GPGGA,212116.000,3726.0785,N,12212.2605,W,1,05,2.0,17.0,M,-25.7,M,,0000*5C  228 64 0 0 64 0
Table 4. Clockstats
Column Sample Meaning






Time of day in seconds



Driver type and unit.



NMEA Sentence



Number of sentences received



Number of sentences accepted and used for timekeeping



Number of sentences rejected because they were marked invalid (poor signal)



Number of sentences rejected because of bad checksum or invalid date/time



Number of sentences filtered by mode bits or same second



Number of PPS pulses used, overrides NMEA sentences

The clock identification in field 3 is normally the driver type and unit, but if your ntpd was built in strict Classic compatibility mode it will be a magic clock address expressing the same information in a more opaque way.

Sentences like $GPGSV that don’t contain the time will get counted in the total but otherwise ignored.

Configuring NMEA Refclocks might give further useful hints for specific hardware devices that exhibit strange or curious behaviour. Note that it describes NTP Classic and the old refclock configuration syntax, and assumes the old default speed of 4800 bps.

To make a specific setting, select the corresponding decimal values from the mode byte table, add them all together and enter the resulting decimal value into the clock configuration line.

5. Setting up the Garmin GPS-25XL

Switch off all output by sending it the following string.


Now switch only $GPRMC on by sending it the following string.


On some systems the PPS signal isn’t switched on by default. It can be switched on by sending the following string.


It is likely any surving instances of this hardware will have era-rollover issues when reporting dates. One or more "g" suffixes on your time1 option may be useful as a workaround.

6. Driver Options

unit number

The driver unit number, defaulting to 0. Used as a distinguishing suffix in the driver device name.

time1 time

Specifies the PPS time offset calibration factor, in seconds and fraction, with default 0.0.

time2 time

Specifies the serial end of line time offset calibration factor, in seconds and fraction, with default 0.0.

stratum number

Specifies the driver stratum, in decimal from 0 to 15, with default 0.

refid string

Specifies the driver reference identifier, an ASCII string from one to four characters, with default GPS.

flag1 {0 | 1}

Disable PPS signal processing if 0 (default); enable PPS signal processing if 1.

flag2 {0 | 1}

If PPS signal processing is enabled, capture the pulse on the rising edge if 0 (default); capture on the falling edge if 1.

flag3 {0 | 1}

If PPS signal processing is enabled, use the ntpd clock discipline if 0 (default); use the kernel discipline if 1.

flag4 {0 | 1}

Obscures location in timecode: 0 for disable (default), 1 for enable.


Not used by this driver.


Used to control GPS sentence selection and logging.

path filename

Overrides the default device path.

ppspath filename

Overrides the default PPS-device path.

baud number

Overrides the default baud/bps rate.

7. Configuration Example

refclock nmea baud 19200        # All sentences from /dev/gps0 at 19200 bps
refclock nmea path /dev/ttyUSB0 # All sentences from /dev/ttyUSB0 at 9600 bps

8. Known bugs

If your GPS has firmware made more than 1024 weeks (19 years and 36 weeks) in the past, its internal date counter will almost certainly wrap around and generate spurious timestamps. Beginning in January 2018, newer GPSes may have a longer wraparound (8192 weeks, or 157 years and 28 weeks) but it is not safe to bet that any given receiver will have firmware updated to take advantage of this.

This problem is fundamental and cannot be compensated for in code without relying on the accuracy of the local system clock, which is exactly what an NTP implementation may not do without risking perverse failure modes (especially at startup time). The only remedy is not to use ancient GPS hardware.

icons/home.gif Home Page

icons/sitemap.png Site Map

icons/mail2.gif Contacts