This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Asset tracker V1 date_time

Hi,

Running the asset_tracker V1 i obtain a LTE connection and date time:

[00:00:19.338,226] [0m<inf> asset_tracker: DATE_TIME_OBTAINED_NTP

I want to convert it to a tm structure

So I do something like:

int64_t ms;

static struct tm tminfo;

date_time_now(&ms);

gmtime_r (&ms,  &tminfo );

I always end up with strange values in the tminfo structure

Is there another call I need to make to convert the date_time_now value into a unix epoch first?

Many thanks

  • Hi,

    A couple of observations:

    You should check the return value from date_time_now(), to ensure that the operation was successful. In case of no time available, the function will return -ENODATA. In case of success, it will return 0. If unsuccessful, ms is likely to contain garbage data.

    The parameter unix_time_ms indicates that this is a type of unix timestamp (number of seconds since 1970, not counting leap seconds), but in miliseconds instead of seconds. Try dividing the value by 1000 to convert to seconds, before using it with gmtime_r().

    It is not fully clear from our documentation, but the timestamps seem to be in milliseconds throughout the Date-Time library. For the standard library in C the time_t is usually in seconds.

    Regards,
    Terje

Related