Android BLE 4.3 onDescriptorWrite returns status 128 on enabling characteristics notification

被刻印的时光 ゝ 提交于 2019-12-05 08:51:39

I had the same problem, and solved it by disabling and reenabling the bluetooth interface.

The Android BLE stack seems to be still immature and suffers from instability problems.

This error could be related to max threshold imposed by Android OS.

#define BTA_GATTC_NOTIF_REG_MAX     15

 - for 4.3 max number of notification/indication is 4 
 - for 4.4 max number of notification/indication is 7
 - for 5.0 max number of notification/indication is 15

https://groups.google.com/forum/#!topic/android-platform/FNHO5KB4sKI

https://android.googlesource.com/platform/external/bluetooth/bluedroid/+/android-5.0.2_r1/bta/gatt/bta_gattc_int.h

A very late answer, but this might prove valuable to anyone encountering status 128 (GATT_NO_RESOURCES) on a gatt.writedescriptor() call.

In my case status 128 showed up when trying to write a descriptor with a value of ENABLE_NOTIFICATION_VALUE for a characteristic that required a subscription for an indication via ENABLE_INDICATION_VALUE instead.

So instead of

BluetoothGattDescriptor descriptor = bluetoothGattCharacteristic.getDescriptor(DESCRIPTOR_UUID);
descriptor.setValue(ENABLE_NOTIFICATION_VALUE);
mGatt.writeDescriptor(descriptor);

going for

BluetoothGattDescriptor descriptor = bluetoothGattCharacteristic.getDescriptor(DESCRIPTOR_UUID);
descriptor.setValue(ENABLE_INDICATION_VALUE);
mGatt.writeDescriptor(descriptor);

Fixed the problem. I assume the other way around will produce the same error status 128.

Serhii Koltsiuk

I received this error when performing writeCharacteristic with the WriteNoResponse property. When I specify the WriteWithoutResponse argument for writeCharacteristic, the problem disappears.

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