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

Get UNIX Time with nrf9160

Hello,

I would like to get current UNIX time with my nrf9160.

First I saw that we can ask the current time from the modem using the AT cmd "AT+CCLK?".

This function works, but give me the date and time and not the UNIX time. 

I saw also that another function exist -> int time_modem_get()

But I don't know how to use it.

I've add in my prj.conf  this two lines:

CONFIG_DATE_TIME=y

- CONFIG_DATE_TIME_MODEM=y
But I can't compile because the functin time_modem_get is not declared in this scope.
 
Someone has an idea how to use it?
Thanks
Parents
  • Hello! 

    Try to use the date_time library instead (#include <date_time.h>). The current time can then be acquired using either the modem or NTP. A simple usage example below:

    #include <date_time.h>
    
    /*TIME*/
    s64_t unix_time_ms;
    
    /*Force the date_time library to get current time */
    date_time_update();
    
    /*Read current time and put in container */
    err = date_time_now(&unix_time_ms);
    
    /*Print the current time */
    printk("Date_time: %i %i\n", (u32_t)(unix_time_ms/1000000), (u32_t)(unix_time_ms%1000000));


    If the program doesn't compile, try to add the following line to prj.conf:

    CONFIG_LEGACY_TIMEOUT_API=y

    Hope this helps!

    Best regards,
    Carl Richard

Reply
  • Hello! 

    Try to use the date_time library instead (#include <date_time.h>). The current time can then be acquired using either the modem or NTP. A simple usage example below:

    #include <date_time.h>
    
    /*TIME*/
    s64_t unix_time_ms;
    
    /*Force the date_time library to get current time */
    date_time_update();
    
    /*Read current time and put in container */
    err = date_time_now(&unix_time_ms);
    
    /*Print the current time */
    printk("Date_time: %i %i\n", (u32_t)(unix_time_ms/1000000), (u32_t)(unix_time_ms%1000000));


    If the program doesn't compile, try to add the following line to prj.conf:

    CONFIG_LEGACY_TIMEOUT_API=y

    Hope this helps!

    Best regards,
    Carl Richard

Children
Related