User Tools

Site Tools


Sidebar

c_niagara:programming:functionguides:ntp
Approved 2022/04/08 08:07 by mk (version: 2)

NTP Time Sync

Time sync is pretty important, because the Niagara controllers is pretty bad at keeping the time!

There is 2 ways to do it, NTP and NiagaraNetworkJobPrototype from the provisioningNiagara palette.

NiagaraNetworkJobPrototype

I Won't go into too many details on this one, just yet. But in your Niagara folder you can add NiagaraNetworkJobPrototype function from the provisioningNiagara palette, with a trigger schedule, add the job “time sync” and add your controllers.

NTP

NTP is the “correct time sync” method, and basically what it does, is asking someone more reliable, what the time is, and then slowly correct the time until it matches.

A reliable source is selected using Stratum levels.

Setting up NTP server in Windows, can be done in 2 ways. You can try, and have Windows use the internal service (See quick links), but doing this is pretty difficult and I haven't made it work yet.

Another method is installing the “official NTP server software” compiled by Meinberg.

Install it with all available selections.

This guide have aditial information and my guide is based on this site.

After installation go to the configuration file at C:\Program Files (x86)\NTP\etc\ntp.conf and edit it, so you remove any restrictions (or at least allow your own controllers).

Conf file

My Conf file is like this for server in a closed network.

# NTP Network Time Protocol 
# **** ATTENTION ****: *You have to restart the NTP service when you change this file to activate the changes* 
# PLEASE CHECK THIS FILE CAREFULLY AND MODIFY IT IF REQUIRED 
# Configuration File created by Windows Binary Distribution Installer Rev.: 1.27  mbg
# please check http://www.ntp.org for additional documentation and background information
# restrict access to avoid abuse of NTP for traffic amplification attacks 
# see http://news.meinberg.de/244 for details  
### RESTRICTIONS REMOVED ###
#### restrict default noquery nopeer nomodify notrap  
#### restrict -6 default noquery nopeer nomodify notrap  
 
# allow status queries and everything else from localhost 
### RESTRICTIONS REMOVED ###
###restrict 127.0.0.1 
###restrict -6 ::1 

# if you need to allow access from a remote host, you can add lines like this: 
# restrict <IP OF REMOTE HOST> 

# Use drift file driftfile "C:\Program Files (x86)\NTP\etc\ntp.drift"

# your local system clock, should be used as a backup
# (this is only useful if you need to distribute time no matter how good or bad it is)
server 127.127.1.0
# but it operates at a high stratum level to let the clients know and force them to
# use any other timesource they may have.
fudge 127.127.1.0 stratum 12 
# Use a NTP server from the ntp pool project (see http://www.pool.ntp.org)
# Please note that you need at least four different servers to be at least protected against
# one falseticker. If you only rely on internet time, it is highly recommended to add
# additional servers here. 
# The 'iburst' keyword speeds up initial synchronization, please check the documentation for more details!
server 0.dk.pool.ntp.org iburst minpoll 6 maxpoll 7
server 1.dk.pool.ntp.org iburst minpoll 6 maxpoll 7
server 2.dk.pool.ntp.org iburst minpoll 6 maxpoll 7
server 1.de.pool.ntp.org iburst minpoll 6 maxpoll 7
server 0.uk.pool.ntp.org iburst minpoll 6 maxpoll 7

# End of generated ntp.conf --- Please edit this to suite your needs

After this, run windows services as an Administrator and make sure the service “Network Time Protocol daemon” is set to auto start and start it (Or reboot).

Using the NTP Query tool we got with the installation, we can now ask our local time server if it is working with the command ntpq -p 127.0.0.1 run from command prompt.

Correct working time server output

And a controller will respond like this

Controller ntpq output

Setting up NTP in controller

I am unsure is NtpPlatformServiceQnx is already added by default at /Services/PlatformServices/NtpPlatformServiceQnx or if it's from a palette. When you have it, enable it, and put in settings as shown in the image below. After you get it to work, you could disable the “Generate NTp Statistics” because it keeps adding to the logfile, but it's a good way to see if it's working.

Controller NTP service

Debugging NTP in controller

If you use remote spy on the NTP service in a controller, you should see output logs like the ones below

NTP Warning

It has been possible to use NTP servers to do DDOS attacks and therefor if your server is public available, you should get restriction working in the NTP conf file.

c_niagara/programming/functionguides/ntp.txt · Last modified: 2022/04/08 08:07 by mk