Beware that this post is related to an SDK in maintenance mode
More Info: Consider nRF Connect SDK for new designs
This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

On-the-fly update of Characteristic value in User Memory

#define BLE_GATTS_VLOC_USER          0x02  /**< Attribute Value is located in user memory. This requires the user to maintain a valid buffer through the lifetime of the attribute, since the stack
                                                will read and write directly to the memory using the pointer provided in the APIs. There are no alignment requirements for the buffer. */

In this case, when I change values in the "User memory", is there any API call or other action required to advise the SoftDevice that the data has changed?

Only the values (content) will change - not the length.

Is there an example which illustrates this?

nRF5 SDK v15.3.0.

Parents
  • No nothing to do, when the characteristic is read the client will read whatever the current value is. You can change it as often as you like, softdevice doesn't need to know. If you want to notify or indicate it, just call sd_ble_gatts_hvx() after your update to queue a notification. 

    One point to note; if your characteristic data is long enough that a write to it is non-atomic, I know of nothing which prevents your being interrupted while you're changing the data. If the softdevice at that point satisfies a read for that characteristic, the data written out will be whatever you were half way through writing. If your characteristic is notify/indicate only, you can control this by waiting until you know the hvx() send has completed. If not and it's important to you, probably need a marker in the data you can update atomically. You set that to false, then you update the data, then you set it true again. In that way if your data goes out half-cooked, the receiver can recognise that and toss the data. 

  • Thanks.

    We have a plan for non-atomicity ....

Reply Children
No Data
Related