This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts
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

access characteristic value

I have writable characteristic on the server. As far as I understood there are at least two ways to access to its value: one using ble_evt_t and BLE_GATTS_EVT_WRITE another via function sd_ble_gatts_value_get(). Please advise when and how to choose between those options.

Thank you.

  • BLE_GATTS_EVT_WRITE event will be generated when client will write some data in this characteristic, after this value was received server will save this value as current characteristic value.

    With sd_ble_gatts_value_get() call you can get current characteristic value at any time and place you want.

  • OK, let's take another look. If the server will update the value of this characteristic on write event and then will access to it without using sd_ble_gatts_value_get(). This looks easier but is it kosher? From other hand sd_ble_gatts_value_get() will probably take more effort to access every time it's needed but may be more legit. The characteristic I have in mind is bool and I don't feel comfortable using sd_ble_gatts_value_get(0 every time instead of if.

  • Yes, you can use it like this. Server will update characteristic value inside softdevice on write ond after this send BLE_GATTS_EVT_WRITE event to your application and you can store and use this value inside your application and don't get it with sd_ble_gatts_value_get() every time. You just need to handle BLE_GATTS_EVT_WRITE event and update your bool variable and as well update it if you call sd_ble_gatts_value_set() for this characteristic anywhere inside your application.

Related