Zephyr API Documentation 4.1.99
A Scalable Open Source RTOS
 4.1.99
All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages

Simple Network Time Protocol API . More...

Data Structures

struct  sntp_time
 Time as returned by SNTP API, fractional seconds since 1 Jan 1970. More...
 
struct  sntp_ctx
 SNTP context. More...
 

Functions

int sntp_init (struct sntp_ctx *ctx, struct sockaddr *addr, socklen_t addr_len)
 Initialize SNTP context.
 
int sntp_query (struct sntp_ctx *ctx, uint32_t timeout, struct sntp_time *ts)
 Perform SNTP query.
 
int sntp_recv_response (struct sntp_ctx *ctx, uint32_t timeout, struct sntp_time *ts)
 Attempt to receive an SNTP response after issuing a query.
 
void sntp_close (struct sntp_ctx *ctx)
 Release SNTP context.
 
int sntp_init_async (struct sntp_ctx *ctx, struct sockaddr *addr, socklen_t addr_len, const struct net_socket_service_desc *service)
 Initialise SNTP context for async operation.
 
int sntp_send_async (struct sntp_ctx *ctx)
 Send the SNTP query.
 
int sntp_read_async (struct net_socket_service_event *event, struct sntp_time *ts)
 Read the result of the SNTP query.
 
void sntp_close_async (const struct net_socket_service_desc *service)
 Release SNTP context.
 
int sntp_simple (const char *server, uint32_t timeout, struct sntp_time *ts)
 Convenience function to query SNTP in one-shot fashion.
 
int sntp_simple_addr (struct sockaddr *addr, socklen_t addr_len, uint32_t timeout, struct sntp_time *ts)
 Convenience function to query SNTP in one-shot fashion using a pre-initialized address struct.
 

Detailed Description

Simple Network Time Protocol API .

Since
1.10
Version
0.8.0

Function Documentation

◆ sntp_close()

void sntp_close ( struct sntp_ctx * ctx)

#include <zephyr/net/sntp.h>

Release SNTP context.

Parameters
ctxAddress of sntp context.

◆ sntp_close_async()

void sntp_close_async ( const struct net_socket_service_desc * service)

#include <zephyr/net/sntp.h>

Release SNTP context.

Parameters
serviceSocket service defined by NET_SOCKET_SERVICE_SYNC_DEFINE

◆ sntp_init()

int sntp_init ( struct sntp_ctx * ctx,
struct sockaddr * addr,
socklen_t addr_len )

#include <zephyr/net/sntp.h>

Initialize SNTP context.

Parameters
ctxAddress of sntp context.
addrIP address of NTP/SNTP server.
addr_lenIP address length of NTP/SNTP server.
Returns
0 if ok, <0 if error.

◆ sntp_init_async()

int sntp_init_async ( struct sntp_ctx * ctx,
struct sockaddr * addr,
socklen_t addr_len,
const struct net_socket_service_desc * service )

#include <zephyr/net/sntp.h>

Initialise SNTP context for async operation.

Asynchronous operation is powered by CONFIG_NET_SOCKETS_SERVICE.

Parameters
ctxAddress of sntp context.
addrIP address of NTP/SNTP server.
addr_lenIP address length of NTP/SNTP server.
serviceSocket service defined by NET_SOCKET_SERVICE_SYNC_DEFINE
Returns
0 if ok, <0 if error.

◆ sntp_query()

int sntp_query ( struct sntp_ctx * ctx,
uint32_t timeout,
struct sntp_time * ts )

#include <zephyr/net/sntp.h>

Perform SNTP query.

Parameters
ctxAddress of sntp context.
timeoutTimeout of waiting for sntp response (in milliseconds).
tsTimestamp including integer and fractional seconds since 1 Jan 1970 (output).
Returns
0 if ok, <0 if error (-ETIMEDOUT if timeout).

◆ sntp_read_async()

int sntp_read_async ( struct net_socket_service_event * event,
struct sntp_time * ts )

#include <zephyr/net/sntp.h>

Read the result of the SNTP query.

Must be called from the callback attached to the net_socket_service_desc context.

Parameters
eventEvent pointer extracted from the service work callback
tsTimestamp including integer and fractional seconds since 1 Jan 1970 (output).
Returns
0 if ok, <0 if error

◆ sntp_recv_response()

int sntp_recv_response ( struct sntp_ctx * ctx,
uint32_t timeout,
struct sntp_time * ts )

#include <zephyr/net/sntp.h>

Attempt to receive an SNTP response after issuing a query.

Parameters
ctxAddress of sntp context.
timeoutTimeout of waiting for sntp response (in milliseconds).
tsTimestamp including integer and fractional seconds since 1 Jan 1970 (output).
Returns
0 if ok, <0 if error (-ETIMEDOUT if timeout).

◆ sntp_send_async()

int sntp_send_async ( struct sntp_ctx * ctx)

#include <zephyr/net/sntp.h>

Send the SNTP query.

Parameters
ctxAddress of sntp context.
Returns
0 if ok, <0 if error.

◆ sntp_simple()

int sntp_simple ( const char * server,
uint32_t timeout,
struct sntp_time * ts )

#include <zephyr/net/sntp.h>

Convenience function to query SNTP in one-shot fashion.

Convenience wrapper which calls getaddrinfo(), sntp_init(), sntp_query(), and sntp_close().

Parameters
serverAddress of server in format addr[:port]
timeoutQuery timeout
tsTimestamp including integer and fractional seconds since 1 Jan 1970 (output).
Returns
0 if ok, <0 if error (-ETIMEDOUT if timeout).

◆ sntp_simple_addr()

int sntp_simple_addr ( struct sockaddr * addr,
socklen_t addr_len,
uint32_t timeout,
struct sntp_time * ts )

#include <zephyr/net/sntp.h>

Convenience function to query SNTP in one-shot fashion using a pre-initialized address struct.

Convenience wrapper which calls sntp_init(), sntp_query() and sntp_close().

Parameters
addrIP address of NTP/SNTP server.
addr_lenIP address length of NTP/SNTP server.
timeoutQuery timeout
tsTimestamp including integer and fractional seconds since 1 Jan 1970 (output).
Returns
0 if ok, <0 if error (-ETIMEDOUT if timeout).