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

Parents
  • 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
  • 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  

  • You will have to solve this the best you see fit. Though from what I can understand this is a proprieatry application, this means that you can have proprieatry characteristics with a data format that fit your needs, e.g. a characteristic can be defined by you to hold both time data and measurements, and this combined data can be sent as one notification for each measurement. This is much effective than using many characteristics, since having more characteristics typically mean you will have to read/write/notify more packets on air, instead of one packet (notification) that can consist of a format that you define (code and decode as you best see fit).

    That said, there should be no problem to also have several services and characteristics, though it might be more difficult to possible know at what time a measurement have been performed in specific if you don't somehow combine the two into one packet as suggested.

    Kenneth

  • Thanks once again for your suggestion. Yes I am planning to send like wise. But my question here is something other, 

    I have to include timestamp without initializing or setting time manually. For this My client device has a service call as Current Time (So the client reads current time from some other device which is not my area), which do notifies when it reads current data.

    My device is peripheral role, but I would like to read the characteristic value of those Current Time Service of client. Is it possible? So that I would get current time withour setting manually then I can use this value to update my timestamp with help of RTC.

    in short, My peripheral device need to read one of the characteristic value from Client (which do notification once it get correct current time data). Is there any suggestion on it, I mean implementation of this logic possible or not?

    Thanks and Regards,

    Sreejith 

  • Hello,

    I am not entirely sure I understand, but it's only a server that can hold data, so a client can either write to the server or read from the server. 

    Best regards,
    Kenneth

  • Yes, but my master device has one service (act as a server service) only for time measurement and do notification once it read from some other time client device. So my server required to read that time server service from Master. Is it possible ? Simply does my server device can read from the master (when the master do notify)?

    Thanks and Regards

Reply Children
No Data
Related