I am developing an Android application that can connect and communicate with BLE device, Connection and data sending is working fine.. But when i am writing descriptor value to gatt object I am getting status code as 4 in onDescriptorWrite Callback. As per my understanding status code zero is GATT_SUCCESS. I dont know what does status code 4 means?
Here is my code
val descriptor = characteristicDeviceToApp?.getDescriptor(UUID.fromString(DESC_UUID))
descriptor?.value = BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE
val descriptorResult = gatt.writeDescriptor(descriptor)
I am getting below callback with status as 4
override fun onDescriptorWrite(
gatt: BluetoothGatt?,
descriptor: BluetoothGattDescriptor?,
status: Int
) {
}
Note: I am getting descriptorResult as true.
I have tried referring official documents..Nothing is helpful..Additionally the same code is returning status as 0 (GATT_SUCCESS) for some other BLE device
It is because the PDU (Protocol Data Unit) size sent from Android. The error code 4 is defined as
INVALID_PDUin the API source code (see Google's API source code). Different devices may have different PDU sizes depending on their specific BLE version.So if the PDU sent from your Android device (client) is wrong length, then the peripheral (server) device will respond with this error code according to the BLE Core Specification v4.0, section 3.3 ATTRIBUTE PDU.
However your code doesn't seem to have a problem. This error may have occured because of some incompabilities like unmatching PDU size in low level APIs of both devices.
Well what to do to handle this situation?
The answer is it depends.