Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
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 11, 2019
1 parent 59eb483 commit 08be81d
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions samples/net/sockets/sntp_client/src/main.c
Expand Up @@ -21,7 +21,7 @@ void main(void)
#if defined(CONFIG_NET_IPV6) #if defined(CONFIG_NET_IPV6)
struct sockaddr_in6 addr6; struct sockaddr_in6 addr6;
#endif #endif
u64_t epoch_time; struct sntp_time sntp_time;
int rv; int rv;


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


LOG_INF("Sending SNTP IPv4 request..."); 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) { if (rv < 0) {
LOG_ERR("SNTP IPv4 request failed: %d", rv); LOG_ERR("SNTP IPv4 request failed: %d", rv);
goto end; goto end;
} }


LOG_INF("status: %d", rv); LOG_INF("status: %d", rv);
LOG_INF("time since Epoch: high word: %u, low word: %u", 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) #if defined(CONFIG_NET_IPV6)
sntp_close(&ctx); sntp_close(&ctx);
Expand All @@ -66,15 +66,15 @@ void main(void)


LOG_INF("Sending SNTP IPv6 request..."); LOG_INF("Sending SNTP IPv6 request...");
/* With such a timeout, this is expected to fail. */ /* 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) { if (rv < 0) {
LOG_ERR("SNTP IPv6 request: %d", rv); LOG_ERR("SNTP IPv6 request: %d", rv);
goto end; goto end;
} }


LOG_INF("status: %d", rv); LOG_INF("status: %d", rv);
LOG_INF("time since Epoch: high word: %u, low word: %u", 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 #endif


end: end:
Expand Down

0 comments on commit 08be81d

Please sign in to comment.