Skip to content
Permalink
Browse files

samples: google_iot_mqtt: 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 08be81d commit 220fba3b5d36cb113d156547751547493f8036ec
Showing with 4 additions and 4 deletions.
  1. +4 −4 samples/net/google_iot_mqtt/src/main.c
@@ -30,7 +30,7 @@ void do_sntp(struct addrinfo *addr)
struct sntp_ctx ctx;
int rc;
s64_t stamp;
u64_t epoch_time;
struct sntp_time sntp_time;
char time_str[sizeof("1970-01-01T00:00:00")];

LOG_INF("Sending NTP request for current time:");
@@ -42,13 +42,13 @@ void do_sntp(struct addrinfo *addr)
return;
}

rc = sntp_request(&ctx, K_FOREVER, &epoch_time);
rc = sntp_query(&ctx, K_FOREVER, &sntp_time);
if (rc == 0) {
stamp = k_uptime_get();
time_base = epoch_time * MSEC_PER_SEC - stamp;
time_base = sntp_time.seconds * MSEC_PER_SEC - stamp;

/* Convert time to make sure. */
time_t now = epoch_time;
time_t now = sntp_time.seconds;
struct tm now_tm;

gmtime_r(&now, &now_tm);

0 comments on commit 220fba3

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