Skip to content

No response from writeCharacteristic #552

Description

@Lightwood13

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions