7

I have an Embedded Board where the distribution on it is a custom Linux Distribution based on Yocto.

I have added ntp and via ntpd I will sync time with the common ntp pools either via UMTS 3G dongle or Ethernet.

This board along with some ESP32 PoE board by Olimex are connected via an Unmanaged Switch.

Purpose

The ESP32 boards have sensors that collect information add a timestamp to them and send it to the InfluxDB running on the main embedded board via Ethernet making it a Wired Sensor Network. These ESP32 boards also have an RTC DS3231 on them so I want them to first get the time from a NTP Server running on this embedded board to sync the RTC and then send information to the InfluxDB.

Questions

  1. How does one create an NTP server on the Embedded Board? Can I add a line in the ntp.conf file that can be used to step up a server with for e.g. NTP server at 192.168.4.11? Using this IP address in my arduino code I can ask for the timestamps

  2. In case of testing, If I somehow setup a NTP server on the Embedded Board, how can I initially test the time coming from it? Is there a command line utility to poll the NTP server and see if the time coming is correct or not on a regular computer?

0

2 Answers 2

4

Precise Description for the Query

Initial NTP time sync

  1. In the Yocto build system under conf/local.conf add ntp recipe as follows:

     IMAGE_INSTALL_append = " ntp"
    
  2. on Target board initially stop the systemd service:

     systemctl stop ntp
    
  3. Assuming board is connected to the internet:

      ntpd -gq
    

    Info: Check time using date

  4. For safe side also sync the Hardware clock to NTP time:

     hwclock -w --localtime
    
  5. Restart the systemd service

     systemctl start ntp
    

Setup a local NTP Server on Embedded Board

  1. Stop the systemd service:

     systemctl stop ntp
    
  2. Edit the /etc/ntp.conf to make the embedded board broadcast the NTP timestamps on port 123. Add the following line:

     # Here the IP Address could that of your board but make sure to use
     # Broadcast address (x.x.x.255) and if you have a larger network
     # select your subnet masks accordingly
     broadcast 192.168.1.255 
    
  3. Restart the systemd service:

    systemctl start ntp
    

Achieving timesync with Sensor Nodes

  1. Assuming one has boards that can be programmed with Arduino; download the NTPClient Arduino Library.

  2. In your Sketch use the NTPClient constructor to connect to your Local NTP server via its IP address

    NTPClient timeServer(ntpUDP, "192.168.1.123", 0, 60000);
    

and obtain the timestamps from the Local NTP Server

References

1

To answer your fist question I'll point at this Ask Ubuntu answer:

https://askubuntu.com/questions/14558/how-do-i-setup-a-local-ntp-server

It's Ubuntu specific but should point you in the right direction for what packages to search for on Yocto.

for the second, ntpdate <ip address of ntp server> can be used to query a ntp server for the date.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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