Network Component
Version 6.6
MDK-Professional Middleware for IP Networking
|
SNTP Client routines deliver precise timing information over an IP network. More...
Functions | |
netStatus | sntp_get_time (const uint8_t *ip_addr, net_sntp_client_cb_t cb_func) |
Determine current time from NTP or SNTP time server. | |
typedef void(* | net_sntp_client_cb_t )(uint32_t utc_time) |
SNTP Client callback function. | |
SNTP Client routines deliver precise timing information over an IP network.
Simple Network Time Protocol (SNTP) is a networking protocol for clock synchronization between computer systems over IP based, variable-latency data networks. SNTP does not require the storage of the state over extended periods of time, so that it is used mostly in memory limited embedded devices and in applications where high accuracy timing is not required.
void(* net_sntp_client_cb_t)(uint32_t utc_time) |
SNTP Client callback function.
[in] | utc_time | UTC time in seconds |
Is the type definition for the SNTP callback function. Users must provide the function.
The function is called by the SNTP client when an NTP message is received from the server. The utc_time argument of the callback function signals the time, specified in UTC (Universal Time Coordinated) in seconds, elapsed since 1.1.1970. A value of 0 reports an error.
Parameter for:
netStatus sntp_get_time | ( | const uint8_t * | ip_addr, |
net_sntp_client_cb_t | cb_func | ||
) |
Determine current time from NTP or SNTP time server.
[in] | ip_addr | IP address of NTP or SNTP server. |
[in] | cb_func | callback function to call, when the session ends. |
In unicast mode, the function sntp_get_time sends a get time request to NTP server.
In broadcast mode, it opens an UDP socket for receiving broadcast NTP messages. You can use broadcast mode, if you have a broadcasting NTP server in your local network.
The argument ip_addr specifies the IP address of a local NTP server. NTP messages that come from the specified NTP server are accepted. Messages that come from a different NTP server are ignored. If ip_addr is 0.0.0.0, then NTP messages from any NTP server are accepted.
If the IP address is not specified (ip_addr is NULL), then the IP address of the NTP Server configured in Net_Config_SNTP_Client.h is used. Broadcast Mode gets also enabled here.
The argument cb_func points to a user-defined callback function called by the SNTP client when an NTP message is received from the server. Refer to net_sntp_client_cb_t.
Code Example