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

Datetime/RTC example

Hi,

Are there any examples utilizing the nRF9160 RTC? I want to timestamp my data that I send to the cloud because my use-case involves queuing up data for extended periods of time (a few hours) and then sending it all at once. It would be nice if I could timestamp the data with actual timestamps instead of just milliseconds since boot. What are my options for this?

Thanks

Parents Reply Children
  • My question relates more to the actual getting of the current time. I can read the RTC off of the modem using "AT+CCLK?" but this time is not accurate until I set it with "AT+CCLK=___". For example, right now when I read the time with AT+CCLK, it is 5 hours ahead. What are my options for getting the current time so I can set it in the modem and use it throughout? Of these, what would be the most reliable?

    I'm thinking that on boot, I would want to request the current time and then save it in the modem. What is the most reliable way of doing this?

  • jlangballeswift said:
    My question relates more to the actual getting of the current time. I can read the RTC off of the modem using "AT+CCLK?" but this time is not accurate until I set it with "AT+CCLK=___". For example, right now when I read the time with AT+CCLK, it is 5 hours ahead. What are my options for getting the current time so I can set it in the modem and use it throughout? Of these, what would be the most reliable?

     It is given with a offset at the end, as per the AT specification here:

    https://infocenter.nordicsemi.com/topic/ref_at_commands/REF/at_commands/mob_termination_ctrl_status/cclk_read.html?cp=2_1_3_28_1

     

    You can override this by setting it back with your time + timezone.

    jlangballeswift said:
    I'm thinking that on boot, I would want to request the current time and then save it in the modem. What is the most reliable way of doing this?

    You have several ways, as mentioned; ntp and gps. You can also query the lte network for time, and use AT+CCLK.

     

    Kind regards,

    Håkon

  • Hi Hakon,

    Maybe this is a separate issue but even when accounting for the timezone difference from CCLK, it is still inaccurate unless it has been set properly. I expected it to automatically get the correct time from the cellular network but it looks like it doesn't do that.

    What I ended up doing is using this sample to get the time using NTP, which I then use to set the modem RTC with AT+CCLK=___. Then I was able to get accurate timestamps from the AT+CCLK? command.

  • Hi,

    I had been following your post and needed a bit of help to get things going for me.

    I was looking at this example and wanted to know how did you link the NTP time to the AT+CCLK command to get the real time instead of manually entering the AT+CCLK command.

    Also, the NTP sample does not run in my SES (NCS v1.3.0) :(

    Thanks Slight smile

Related