Saturday, October 14, 2017

Paradise ponders: NTP adventures and old friends edition...

Paradise ponders: NTP adventures and old friends edition...  Debbie and I are both feeling a bit better today, but wimpy as heck.  Debbie's fever seems to have broken last night, and her voice is back.  I can tell she's feeling much better because she did the cat chores today, much to the delight of our feline contingent!

Last night our forecast called for snow, but we didn't get any.  We did get just a bit of a kind of fine-grained hail (photo at right), along with (I'm guessing) about a tenth inch of rain before the temperature dipped below freezing.

I got a real surprise yesterday: a colleague and friend, Ron N., from over ten years ago contacted me out of the blue.  I'm not quite sure how he located me, but he left a comment on my blog and then the two of us got together on email.  It's been interesting to catch up with him, though obviously we've got a lot more to do of that!  He tells me he'd like to come up here to visit sometime next year, which would be really fun...

Most of yesterday and this morning I've been consumed with trying to fix a problem with my NTP project: configuring the GPS to be in stationary mode, wherein it assumes the antenna is not moving.  This translates into more accurate time measurement (more on that below).  The problem I started out with was that the directions I was following for setting up my NTP server included a link to a program that just plain didn't work.  The specific problem was that the program hung when it tried to open the serial port for reading and writing.  I troubleshot it for several hours, but finally gave up because I didn't understand how it could ever work in the first place.

So I decided to write my own program instead.  That meant that I had to understand the rather complex communications protocol that the GPS chip manufacturer uses for the functions I needed, as they're implemented in a proprietary “UBX” protocol.  Then I had to dust off my (extremely) rusty C programming skills – the last time I wrote a complete C program was around 1983 (seriously!).  I've done lots of work since then in C++ and Java, but not in C – and if you're a C programmer, you know it's changed a lot since the '80s!  Finally, I had to learn something completely new to me: serial port programming on Linux. I did the development work on a Raspberry Pi, where the only development tools I had was gcc (the Gnu compiler) and nano (a text editor).  Somehow I managed to get my little program working, which, I have to tell you, was a very satisfying thing indeed – validation, of a sort, that I might have more than two or three little grey cells still working.  If you're geekly enough to be interested, here's my satisfying little program.

A couple of my readers wanted to know what the heck a GPS receiver has to do with keeping good time on my network.  If you don't know anything about how GPS actually works, I can imagine this is really quite puzzling!  The first thing you need to know is that each GPS satellite has an incredibly accurate atomic clock in it.  There are over 50 of these satellites in four separate systems (the US, Russia, China, and Europe each have their own independent system), so there are a lot of these awesomely precise clocks flying around.  The GPS receiver I'm using can listen to all four systems, and at any given moment it likely has 10 or 12 satellites “in view” (meaning that it can hear their signals). Once my receiver can “hear” at least four satellites, it can tell the time very precisely indeed.  In fact, its accuracy is very nearly that of an atomic clock, as if I owned one of these (very expensive!) things.  All that with a $39 GPS receiver and a $29 antenna!

With the success of my little program, I've now got my stratum 1 NTP server up and running.  It's working great, passing all the tests I can throw at it.  Now the only things left to do are to mount the antenna on my barn's roof (that might be a challenge!) and to make a case for the Raspberry Pi.  I've already got it in use on my network, though – even with the antenna just pointed out of a window in my office, it's much more accurate than any NTP server I can access over the Internet...

1 comment:

  1. There goes that tenacity at work again!!! :) Awesome to hear you got that sucker up and going. Now you know its gonna bug you until you do it - get up on that barn and mount the antenna!

    ReplyDelete