I have an nRF52840 based peripheral running SDK 15.3.
I have a custom service with a write characteristic and a read characteristic. The peripheral supports multiple connections. I would like for the read characteristic's value to be unique for each connection (i.e. unique for each central). Is this possible?
For example. Assume the Bluetooth service is performing an echo of the data written by the central. Let's assume there are two central devices connected (central_1 and central_2). Assume central_1 is connected on connection handle 1 and central 2 is connected on connection handle 2. The desired behavior is:
Is there a way to accomplish this?
Did you look at the BLE Link Context Manager.
You could probably test it using the Nordic UART service that it refers too.
Can you describe in more detail exactly how would you use the BLE link context manager to accomplish what I described above?
Is the BLE_GATTS_EVT_RW_AUTHORIZE_REQUEST event the only way to supply the unique data to each client?
Can the context manager be used to provide unique notifications per each connection?
It appears the context manager does not actually set the characteristic value for each connection. It looks like it just supplies a storage area to store the values for multiple connections and then on RW_AUTHORIZE_REQUEST the actual response is set. Is my understanding correct?
Yes, your understanding seems correct. There is only one attribute table. So the application will have to switch the values in the attribute table if you want each client to have a unique dataset.
If you want to send unique notifications per connection you can change the data before calling sd_ble_gatts_hvx. Remember that you need to provide the connection handle every time you call this function. So you can notify multiple clients with different values. Each time you send a notification the value in the attribute table is changed. So if a peer tries to read the value the context manager can be used to provide the value belonging to that peer based on the connection handle.
For an example on how to use the context manager when sending notifications you can look at the ble_hids.c and the ble_hids_inp_rep_send() function.