Example Program Drafts

cancel
Showing results for 
Search instead for 
Did you mean: 

Installing and Configuring NTP on NI Linux Real-Time Devices

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:

  1. Ensure your NI Linux Real-Time device is connected to a network with internet access.
  2. Follow the instructions for accessing the Shell on a NI Linux Real-Time device found here.
  3. Once logged into your NI Linux Real-Time device, you will need to perform the following steps to enable a suitable third-party software installation repository:


Installing NTP on NI Linux Real-Time:

  1. Issue the command: opkg flag ok libc6 to confirm that it is suitable for the libc6 package to be updated on the NI Linux Real-Time system.  This is necessary because NTP requires a newer version to function properly.  Note: This is not supported and may cause other components of the NI Linux Real-Time system to function improperly.
  2. Issue the command: opkg install ntp ntp-tickadj to install NTP on the NI Linux Real-Time system. 
  3. Issue the command: vi /etc/ntp.conf to edit the NTP configuration file with the "vi" text editor.
  4. Modify the settings in the NTP configuration file as needed.  Many guides are available, but a basic ntp.conf file may look similar to the following:
    • # 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

  5. Save and exit the "vi" text editor using the :wq command.
  6. Restart the NI Linux Real-Time system.  NTP should now be running as a background process to synchronize time with your chosen NTP server.

Setting up NTP on NI Linux Real-Time (Real-Time Module 14.0 or newer)

  1. Follow the instructions for accessing the Shell on a NI Linux Real-Time device found here.

Installing NTP on NI Linux Real-Time:

  1. Issue the command: opkg install ntp ntp-tickadj to install NTP on the NI Linux Real-Time system. 
  2. Issue the command: vi /etc/ntp.conf to edit the NTP configuration file with the "vi" text editor.
  3. Modify the settings in the NTP configuration file as needed.  Many guides are available, but a basic ntp.conf file may look similar to the following:
    • # 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
  4. Save and exit the "vi" text editor using the :wq command.
  5. Restart the NI Linux Real-Time system.  NTP should now be running as a background process to synchronize time with your chosen NTP server.

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

| Zach J. | Systems Engineer, HIL and Test Cells | National Instruments |
Comments
Active Participant A.Rohde
Active Participant

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"

Member phell
Member

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

Active Participant Mads
Active Participant

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.


MTO
Check out ClampOn CAN Monitor on the LabVIEW Tools Network.
Member metux
Member

General notes on clocks and time measurement (yes, especially important for RT):

http://forums.ni.com/t5/NI-Linux-Real-Time-Discussions/Permissions-Setting-date-time-with-system-exe...

Linux Embedded / Kernel Hacker / BSP / Driver development / Systems engineering
Active Participant Lily1979
Active Participant

Hi,

I did the same, but it does't work.

 

Lily

Active Participant mtitoo
Active Participant
Active Participant mtitoo
Active Participant

also if  

6) /usr/sbin/update-rc.d -f callbootntp default 99 0   change it to defaults ('s' at the end)

Member MPCC
Member

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/
Member MPCC
Member

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?

 

Member MPCC
Member

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.

Active Participant kosist90
Active Participant

Detailed and helpful article, but I'd like to add the following:

  • Link to help document for vi editor is broken (maybe it was pointing to this page - https://www.cs.colostate.edu/helpdocs/vi.html?)
  • It would be nice to add to this description example of real time server, like time.nist.gov - and show, how final configuration file could look like
  • If one can't execute command opkg update and receives an error that "download.ni.com" is bad address - then check DNS server configuration on cRIO, it should not be default; you must to set up it.
  • Check NTP synchronization state you could by executing command ntpq -p.

Thank you very much,

 

Sincerely, kosist90.

Check one more article about malleable VIs and class adaptation!

Member Drew_G
Member

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)?

 

Active Participant kosist90
Active Participant

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

Contributors