How to update Timestamp using the time.h library in NRF52840

Hello guys,

I'm stuck trying to produce a timestamp for data synchronization in my project. I have gone through some of the issues raised in this regard but none was actually helpful. 

Currently I am using the time.h library, but the time doesn't get updated. it keeps printing the same time.

Now I tried using a static incrementing counter to update the ".tm_secs" struct member, Now the time updates over as the counter increment. but the minute and hour field soesn't get updated when ".tm_secs" gets to 59.

I don't know if this is the best approach, but I just want to produce a time epoch, I can always set the epoch with the current time over my GSM modem.

Parents
  • Hi 

    I recently did something similar in a hobby project of mine, where I needed to keep track of time. 

    I set the time using the clock_settime(..) function, like this:

    Fullscreen
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
     

    Then I can simply read out the time like this:

    Fullscreen
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

    You can find the source here.

    Best regards
    Torbjørn 

  • While I have solved the underlying issue, I will try this out and compare what I have with yours. Thank you, sir!

    Edit: I have tried replicating this code but I ran into this error:

    main.c:67: undefined reference to `clock_settime'
    collect2.exe: error: ld returned 1 exit status
    ninja: build stopped: subcommand failed.
    FATAL ERROR: command exited with status 1: 'C:\ncs\toolchains\31f4403e35\opt\bin\cmake.EXE' --build 'c:\nordic\myapps\firmware\app\build' 

    I have included these libraries:

    #include <time.h>
    /* clock_gettime() prototype */
    #include <zephyr/posix/time.h>
    but the error keeps occurring.
  • I have fixed the error, i included "

    CONFIG_POSIX_CLOCK=y

    "

    in my prj.conf file.

    Thanks!!!!

  • Glad I could help. The best of luck with your project Slight smile

Reply Children
No Data