Synchronize Linux Real Time Targets with Network Time Protocol (NTP) Server

Updated Mar 28, 2023

Environment

Hardware

  • CompactRIO Controller
  • PXI Controller

Operating System

  • LabVIEW Real-Time (NI Linux Real-Time)

This article details how to set up your Linux Real-Time Device (e.g. CompactRIO or PXI) to synchronize with a Network Time Protocol (NTP) Server.

To use NTP on a Linux Real-Time target, you will need to install and configure the NTP software on the target using a secure shell (SSH) session to the target. These instructions should apply to all Linux Real-Time targets, but if you are using a TSN-enabled target, such as a cRIO-904x or cRIO-905x, please read the note in the Additional Information section below.
  1. Make sure that the Linux Real-Time target is connected to the internet. A simple way to do this is to connect both the host PC and the target to a network switch that is connected to the internet.
  2. Open an SSH session to the Linux Real-Time target using a terminal program, such as PuTTY.
  3. Enter the username and password when prompted to log into the target.
  4. Once the SSH session is open to the Linux Real-Time target, enter the following command lines to install the NTP software:
    • opkg update
    • opkg install ntp ntp-tickadj ntp-utils
  5. The NTP software should now be installed and running in the background. If the above commands fails to update or install, make sure that the device is connected to the internet.
  6. You now need to setup the NTP configuration file to point to the NTP server of your choice. You can use an NTP server on your local network or use a publicly available NTP server. This example will show how to connect to the time.natinst.gov server.
    1. Open a new SSH session to the target if your session is no longer open.
    2. Run the following command to open the NTP configuration file:
      • vi /etc/ntp.conf
  7. The ntp.conf file should now be open in the Linux vi text editor.
  8. Press i to enter edit mode.
  9. Move the cursor with keyboard arrows. Add a line with server name in the format server <server URL or IP address>. You can add multiple servers in this file by placing each on their own line. If you need additional help configuring /etc/ntp.conf, there are many guides available on the internet.
  10. The file should now look like this:
  1. Exit the edit mode of the file by pressing the ESC key.
  2. Save and exit the NTP configuration file by entering:
    • :wq
  3.  Reboot the Linux Real-Time target and the time server. Your target should start synchronizing to the server you specified in the configuration file. Please be aware that NTP will adjust the time slowly, so it may take some time for the skew between the target system time and the NTP server time to be minimized.
  4. You can test the connection to the NTP server by running the following command to query the server:
    • ntpq -p

Additional Information

  • This solution should work on Linux Real Time Targets with Real Time module 14.0 or newer. For this solution to work on Real Time module 13.1 and older, you need to configure third party installation sources as mentioned in Installing and Configuring NTP on NI Linux Real-Time Devices community post.
  • The configuration file works on the OS level, thus the NTP server setup will be included in the RT image, should it be copied with the Replication and Deployment (RAD) Utility .
  • To use NTP with TSN-enabled targets, such as the cRIO-904x and 905x, the Linux OS time needs to be desynchronized with the network time. Otherwise, time will be driven from two sources and synchronization quality will be poor or unusable. NI-Sync 20.1 is required to desynchronize Linux OS time from network time. For more information and instructions on how to turn off the synchronization, follow the instructions in this documentation.