Hi, question about Kable In the androidMain file B...
# juul-libraries
a
Hi, question about Kable In the androidMain file BluetoothDeviceAndroidPeripheral.kt Is it possible that the onServicesDiscovered is called before there is an established connection? I've been getting this issue with requestMtu, where it seems like we're not connected before discoverServices is called.
Copy code
om.juul.kable.GattStatusException: OnMtuChanged(mtu=23, status=GATT_ERROR(133))
t
onServicesDiscovered
is called after a connection is established. Unless Android is misreporting statuses (via the callback). This is unlikely though. Events in the callback are logged though, so if you provide logs, then it would help to diagnose your issue.
a
Copy code
com.juul.kable.GattStatusException: OnMtuChanged(mtu=23, status=GATT_ERROR(133))
                                                                                                        at com.juul.kable.ConnectionKt.checkResponse(Connection.kt:276)
                                                                                                        at com.juul.kable.ConnectionKt.access$checkResponse(Connection.kt:1)
                                                                                                        at com.juul.kable.Connection.requestMtu(Connection.kt:210)
                                                                                                        at com.juul.kable.Connection$requestMtu$1.invokeSuspend(Unknown Source:15)
                                                                                                        at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:34)
                                                                                                        at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:100)
                                                                                                        at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:586)
                                                                                                        at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:829)
                                                                                                        at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:717)
                                                                                                        at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:704)
2026-02-24 09:55:46.245 10915-10943 E  Could not connect, status exception
                                                                                                    com.juul.kable.GattStatusException: OnMtuChanged(mtu=23, status=GATT_ERROR(133))
                                                                                                        at com.juul.kable.ConnectionKt.checkResponse(Connection.kt:276)
                                                                                                        at com.juul.kable.ConnectionKt.access$checkResponse(Connection.kt:1)
                                                                                                        at com.juul.kable.Connection.requestMtu(Connection.kt:210)
                                                                                                        at com.juul.kable.Connection$requestMtu$1.invokeSuspend(Unknown Source:15)
                                                                                                        at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:34)
                                                                                                        at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:100)
                                                                                                        at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:586)
                                                                                                        at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:829)
                                                                                                        at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:717)
                                                                                                        at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:704)
here is how I've set up the Peripheral
Copy code
private const val GATT_MAX_MTU_SIZE = 517

internal actual suspend fun connectWithAdvertisement(
    advertisement: Advertisement,
    autoConnect: Boolean,
): Peripheral {
    return Peripheral(advertisement) {
        logging {
            engine = SystemLogEngine
            level = Logging.Level.Warnings
            format = Logging.Format.Multiline
        }
        autoConnectIf { autoConnect }
        onServicesDiscovered {
            requestMtu(GATT_MAX_MTU_SIZE)
        }
        phy = Phy.Le2M

        observationExceptionHandler { exception ->
            Logger.e(exception) { "error while connecting" }
        }
    }
}