Hi,
I think I found a bug in writeCharacteristic method. If BLE device disconnects right before the call to writeCharacteristic, then it never returns success or failure.
Example to reproduce:
disconnect()
.done { Log.d("test", "Disconnect request successful") }
.fail { _, _ -> Log.d("test", "Disconnect request failed") }
.enqueue()
writeCharacteristic(
communicationCharacteristic,
byteArrayOf(),
WRITE_TYPE_DEFAULT
)
.done { Log.d("test", "Write request successful") }
.fail { _, _ -> Log.d("test", "Write request failed") }
.invalid { Log.d("test", "Write request invalid") }
.enqueue()
This example prints in the logs Disconnect request successful, but write request neither succeeds nor fails.
I've also noticed the same behavior when BLE device disconnects because of poor signal and the code is trying to write characteristic at the same time.
WhenwriteCharacteristic is used from kotlin with .suspend() like this:
writeCharacteristic(
communicationCharacteristic,
data,
WRITE_TYPE_DEFAULT
).suspend()
it just hangs, never returning or throwing anything. Also, because WriteRequest is not cancellable when suspended, this coroutine can't be cancelled, so wrapping it in withTimeout doesn't help.
Hi,
I think I found a bug in
writeCharacteristicmethod. If BLE device disconnects right before the call to writeCharacteristic, then it never returns success or failure.Example to reproduce:
disconnect() .done { Log.d("test", "Disconnect request successful") } .fail { _, _ -> Log.d("test", "Disconnect request failed") } .enqueue() writeCharacteristic( communicationCharacteristic, byteArrayOf(), WRITE_TYPE_DEFAULT ) .done { Log.d("test", "Write request successful") } .fail { _, _ -> Log.d("test", "Write request failed") } .invalid { Log.d("test", "Write request invalid") } .enqueue()This example prints in the logs
Disconnect request successful, but write request neither succeeds nor fails.I've also noticed the same behavior when BLE device disconnects because of poor signal and the code is trying to write characteristic at the same time.
When
writeCharacteristicis used from kotlin with.suspend()like this:writeCharacteristic( communicationCharacteristic, data, WRITE_TYPE_DEFAULT ).suspend()it just hangs, never returning or throwing anything. Also, because
WriteRequestis not cancellable when suspended, this coroutine can't be cancelled, so wrapping it inwithTimeoutdoesn't help.