This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Android - Never get notification

Hi,

I'm writing an application to communicat on BLE with an IoT device. I connect well, and can write on characteristic but normally I should receive notification after writing. I never get it. But when I go through the application nRF Master Control it works well. I get good notification after writing this characteristic. Yet I send the same byte array.

Are there a few things specific to do?

  • Hi. First, You should enable notification sending 1 to cccd descriptor of desired characteristic.

  • Yes i've done that. I also try with the flag indication, but nothing... I've resolve the problem by threading the write. Each writing operation is made by a new thread, and with that solution i get notification.

  • Here are the required steps to enable a characteristic notifications (very similar for indications):

    • Get the characteristic from the connected device:

    BluetoothGattCharacteristic char = gatt.getService(serviceUuid).getCharacteristic(charUuid);

    You should maybe check if the characteristic has a CCCD and has the notification property.

    • Then, enable the notifications or indications:

    gatt.setCharacteristicNotification(char, true);

    • Finally, write to the CCCD to enable notifications:

    BluetoothGattDescriptor desc = char.getDescriptor(CCCD_UUID); desc.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE); boolean success = gatt.writeDescriptor(desc);

    You can check the result of the GATT writeDescriptor operation to be sure it has been sent. Then, you can wait for the asynchronous onDescriptorWrite callback to be sure the value has been written to the remote device.

    Be aware that it is not possible to queue GATT operations with the Android BLE stack. If the radio/stack is busy, you must wait on the operation callback before sending a new operation.

    Nordic provides some Android source code examples on Github, have a look here for instance. You can see an example with a queue of operations.

  • getValue() is showing null value. Is there any process to get the byte value from nRF52 ble module

Related