“After the nice reception my last article on NTP got, I decided that it was about time I pulled a project off the shelf from a few years ago and get a stratum 1 NTP server running on a Raspberry Pi again.
So this article is going to be my notes on how I built one using a cheap GPS module off eBay as the reference time source and a Raspberry Pi. (a 2B in this case, but hopefully the differences for newer models will be minor; if there are any, they’re probably around the behavior of the serial port since I think things changed on the Pi3 with bluetooth support?)
So anyways, before we jump into it, let’s spend some time talking about why you would and wouldn’t want to do this:
Pro: NTP is awesome, and this lets you get a stratum 1 time server on your local network for much lower cost that traditional COTS NTP time standards, which tend to be in the thousands of dollars price range.
Con: This is a Raspberry Pi, booting off an SD card, with a loose PCB plugged into the top of it, so I wouldn’t classify it as “a robust appliance”. It isn’t a packaged enterprise grade product, so I wouldn’t rely on this NTP server on its own for anything too critical, but then again, I would say that about NTP in general; it’s only meant to get clocks to within “pretty close” of real time. If you’re chasing individual milliseconds, you should probably be using PTP (Precision Time Protocol) instead of NTP… Totally depends on what you’re doing. I’m just being a nerd.
Pro: The pulse-per-second driver for the Raspberry Pi GPIO pins is pretty good, so once you get this working, the GPS receiver will set the Pi’s clock extremely well!
Con: The Raspberry Pi’s Ethernet interface is actually hanging off of a USB hub which is hanging off of the USB interface on the SoC (system on chip) that powers the Raspberry Pi, so there is an intrinsically higher level of latency/jitter on the Pi’s Ethernet interface vs a “real” PCIe NIC. This means that your bottleneck for getting crazy good time sync on all of your computers is ironically going to be getting the time off of the Raspberry Pi onto the network…
Pro: I would expect this USB jitter to be on the order of 500 microseconds, which is still less than a millisecond, and remember what I said about chasing individual milliseconds in NTP? This should be fine for any reasonable user of NTP.”