This library contains functions for target's local time synchronization using time protocol or simple NTP protocol.
The latest version 1.1.0 can be downloaded via this link.
When using time protocol, you have just to call:
and your target's time is set. Check however the return of this function.
It may return
ERROR if unable to connect to time server.
If you prefer to use SNTP time synchronization, here are the steps to perform. First of all you have to tell the library what are your NTP servers:
You can add up to 16 servers (see trim.c if you want make more). From the list of servers you've just specified the NTP client will choose a one that works. An NTP server reports a universal UTC time. You may want to see your local time set on the target. For this you have to apply a time shift to the UTC value. Pay attention that this shift may change when switching summer/winter time, or changing time zone. You'll have to do all these adjustments manually.
This will add 2 hours and 0 minutes to the UTC in order to obtain your local time.
When you're done with all these preliminaries, perform a final call:
This function will perform an NTP transaction with one of the servers (with a first one that responds, actually). On success function returns OK and your local time is set (and previously specified time shift applied).
You may also want to perform time synchronization regularly. For this, instead of calling sntpAdjust() you must call:
This function launches a synchronization task that will perform SNTP synchronization every 60 (argument value) seconds. The task created has a name 'sntpTask'.
Project Web Hosted by