Skip to content
Permalink
Browse files

samples: sntp_client: Switch from sntp_request() to sntp_query()

sntp_request() was deprecated and superceded by sntp_query(), which
provides better time resolution.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
  • Loading branch information...
pfalcon authored and jukkar committed May 10, 2019
1 parent 59eb483 commit 08be81d949c789746bd9ccaf76ddad84daa0915a
Showing with 5 additions and 5 deletions.
  1. +5 −5 samples/net/sockets/sntp_client/src/main.c
@@ -21,7 +21,7 @@ void main(void)
#if defined(CONFIG_NET_IPV6)
struct sockaddr_in6 addr6;
#endif
u64_t epoch_time;
struct sntp_time sntp_time;
int rv;

/* ipv4 */
@@ -38,15 +38,15 @@ void main(void)
}

LOG_INF("Sending SNTP IPv4 request...");
rv = sntp_request(&ctx, K_SECONDS(4), &epoch_time);
rv = sntp_query(&ctx, K_SECONDS(4), &sntp_time);
if (rv < 0) {
LOG_ERR("SNTP IPv4 request failed: %d", rv);
goto end;
}

LOG_INF("status: %d", rv);
LOG_INF("time since Epoch: high word: %u, low word: %u",
(u32_t)(epoch_time >> 32), (u32_t)epoch_time);
(u32_t)(sntp_time.seconds >> 32), (u32_t)sntp_time.seconds);

#if defined(CONFIG_NET_IPV6)
sntp_close(&ctx);
@@ -66,15 +66,15 @@ void main(void)

LOG_INF("Sending SNTP IPv6 request...");
/* With such a timeout, this is expected to fail. */
rv = sntp_request(&ctx, K_NO_WAIT, &epoch_time);
rv = sntp_query(&ctx, K_NO_WAIT, &sntp_time);
if (rv < 0) {
LOG_ERR("SNTP IPv6 request: %d", rv);
goto end;
}

LOG_INF("status: %d", rv);
LOG_INF("time since Epoch: high word: %u, low word: %u",
(u32_t)(epoch_time >> 32), (u32_t)epoch_time);
(u32_t)(sntp_time.seconds >> 32), (u32_t)sntp_time.seconds);
#endif

end:

0 comments on commit 08be81d

Please sign in to comment.
You can’t perform that action at this time.