Pi-Based Stratum 1 GPS Time Server


At the UKMON conference in Cardiff last year Edward Cooper demonstrated an Adurino-based NTP (Network Time Protocol) server using GPS as its time source. Edward has provided step-by step instructions in his ARDUINO-based GPS/NTP time server article.

Having a good source of accurate time is vital for meteor observation. Typically, UKMON observation stations will use remote NTP servers accessed via the Internet but this presents a particular challenge for remote sites with no, or poor, internet connectivity.

This article describes briefly the construction of an alternative GPS / NTP solution based on the Raspberry Pi computer.

Why a Raspberry Pi?

The answer to this question is not very technical, it is simply that we had a spare Raspberry Pi 2B looking for a project and Edward’s Arduino time server had piqued our interest. We thought that this would be a useful evaluation / comparison for those with a fascination for all thing’s Pi.

There are pros and cons between the Arduino and Raspberry Pi. The Arduino has the added complication and cost of an Ethernet shield whereas this comes standard with the Pi. However, the Achilles heel of the Pi can be its SD card which may be corrupted if the Pi does anything than an orderly shutdown. The Arduino does not have this problem Also, building the Pi solution, whilst not difficult, does require a little more knowledge and expertise. Knowing your way around Unix does help when it comes to troubleshooting (and in the construction of our Pi-based time server there was a fair bit of trouble shooting necessary).

The Hardware:

Raspberry Pi GPS Stratum Time Server

he basic hardware list is as follows:

  • Raspberry Pi Model 2B
  • Adafruit Ultimate GPS HAT
  • SD card (we used a 32GB card, but this is overkill)
  • Case
  • 5v Power supply

The Adafruit Ultimate GPS HAT provides a real time clock with battery back-up. It has its own internal patch antenna and a u.FL connector for external active antenna. An antenna is recommended by Adafruit for internal use but so far we have found it to be unnecessary. A flashing on board LED confirms a GS fix.

Building the NTP Server

Ideally we would like this to have been a solderless plug-and-play project but unfortunately the Adafruit Ultimate GPS Hat is supplied without the GPIO header connector pins attached. Keen eyesight and a fine tipped soldering iron rather than a high degree of skill are key to success. Once the pins are soldered the GPS HAT slots onto the Pi Computer without the need for any additional wiring.

To install the Raspbian Stretch operating system, the image has to be downloaded in zip format from the Raspberry Pi Foundation website https://www.raspberrypi.org/downloads/ onto a PC. The GUI desktop is not really needed for a server application and therefore it is sufficient to download Raspbian Stretch Lite.

Once unzipped the Operating System image file is copied onto the SD card using an application such as Etcher https://www.balena.io/etcher/. Your PCs wil need an SD card slot and you will also need a micro-SD adapter. Thankfully micro-SD cards are usually sold with an adaptor. USB SD card interfaces are also available at a very reasonable cost if your PC is without an SD card slot.

Once the SD card is loaded it can be inserted into the SD slot on the PI and the Pi should then boot. You will need an HDMI cable, monitor and a USB keyboard / mouse just for the purpose of setting up but once setup is completed the Pi will run without these.

The steps to configure the Pi to work as a Stratum 1 NTP server are described clearly in a report by the South Florida Amateur Astronomers Association which is available on the “Super Library of Solutions” web site https://www.slsmk.com/how-to-setup-a-gps-pps-ntp-time-server-on-raspberry-pi/. This guide is detailed enough and so we have not replicated the steps here.

Although the instructions are easy to follow, we encountered a few inevitable problems. These were not difficult to overcome but knowing your way around Unix comes in handy. Being able to find system log files and set permissions on folders are essential skills. In particular we found that GPS logging was not happening due to default permissions on the /var/logs directory. The standard Pi editors (vi and nano) take a bit of getting used to.

It is useful to build in a back door into the operating system using telnet which can be used to connect from any PC on your network should any troubleshooting be necessary. We will also need this from time to time to shut down the Pi. To install telnet run “sudo apt-get install telnetd” at the command interface (note that unlike Microsoft Windows Unix commands and file names are case sensitive). More secure options are available, but at the very least ensure that you have a strong password.

Building an Enclosure

Why build when you can buy cheaply. There are many good cases for the Pi available from Amazon. Better still, may of these will accommodate the Pi and the Adafruit GPS hat. These off-the-shelf cases will ensure that all of the Pi connectors are accessible, but at the expense of exposure to the environment. Different Pi models have different connector layouts and so it is important to obtain the correct case.

Our case hides the GPS fix LED but there is a neat trick to make it visible. RS components sells “LED Light Pipes” which “transport” light from a board-mounted LED to the point where the light is required. These come in various shapes and sizes and will push fit into a hole drilled in the case over the LED.

Raspberry Pi Enclosure

Evaluating Performance

We are still evaluating performance but so far are seeing sub-millisecond jitter even indoors and without an external aerial. This about as good as it gets with NTP and so is a pleasing result. It is early days and we will be monitoring its performance over the coming weeks

Pi or Arduino?

Both are excellent solutions. The Ardurino is perhaps a better solution for someone who is less confident with working with Unix and will put up with power loss without risk of corrupting the SD card. On price wise there is little between them considering that the Pi also requires a micro SD card.

One advantage of the Pi is that it is a more flexible platform, can run other applications simultaneously and can be configured to provide detailed time synchronization logs. Various GPS monitoring tools are available such as gpsmon (below).

Whatever solution you choose, you will find a wealth of information on the internet and plenty of enthusiastic fans of the Arduino and Pi willing to provide help and advice.

Raspberry Pi GPS module in command line