In unicast mode, the SNTP Client local time, nx_sntp_client_local_ntp_time (in NX_SNTP_CLIENT control block), may not be incremented at runtime. The first packet received from the SNTP Server is successfully applied to the local time because the SNTP Client does not check for a maximum adjustment to make. This is because the SNTP Client local time is not set yet. However, on subsequent updates from the SNTP Client, time update is compared to a maximum allowed adjustment to make, and the local time will fail to be updated if the time difference between the Server update time differs from the local time by greater than the maximum adjustment.
The Maximum time adjustment allowed to local clock time(milliseconds) property defines the largest allowed time adjustment that the SNTP Client will allow the local time to be changed by. The error occurs if it is greater than the value set for the Starting poll interval for unicast update request (seconds) property. The Starting poll interval is the interval at which the SNTP Client polls the SNTP Server for SNTP Clients in unicast mode.
Further, using the default values for SNTP Client will also result in an error and failure to update the local time on updates after the first SNTP packet is received. This is because the default value for Maximum time adjustment (180 seconds) is less than the Starting poll interval (3600 seconds). .
There are two ways to get around this problem. One involves adding some source code in the user application and the other modifying the SNTP Client properties.
Source code: Create a thread to update the local time periodically. This will keep the local time reasonably close to the server time. Start this thread after the SNTP Client receives the first time update or else after the application sets the local time (optional) using the nx_sntp_client_set_local_time API. A simple example follows:
status = nx_sntp_client_get_local_time(&g_sntp_client0, &seconds, &milliseconds, buffer);
/* Wait for a second (100 ticks on most processors) */
tx_thread_sleep(1 * NX_IP_PERIODIC_RATE);
if (status == NX_SUCCESS)
seconds += 1;
status = nx_sntp_client_set_local_time(&demo_client, seconds, 0);
Property settings: Set the Maximum time adjustment to a multiple of (or greater than) the Starting poll interval (or anticipated broadcast intervals if in broadcast mode). Remember that the Maximum time adjustment is in milliseconds and the Starting poll interval is in seconds.
The reason for having a Maximum time adjustment is to guard against rogue or corrupted SNTP time updates that could set the local time off catastrophically.