Overview
Network Time Protocol (NTP) is a daemon that can be run on a GNU/Linux device to contact servers running a NTP server for time synchronization and adjustment. It is a viable option for keeping NI Linux Real-Time devices time-synchronized with a server of your choice for accurate time-stamping of data and other time-based functionality. This tutorial will equip users with the knowledge to install and configure NTP on a NI Linux Real-Time device. It will show how to synchronize to www.ntp.org, a popular NTP server in the GNU/Linux community.
Setting up NTP on NI Linux Real-Time (Real-Time Module 13.1 or older)
Configuring Third-Party Installation Sources On NI Linux Real-Time:
# src/gc angstrom-base http://us.feeds.angstrom-distribution.org/feeds/next/ipk/eglibc/armv7a/base/
Modify this line to be the following:
src/gc angstrom-base http://feeds.angstrom-distribution.org/feeds/next/ipk/eglibc/armv7a/base/
Note: The "vi" text editor is a difficult editor to use for first-time users. Please refer to a help document for working with it.
Save and exit the "vi" text editor with the :wq command.
After saving, you will return to the NI Linux Real-Time shell. Issue the command: opkg update to update the local package database.
Installing NTP on NI Linux Real-Time:
# This is the most basic ntp configuration file
# The driftfile must remain in a place specific to this
# machine - it records the machine specific clock error
driftfile /etc/ntp.drift
# This obtains a random server which will be close
# (in IP terms) to the machine. Add other servers
# as required, or change this.
server 0.pool.ntp.org
server 1.pool.ntp.org
server 2.pool.ntp.org
server 3.pool.ntp.org
# Using local hardware clock as fallback
server 127.127.1.0
fudge 127.127.1.0 stratum 14
# Defining a default security setting
restrict default kod nomodify notrap nopeer noquery
Setting up NTP on NI Linux Real-Time (Real-Time Module 14.0 or newer)
Installing NTP on NI Linux Real-Time:
# This is the most basic ntp configuration file
# The driftfile must remain in a place specific to this
# machine - it records the machine specific clock errordriftfile /etc/ntp.drift# This obtains a random server which will be close
# (in IP terms) to the machine. Add other servers
# as required, or change this.
server 0.pool.ntp.org
server 1.pool.ntp.org
server 2.pool.ntp.org
server 3.pool.ntp.org
# Using local hardware clock as fallback
server 127.127.1.0
fudge 127.127.1.0 stratum 14
# Defining a default security setting
restrict default kod nomodify notrap nopeer noquery
Requirements
Software
NI Real-Time Module 13.0 or newer
NI-RIO 13.0 or newer
NI Measurement and Automation Explorer
Hardware
NI Real-Time target utilizing NI Linux Real-Time OS
NIコミュニティのサンプルコード交換のサンプルコードは、MIT Licenseによりライセンス供与されています。
Tip: If you run into the error ntp and ntp-tickadj unknown package / cannot install package on a fresh system for 2014 after running step (1) it might be nessasary to run the command "opkg update"
I got the myRIO to sync the time with NTP server at boot.
The following was done using PuTTY to connect to the myRIO.
1) opkg update
2) opkg install ntp ntp-tickadj ntp-utils
3) vi /etc/ntp.conf
driftfile /etc/ntp.drift
server time.nist.gov
restrict default kod nomodify notrap nopeer noquery
tos maxdist 16
4) vi /etc/init.d/callbootntp
#!/bin/bash
/etc/init.d/ntpd stop
until ping -q -c3 8.8.8.8; do
echo "Waiting for network..."
done
ntpd -gq
/etc/init.d/ntpd start
5) chmod +x /etc/init.d/callbootntp
chmod 777 /etc/init.d/callbootntp
6) /usr/sbin/update-rc.d -f callbootntp default 99 0
Best regards
phell
I seem to have ntpd running after following this guide (thanks), but how can I check the status of the time sync?
I have found lots of sites on the topic, but they all refer to ntpq for this, and ntpq does not seem to be installed(?).
Edit - found out from Phells comment here...I had not installed ntp-utils.
General notes on clocks and time measurement (yes, especially important for RT):
Hi,
I did the same, but it does't work.
Lily
For RT 2017, you need to follow this.
opkg install fix- https://forums.ni.com/t5/NI-Linux-Real-Time-Discussions/LabVIEW-2017-RIO-17-0-PSA-Feed-Adjustment-fo...
also if
6) /usr/sbin/update-rc.d -f callbootntp default 99 0 change it to defaults ('s' at the end)
I found what appears to be a typo or possibly a difference in targets.
This will open a file in the "vi" text editor. After opening the file, you will see a line that contains the following text: # src/gc angstrom-base http://us.feeds.angstrom-distribution.org/feeds/next/ipk/eglibc/armv7a/base/ Modify this line to be the following: src/gc angstrom-base http://feeds.angstrom-distribution.org/feeds/next/ipk/eglibc/armv7a/base/
src/gc should be src/gz
I also didn't have an initial line on my target and I needed to change to core2-64 because I'm using a cRIO with an Intel proc and not an Arm.
The resulting path that worked in my angstrom-base-feed.conf file is this:
src/gz angstrom-base http://feeds.angstrom-distribution.org/feeds/next/ipk/glibc/core2-64/base/
It also appears that one of the packages is broken. I don't have an init.d/ntp or /ntpd file on my system.
Anyone mess with this recently?
We also found that having NI Sync installed can cause additional problems. In our case, it wasn't configured to any time sync streams but it was causing an unknown offset. I recommend uninstalling NI Sync from the target if you are using NTP.
Detailed and helpful article, but I'd like to add the following:
Thank you very much,
Sincerely, kosist90.
Check one more article about malleable VIs and class adaptation!
Couple of things:
1. How do I work out what version of Linux Real Time Module I'm using. I'm using a cRIO 9064. According to MAX and the web interface the operating system is: NI Linux Real-Time ARMv7-A 3.2.35-rt52-2.10.0f0?
2. Is there anyway to update the opkg without the internet (my cRIO lives behind our corporate firewall)?
Hello Drew_G,
1. Yes, you could see it in NI MAX - or you'd like to check version of Linux core? Then you'll need to connect to cRIO via putty, to use terminal, and try to execute some of the Linux commands, let's say, from here - https://www.cyberciti.biz/faq/command-to-show-linux-version/.
2. I guess you can't update it without the internet. But, you could download packages which you'd like to install (by this link https://forums.ni.com/t5/NI-Linux-Real-Time-Discussions/LabVIEW-2017-RIO-17-0-PSA-Feed-Adjustment-fo... are mentioned some ftp repositaries from it, also you'll see addresses in terminal while try to install packages). After downloading of packages on your PC, just put them on cRIO drive, and install them via terminal commands.
The only issue what could be in this case - some packages require dependencies, so you'll need to download all the dependencies before the installation, and it could be a challenge.
Hope, that it would help,
Sincerely, kosist90
A couple notes:
I found it necessary to add in "restrict ::1" to the ntp.conf file.
Also I disabled NI-Sync Linux OS Time Synchronization in order to leave the driver installed and not fight when other packages install it as a dependency:
/usr/lib/x86_64-linux-gnu/ni-timesync/configgen --tsmJsonFile /var/lib/ni-timesync/tsm.json --setTKPluginConfig phc2sysEnable false
Below is a script I put together to do all of this using a package and SystemLink. In the package I manually added the dependencies and SystemLink installed them automatically (I like nano so I included that too). "defaults" is corrected in the script as noted above in the comments too. Just create, save, and add the script (with a .sh exension) to your project, then add it as a custom action in the Advanced section, post-install.
#!/bin/bash
rm /etc/ntp.conf
cat <<EOF >/etc/ntp.conf
driftfile /etc/ntp.drift
server time.nist.gov
restrict default kod nomodify notrap nopeer noquery
tos maxdist 16
restrict ::1
EOF
cat <<EOF >/etc/init.d/callbootntp
#!/bin/bash
/etc/init.d/ntpd stop
until ping -q -c3 8.8.8.8; do
echo "Waiting for network..."
done
ntpd -gq
/etc/init.d/ntpd start
EOF
chmod +x /etc/init.d/callbootntp
chmod 777 /etc/init.d/callbootntp
/usr/sbin/update-rc.d -f callbootntp defaults 99 0
/usr/lib/x86_64-linux-gnu/ni-timesync/configgen --tsmJsonFile /var/lib/ni-timesync/tsm.json --setTKPluginConfig phc2sysEnable false
/etc/init.d/callbootntp