After writing, onCharacteristicWrite()
gets called with the status BluetoothGatt.GATT_SUCCESS
, but I don't actually see it on my peripheral.
I know the issue isn't on the peripheral because it works when I use a generic BLE Scanner app.
This is what my writeCharacteristic
function looks like:
fun writeCharacteristic(characteristic: BluetoothGattCharacteristic, value: String) {
characteristic.writeType = BluetoothGattCharacteristic.WRITE_TYPE_DEFAULT
characteristic.setValue(value)
bluetoothGatt?.writeCharacteristic(characteristic)
?: run {
Log.w(TAG, "BluetoothGatt not initialized")
}
}
I've tried using a String or a ByteArray as the payload. I've also tried adding the operation to a queue.
The issue remains the same.
Well the success status is only reported after the peripheral has actually sent back a Write Response.
So either you write to the wrong characteristic, the wrong device, or you are not correctly detecting at the peripheral when an incoming write has been received.
One way to debug this is to use the hci snoop log in Android, or using a BLE sniffer.