What Time is it?

My computers now know what time it is, to the millisecond, without using the Internet.

I put together a stratum-1 ntp time server, based on a Raspberry Pi 3 model B with an Adafruit Ultimate GPS Hat.  I put the whole thing into a C4 Labs Zebra GPS HAT Case, made of layers of shiny acrylic.  The case is entirely too beautiful, considering that I’m keeping this unit on a shelf in my garage, high up and out of sight, but it provides good dust protection, and the acrylic top is not only transparent to visible light, but it also allows the GPS signals to be received with the GPS unit’s built-in patch antenna, even indoors under my garage roof (the thinnest roof in my house, one layer of wood plus some composite shingles).

Stratum-1 Time Server

Why?  Because I can, mostly.  No, this has nothing to do with my earlier post on the possible demise of WWV/WWVB.   I do have a use for accurate computer time coming in a future post.  But before this, I was using ntp to get time accurate to a handful of milliseconds, usually.  Now, my accuracy and stability has improved by a few of orders of magnitude, with errors measured in single-digit microsecond (millionths of a second) levels. That’s far more accurate than I need for any practical reason, but it’s nice to have, anyway.  It was amazingly simple and cheap to achieve this level of accuracy.

How did I do it?

I purchased a Raspberry Pi 3 model B, an Adafruit  Ultimate GPS Hat, and the case.  The GPS hat required a bit of simple through-hole soldering to attach the header to the board.  The rest went together very simply.  Once I got it all together, I powered up the Raspberry Pi even before I placed an SD card into the Pi, and I left it outdoors, so it could “see” the satellites and obtain a GPS lock.

As I left the GPS outside getting locked onto the satellites, I downloaded the latest Raspbian Stretch image, and burned it onto an SD card.  I changed the boot directory of the SD card image, and put a file named “SSH” there (contents don’t matter, mine was zero bytes long).  This allows me to get into the Pi using the “ssh” program. Then I disconnected power from the Raspberry Pi, inserted the SD card, and booted up.

I went to my router’s status page to find out the address of my new Pi, and used ssh to connect to it, using the default user “pi” and default password, “raspberry”.  I immediately changed the password, expanded the SD card image to fill the entire disk, set a static IP address, set a hostname, updated the software using “aptitude update” and “aptitude upgrade”, installed emacs (my favorite text editor), and basically got myself a basic bare-bones headless Raspberry Pi on my home network.

Once I did that, I went through the basic checkout and setup of the Adafruit GPS hat, as listed here:  https://learn.adafruit.com/adafruit-ultimate-gps-hat-for-raspberry-pi/

Finally, I set up the Pi with GPS hat as a Stratum-1 time server, using the following instructions and script, by the legendary hacker Eric S. Raymond:  https://www.ntpsec.org/white-papers/stratum-1-microserver-howto/

There is a lot of detail in that page, but the “Clockmaker” script handled the dirty work very effectively.

How well does it work?  It stays pretty accurate, but if you watch for a while, you may notice some fluctuations as the computer’s quartz oscillator speeds up and slows down with the daily temperature fluctuations, and the ntp software steers the clock to correct as best it can.  You can see the current offset and jitter of my ntp server right here!

2 thoughts on “What Time is it?”

  1. I have recently written a program for the Pi to transmit time radio signals such as WWVB. Originally to get my DCF77 watch working (which currently lives a long way away from the sender in Frankfurt), but then I also implemented WWVB, JJY and MSF.

    https://github.com/hzeller/txtempus

    So, this might be the next hardware extension for this Pi in the case of a WWVB shutdown…

    1. Fantastic work, Henner! I actually read about your program on Hackaday this morning, at https://hackaday.com/2018/09/10/no-signal-for-your-radio-controlled-watch-just-make-your-own-transmitter/

      I knew that my idea of mimicking the radio transmissions from WWVB was obvious enough that many people must have thought of it. I’m very pleased to find out that you not only thought of it, but actually did the work to put it into functioning code.

      WWVB is still putting out a strong working signal here, and for the sake of my neighbors, I don’t want to interfere with it, and won’t transmit on its frequency. But I do have a watch that can sync to DCF77, so I might try a test to make sure I can get the code working in that mode. If WWVB ever does go away, at least now I know what my plan will be to keep all the clocks in my house synchronized.

      Thanks for sharing your work! And thanks for submitting a comment here.

Comments are closed.