cordova-plugin-bluetoothle icon indicating copy to clipboard operation
cordova-plugin-bluetoothle copied to clipboard

Subscribe operation: make descriptor writes optional

Open acutetech opened this issue 8 years ago • 3 comments

As far as I can see, the subscribe() method first writes to the peripheral's Client Configuration Configuration descriptor then, when the code receives the callback from that operation, it calls gatt.setCharacteristicNotification() to register the indication/notification in the central.

However it is not necessary to write the descriptor on every connection since "This descriptor shall be persistent across connections for bonded devices." (https://www.bluetooth.com/specifications/gatt/viewer?attributeXmlFile=org.bluetooth.descriptor.gatt.client_characteristic_configuration.xml). That is, on bonded devices the peripheral will have stored the CCCD value from earlier. So the write could/should be made optional (for greater efficiency) as is done by the Evothings plugin (see the "writeConfigDescriptor" parameter here https://evothings.com/doc/lib-doc/module-cordova-plugin-ble.html#.enableNotification).

In the Evothings code the enableNotification() method first calls setCharacteristicNotification() then writes the descriptor only if the writeConfigDescriptor parameter is true. The application need only write to the CCCD after bonding (or if it really wants to dynamic control of indications/notifications).

The same parameter would be needed for unsubscribe (and is present in Evothings disableNotification()).

acutetech avatar Aug 11 '17 16:08 acutetech

What's the downside of writing it again? Slightly slower subscribe setup?

randdusing avatar Aug 13 '17 20:08 randdusing

I guess the motivation for making the change would be (a) keeping in the spirit of the spec and (b) the general philosophy of minimising radio messages and processor wake time so as to maximise peripheral battery life.

My attention was drawn to this because of the contrast with the behaviour I was used to with the Evothings plugin.

acutetech avatar Aug 14 '17 08:08 acutetech

We would like to bring this issue back to life. Altough for another use case. We have some read (no indicate/notify) characteristics which do not have any descriptors. The Subscribe operation however wants to get the ClientConfigurationDescriptor descriptor so we get the "Descriptor not found" error. Is there a possibility to make this an optional check?

StephanBis avatar Nov 23 '21 14:11 StephanBis