Zephyr Timing With Epoch

Hello,

I am using Zephyr in conjunction with a Xiao BLE Sense, my requirement is that I need the device to know when a certain date has been reached, is that possible with zephyr? I have tried using the time.h as in the documentation Zephyr said that is a possible way of getting the Epoch time, at least from what I could figure out.

If theres anyway to do this please let me know.

My only main issue if this is possible, is whenever I try to use the Time.h library, zephyr says there is an undefined reference to the functions within Time.h

Thanks,

Cage

  • Hello Cage,

    Regarding epoch time feature enabling in a Zephyr, about a year ago I observed some promising output from a Nordic Semi ncs v1.6.1 sample application, Nordic's `aws_iot` sample app of that SDK release.  I was building and testing this sample on an nRF9160DK dev board.  I recall early on in the sample's Zephyr console output -- which also streamed out some application messages -- that the firmware sample had connected with an Network Time Protocol (NTP) server.  Sample app then printed the date in a format much like or identical to Unix' default `date` utility output.

    Are you looking to add epoch time to your application without synchronizing with a time service somewhere on the internet?  If yes, then the NTP related part of Nordic's `aws_iot` sample goes beyond what you need in that regard.  I see however looking over the included header files of aws_iot source file main.c, that the sample pulls in a Nordic header file named `date_time.h`, which in turn pulls in `time.h`.

    You mention that you ran into a undefined symbol error reported in `time.h`.  Can you share that error?  That might shed some light on an issue you'll need to resolve whether you require NTP in addition to epoch time features from a given library.

    Two more things I will mention which you may already be aware:  (1) ncs v1.6.1 is quite old now, and only available from Nordic Semi github repository as a zip file:

    https://github.com/nrfconnect/sdk-nrf/releases/tag/v1.6.1

    If you're able to download ncs v1.6.1 and open `nrf/samples/nrf9160/aws_iot/src/main.c`, take a look for the function `static void date_time_event_handler(const struct date_time_evt *evt)`.  Those lines of code are the ones which I first found related to NTP service provision, which was related to the support of epoch time in this sample.

    (2)  I checked the latest ncs release and specifically this sample app, and there's no longer any obvious NTP code in it.  Here is the path / URL to today's cutting edge version of Nordic ncs and that sample app:

    https://github.com/nrfconnect/sdk-nrf/tree/main/samples/net/aws_iot

    You don't mention which ncs version with which you're working, so you may yet have NTP code in one or more Nordic sample apps.  That will be up to you to check whether you can find any `NTP` or `ntp` patterns among the sources in your local copy of their SDK.

    What was clear to me from the 1.6.1 version of aws_iot sample is that both epoch time and NTP service worked.  I was not even looking for those at that early stage development time.  But time feature and time synchronization are important and basic building blocks for many devices.  So I made a mental note of the working resource.

    Hopefully this can give you a place to look for how epoch time can be enabled in a Zephyr project.  There are likely examples outside of ncs altogether, but I haven't looked elsewhere, and you're using that SDK as well so it' a good starting point.

    - Ted

  • Im currently using zephyr with a dev container, I dont know if that encompasses the SDK for nordic? I am also using the expansion board with the Xiao, which has an RTC on it, would that work?

    wiki.seeedstudio.com/.../

Related