This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

How to read Characteristics value in a fixed interval time?

I want to read peripheral's characteristics value in a fixed time interval or an event-based in the central.

I am using the nRF52840 Evalution board and SDK_17.0.2.

Here I know that notification is the best way to be notified when the peripheral's characteristics value changes.

But peripheral's value changes too often in which I don't want to be notified of. 

only want to send read requests based on a certain period let say 5min for an example.

I am trying to use it on a sample example of hrs_c in which I want to read battery level after some regular time interval.

  • Hello,

    If you are "in charge" of the peripheral as well, I would suggest that you tell it to only send the notification every 5 minutes. 

    But it is possible to do as you say, to have the peripheral update the characteristic as often as it likes, but only read the characteristic every 5 min from the central. 

    In order to do this, you need to modify both the central and peripheral projects. Firstly you need to change the characteristic owned by the peripheral to allow being read. Then you need to implement reading that characteristic.

    If you want to look at the ble_app_hrs and ble_app_hrs_c examples, I suggest you start by looking at the peripheral example and look at how the Device Information Service (DIS) implements the Manufacturer Name String as a readable characteristic. (It is not given that you can read it even if you can enable notifications).

    Check out services_init() -> ble_dis_init() -> if (p_dis_init->manufact_name_str.length > 0) -> 

    add_char_params.char_props.read = 1;
    and 
    add_char_params.read_access     = rd_sec;

    Then try to connect to it using nRF Connect (for Desktop or mobile) and try to read the Manufacturer Name String characteristic. Try to modify whatever characteristic you want to be readable to do the same, and check that you can read it using nRF Connect. Then you can start implementing the central application. You need to write a function that reads the characteristic. This will probably involve sd_ble_gattc_read(), and you will probably get a callback when the read is complete.

    We don't have any central examples doing this kind of read as far as I know, but I guess the implementation will be quite similar to how ble_app_uart_c uses ble_nus_c_string_send() to write. I would also suggest that you go back a couple of SDKs (15.3.0) to find the implementation without the GQ (gatt queue), as this can be quite confusing. You can of course implement your solution in SDK17.0.2. It should be almost identical API. 

    Look at how ble_nus_c_string_send() uses sd_ble_gattc_write(), and try to replace it with sd_ble_gattc_read(). The parameter offset in sd_ble_gattc_read() can be set to 0, but look at that example to see how to get the conn_handle and handle. 

    Best regards,

    Edvin

  • It is working Thank you..!

Related