NordicSemiconductor / Kotlin-BLE-Library

BSD 3-Clause "New" or "Revised" License
310 stars 33 forks source link

Can not discover services with ble client sdk. #87

Open maitolab opened 9 months ago

maitolab commented 9 months ago

I am using the client sdk with the latest version 1.0.10. After calling the connect and discoverService function as below:

val client = ClientBleGatt.Companion.connect(context, device.address, scope) val service = client.discoverServices()

Then I faced the warning and could not find any services.

Unhandled exception in callback
java.lang.IllegalStateException: This mutex is not locked
    at kotlinx.coroutines.sync.MutexImpl.unlock(Mutex.kt:213)
    at kotlinx.coroutines.sync.Mutex$DefaultImpls.unlock$default(Mutex.kt:98)
    at no.nordicsemi.android.kotlin.ble.core.mutex.MutexWrapper.unlock(MutexWrapper.kt:56)
    at no.nordicsemi.android.kotlin.ble.client.api.ClientMutexHandleCallback.tryEmit(ClientMutexHandleCallback.kt:32)
    at no.nordicsemi.android.kotlin.ble.client.real.ClientBleGattCallback.onServicesDiscovered(ClientBleGattCallback.kt:70)
    at android.bluetooth.BluetoothGatt$1$5.run(BluetoothGatt.java:347)
    at android.bluetooth.BluetoothGatt.runOrQueueCallback(BluetoothGatt.java:823)
    at android.bluetooth.BluetoothGatt.access$200(BluetoothGatt.java:47)
    at android.bluetooth.BluetoothGatt$1.onSearchComplete(BluetoothGatt.java:342)
    at android.bluetooth.IBluetoothGattCallback$Stub.onTransact(IBluetoothGattCallback.java:241)
    at android.os.Binder.execTransactInternal(Binder.java:1184)
    at android.os.Binder.execTransact(Binder.java:1143)
andrewowen commented 7 months ago

late response, but I noticed you're using ClientBleGatt.Companion.connect() but I'm pretty positive you should just be calling ClientBleGatt.connect(context, device.address, scope) instead. Hope this helps!