randdusing / cordova-plugin-bluetoothle

Bluetooth Low Energy Phonegap Plugin
804 stars 353 forks source link

Subscribe operation: make descriptor writes optional #451

Open acutetech opened 7 years ago

acutetech commented 7 years ago

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()).

randdusing commented 7 years ago

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

acutetech commented 7 years ago

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.

StephanBis commented 2 years ago

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?