IIoT - SNTP Support

SNTP or Simple Network Time Protocol (SNTP) is an Internet Protocol (IP) used to synchronize the clocks of networks of computers.

This project will go out to a dedicated website that provides the current time in Current UTC time (previously Greenwich Mean Time) and use that to synchronize the P2CDS-622 clock.

For example, if the local time is EST at 7:30am, UTC is 4 hour faster at 11:30am.

Introduction

The library SNTP Service SL contains function blocks for easy implementation of SNTP client and server components on a CODESYS control (SNTP V3, SNTP V4). The function block SNTPGetUTCTime can be used to request the UTC time of a SNTP/NTP server.

The function block SNTPServer can be used to build a simple SNTP server.

Function blocks (FBs) of the SNTP library:

  • SNTPGetUTCTime: FB to request the time of a SNTP server (SNTP client)

  • SNTPServer: FB to send the local server time (SNTP server)

alternate text

Caution

To do this project, the steps outlined in the previous section Preparation have to be completed successfully.

Install IIoT Library

To access the free IIoT Library functions e.g. Web Client functions, oyoune must install the IIoT Single license with the CODESYS Installer.

This license is located on the CODESYS website store at IIoT License

Note

This Library does NOT require any payment to download! Just click on the Download button.

Project

The following project is a modified version of the IIoT Library example located in your install directory. This example should be located at C:Users<username>SNTP Service SL along with an associated Help file.

The SNTP example project can be downloaded in Archive format here- SNTP project.

(1). With CODESYS IDE launched, click File > Project Archive > Extract Archive. Select all options in pop-up. Click “yes” on next pop-ups.

Update everything (including Library’s) to latest revisions. May have to add a Library, e.g. Basic OSCAT.

Caution

It is provided that the provided example URL for accessing hourly time may not always be accessible. If not, pick a URL of your choosing.

Items of Note

  • This project uses a NIST server to obtain the time at NIST Maryland. Defined at https://tf.nist.gov/tf-cgi/servers.cgi.

  • Server time is in UTC time,

  • Error codes obtained by double-clicking on the Function Block SNTPGetUTCTime and inspecting SNTP Service > Enums > ERROR .

  • The above screenshot shows the time difference in milliseconds (ms). We would expect a 4-hour difference from local time. This example, 4.02 hours error.

  • The above screenshot shows a successful (no errors) time access via the green icon under Get server time.