9 years, 9 months ago.

onDataRead() callback like onDataWritten?

I cannot find a callback similar to BleDevice.onDataWritten(), but which is called when data is being read. This is useful when you want to read a sensor only when the Gatt client (phone,..) requests the data. I noticed that all the BLE examples are using a timer to update the value of characteristics. What's the proper way to intercept read requests?

Question relating to:

High level Bluetooth Low Energy API and radio abstraction layer

This is not a design oversight from Nordic as you mention, this is simply functionality that comes with the Nordic SoftDevice but has not been exposed to the mbed C++ API yet. The authorization mechanism was introduced with the first version of the Nordic SoftDevice to deal with these sort of situations.

posted by Carles Cufi 11 Aug 2014

Hi Carles, thanks for your input. Apologies, I misunderstood the authorisation mechanism. I believed it's used only for encrypted connections. It seems I can use this also for non-encrypted connections and simply return success for every authorisation request. As for the BLE library from mbed, I can fork it and include the functionality I need.

posted by Prashant Vaibhav 11 Aug 2014

1 Answer

9 years, 8 months ago.

The following comes from one of the BLE experts:

Quote:

By default the SoftDevice only sends events for write operations, but you *can* get events for reads if you set the ble_gatts_attr_md_t::rd_auth bit when populating a characteristic, it’s called “authorization”, see this diagram here:

https://devzone.nordicsemi.com/documentation/nrf51/6.0.0/s110/html/a00852.html

The drawback then is that the app needs to respond to the authorization request for the read response packet to go over the air.

It seems that authorization would be one way to get the behaviour you want. However, that may or may not be the correct approach.

An alternative which provides most of the benefits would be to poll for data infrequently (perhaps only when the peripheral is connected), and then use notifications/indications to update the client when the data changes.

If you must have an authorization trigger for reads, then i can pencil in a request to be handled later.

Accepted Answer

Thanks for your reply. I do however think that polling is not the best workaround. It will introduce unavoidable latency (update period). This is not so bad, but the processor will also need to wake up every x ms to read the sensor value, without any request from the user. I guess we can chalk it up to a design oversight from Nordic :-/

Since I also need callbacks for Write without response events I'll be happy to modify the mbed BLE library to use authorisations, and send a pull request once it's working fine.

posted by Prashant Vaibhav 11 Aug 2014

Assigned to Rohit Grover 9 years, 8 months ago.

This means that the question has been accepted and is being worked on.