I have an embedded system which synchronizes UTC locally using NTP. One of the clients in the system acts as time reference for the other clients. I guess you could think of it as stratum 0. A program on this "NTP server" may get a message to set time from one of many potential time sources, such as GPS system or somebody setting a new time through the UI. New time does not come as an actual NTP message on NTP port 123.

I've been searching for a while how to set the ntpd time without success. I'm thinking a popen() doing something-something should do the trick, but the internet seems all focused on how to adjust time to external server, not configuring a local system.

How do I set ntpd server time without referencing an external NTP server?

As an example use case, the time source may be one of these: docs.novatel.com/oem7/Content/Home.htm (a GNSS reciever). This is just one possible configuration. Other customers use their own separate time sources. It does not include an NTP server, so I would have to implement one from scratch.

  • @PhilipCouling Senior officers says it is the best way to go, and since I'm new to the project it is best to trust their decision. Time is embedded in messages from this: docs.novatel.com/oem7/Content/Home.htm It does not include an NTP server, so I would have to implement one from scratch. Which is sort of what I'm doing, I guess? – Andreas Jun 24 at 10:32
  • @PhilipCouling Also Novatel is just one possible configuration. Other customers use their own separate time sources. Sometimes entered manually through the UI. – Andreas Jun 24 at 10:34
  • It is a weird idea indeed. In my (quite long) experience in IT I have never seen a business setting up their own stratum 0 NTP server... – dr01 Jun 24 at 10:38
  • @dr01 Currently reading this: serverfault.com/questions/153206/… apparently I'm not the only one trying to set up a "local" NTP server. (But the post does not tell how to calibrate the master so it is not the same I think…) – Andreas Jun 24 at 10:46
  • @Andreas Just something to be aware of. GPS time is not the same as UTC – Philip Couling Jun 24 at 10:49

Time is a much more complicated topic than many people realize. While it may appear that all you need to do is "set the ntpd time", there's actually a lot more to consider.

A really blind (bad) answer to your question might be to simply set the system time using clock on the commandline or stime from a program. This would work because NTP doesn't store it's own internal clock. But doing this may not produce the results you actually want.

NTP not only sets the current system time and hands it out to clients, it also tracks errors in the clock allowing it to make adjustments in between polling another time source. Simply setting the current time won't inform NTP of the error and thus doesn't update the "frequency" used by NTP to make adjustments to the system clock.

If your only source for the real time is someone setting the system time may be your only option.

If you wish to use a GPS as a time source for an ntpd server, then the correct term is that you are trying to configure ntpd as a stratum 1 server.

Having done some reading on the matter it seems that ntpd does have a built-in way to talk to hardware clocks including GPS. It's configured using the dummy address range There's an example of this here:

If this too isn't available for you because the time device isn't actually attached to the NTP server box, then you may be able to write your own kernel module to simulate a hardware clock based on the incoming packets.

But your best option by far is to use the drivers others have built for this purpose. If at all possible you should attach your GNSS receiver to a box actually running ntpd to allow ntpd to get the time automatically whenever it wants.

  • Any thoughts about adjtime(), adjtimex() or ntp_adjtime()? – Andreas Jun 24 at 14:19
  • These are alternatives to stime(). adjtime lets you add or subtract an offset rather than specifying an absolute time. adjtimex and ntp_adjtime both let you set a number of additional parameters inside the kernel (including frequency, max error, etc.). Calculating these parameters yourself rather than getting ntpd to do it for you is very complicated and a very long way outside my knowledge. – Philip Couling Jun 24 at 15:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.