androidarduinobluetooth-lowenergygatt

How to set Client Characteristic Configuration on Android for BLE descriptor?


Hi I am making an Anrdoid BLE App which can communicate with Arduino nano 33 IOT. My notification callback method is never called, so I ask question on stackoverflow few days ago. and someone has answer me that my Arduino BLE descriptor is clearly states notifications and indications are disabled link here. So I tried to found how to set enable notification and indication. As soon as I searched on google, I realized there is no way to set descriptor on Arduino. And also someone said I have to set notification and indication on Android. link here

But I can't still find some code which can set notification and indication on Android. I thought the codes below can set descriptor's notification and indication, but it didn't work.

MainThreadPrint("1 - btGattCharacteristic success");
BluetoothGattDescriptor bluetoothGattDescriptor = btGattCharacteristic.getDescriptor(UUID.fromString("beca6057-955c-4f8a-e1e3-56a1633f04b1"));
MainThreadPrint("2 - Descriptor found! : beca6057-955c-4f8a-e1e3-56a1633f04b1");                          
bluetoothGattDescriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE);
MainThreadPrint("3 - Descriptor ENABLED.");
btGatt.writeDescriptor(bluetoothGattDescriptor);
MainThreadPrint("4 - descriptor setting finished.");

So how to set descriptor's value for enable notification and indication on Android APP? (descriptor value : the red underline in the picture.)

enter image description here


Solution

  • In order to enable notifications on a remote device, you need to use the function setCharacteristicNotification(). This is described in further details in the links below:-