BLE GATT onCharacteristicChanged not called after subscribing to notification

≯℡__Kan透↙ 提交于 2019-12-05 02:32:52

So, I finnally figured out my mistake :) As you can see above, I'm usinng a UUID with the same base for my descriptor as my characteristics (starting with 3f54XXXX-....)

I changed it to public static final UUID X_ACCEL_DESCRIPTOR_UUID = UUID.fromString("00002902-0000-1000-8000-00805f9b34fb"); and now everything is working as expected.

I did not do this before as i thought that there should be a descriptor for each characteristic. But in fact, according to the Client Characteristic Configuration the ...

[...] descriptor shall be persistent across connections for bonded devices. The Client Characteristic Configuration descriptor is unique for each client.

So I checked the RedBearLab Android App example and saw that the descriptor's UUID equals the ones posted on other SO answers.

This also explains why my App received Notifications after I enabled them in the BLE Scanner App: As the descriptor shall be persistent across connections for bonded devices, the BLE Scanner App used also this UUID for the descriptor and thus enabled notifications for the client (= my phone).

customBluetoothGatt.setCharacteristicNotification(characteristic, enabled);

    BluetoothGattDescriptor descriptor = characteristic.getDescriptor(UUID.fromString(SampleGattAttributes.CLIENT_CHARACTERISTIC_CONFIG));
    descriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE);
    descriptor.setValue(BluetoothGattDescriptor.ENABLE_INDICATION_VALUE);
    boolean success = customBluetoothGatt.writeDescriptor(descriptor);

Now set the descriptor property ENABLE_INDICATION_VALUE

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!