Adding Timestamp

Hi,

I am developing an application (Peripheral Sensor device: Acceleration measurement), I have included the characteritsics for the measurement and I am trying to include three packets of data to this characteristics value Timestamp, Value and Flag. I have already done the part of Value and Flag and currently I am facing difficulty in adding time stamp (I wish to add unix timestamp in Seconds). My client device has the Synchronization characteristics which notifies the current time (unix timestamp in Seconds in milliseconds). But I am not aware of where to start in order to include the timestamp in to my characetristic value. I refered nordic example "ble_cts_c" but I could not understand how can I sync the readed current time with my RTC of my measurement. In short I have following challanges,

1. Can I duplicate the Nordic example of Current Time Service Client in order to read the current time from my master/client which provides the current time (unix time stamp in millisecond)?

2. How and Where should I synchronize the readed current time value with my app_timer for the acceleration measurement? Is there any public example/codes available to refer? Can anyone comment on the code procedure (I mean where to start)? 

        2.1 Where should I call the function to read the current time?

        2.2 If I use 20 ppm timer accuracy how often should I call this read current time function?

        2.3 what happens when the the device enters in to the idle state (sleep mode), do I need to synch the time again after wake?

3. Is there any another way to include unix time stamp? 

(I am using nRF5, development kit: nRF52840DK)

It would be really helpful, If i get some guidance on this topic.

Thanks and Regards,

Sreejith

  • Hi,

    If you are interested in the current time profile you may find these links useful:
    example: https://infocenter.nordicsemi.com/topic/sdk_nrf5_v17.1.0/ble_sdk_app_cts_c.html 
    16-bit UUIDs: https://btprodspecificationrefs.blob.core.windows.net/assigned-values/16-bit%20UUID%20Numbers%20Document.pdf 
    current time service: https://www.bluetooth.com/specifications/specs/current-time-service-1-1/ 
    current time profile: https://www.bluetooth.com/specifications/specs/time-profile-1-0/ 
    gatt specification supplement, https://www.bluetooth.org/docman/handlers/DownloadDoc.ashx?doc_id=539729 (3.64 Date Time described the structure)

    As you can see from the above the resolution is in best case 1/256th second, so the resolution is ~4ms, and the server would need to update this every 1/256times a second for it to be this accurate (this to ensure that if the peer read this value it will always get the most accurate one). You could read this value periodically from the peer, and then have a 1ms tick counter on the peer that updated the time locally every 1ms and attach the time to your measurements if you like.

    It is unfortunately much higher than the 20ppm I can see you are asking for, which I don't see any way to implement.

    The easiest may instead just be to have a local time on the peer (where you specificy the resolution and timer) that start from 0 when you power up the peer, and attach this relative time for all measurements, and let the central somehow solve the timing (e.g. every time when it receives measurements with a relative time that started from 0 orignally, the central could at least place the measurements on a time line with high accuracy between eachother). The problem with this approach would be that you potentially have an unknown fixed offset of a few ms for all measurements, but the timing between the samples would be known.

    Best regards,
    Kenneth

  • Hi Kenneth,

    Thanks for your response.

    When I use the Current_Time_service every time (atleast first time) before starting the measurement I have to synchronize with the client to get current time, isn't it? 

    I have tried to use the NRF_CALENDAR example, but during the initialization function "

    NRF_CLOCK->LFCLKSRC = CLOCK_LFCLKSRC_SRC_Xtal << CLOCK_LFCLKSRC_SRC_Pos; The code enters in to infinte loop and shows an error <error> app: SOFTDEVICE: INVALID MEMORY ACCESS. How can I solve this error, is it because of any SDK_CONFIG problem?
    Thanks and looking forward for your response.
    Thanks and Regards,
    Sreejith
  • Sreejith Sundh said:
    When I use the Current_Time_service every time (atleast first time) before starting the measurement I have to synchronize with the client to get current time, isn't it? 

    What do you plan to use it for? Typically application just send notification as they are measured without any time stamp.

    KEnneth

  • All together I need to include unix timestamp (in uint32_t Seconds) along with the Measurement data. This is my requirement. So that I have included the NRF_CALENDAR example to get time, it works only when comment the following lines in nrf_calendar.c

    NRF_CLOCK->LFCLKSRC = CLOCK_LFCLKSRC_SRC_RC << CLOCK_LFCLKSRC_SRC_Pos;
    NRF_CLOCK->LFCLKSRC = CLOCK_LFCLKSRC_SRC_RC << CLOCK_LFCLKSRC_SRC_Pos;
    NRF_CLOCK->EVENTS_LFCLKSTARTED = 0;
    NRF_CLOCK->TASKS_LFCLKSTART = 1;
    while(NRF_CLOCK->EVENTS_LFCLKSTARTED == 0);

    when I uncomment, it shows INVALID error, I could not get what is the problem here, when I comment it I am getting timetsamp but that lasts only for 60 seconds after that all measurements were stopped and no more reading....

  • What do you plan to use it for?

    I would like to add timestamp (32 bit Unix timestamp in seconds) along with my measured acceleration data. What I currently done is that I used the NRF CALENDAR example and the initial time I set manually and now it works perfectly. But I wish to include a new custom time service (in my peripheral device) which has one characteristic named as current time char which is possible to read and write. But I would like to read a value from the client characteristic and write to the above mentioned current time char. Is it possible? does the cts_c example helps here? I am little confused that a peripheral device (which has about 5 services) can act as client to read only time?

    I do really appreciate your help.

    Thanks and Regards,

    Sreejith  

Related