kable icon indicating copy to clipboard operation
kable copied to clipboard

Add support for L2CAP

Open ErikHellman opened this issue 1 year ago • 3 comments

An alternative to GATT for BLE communication is to use L2CAP. This let's use use a connection-oriented channel towards the peripheral instead of the message-based method GATT uses. Think of this like TCP vs UDP. On an API level we two streams (InputStream and OutputStream), so it makes it much easier to work with.

This is supported by both Android and iOS, but doesn't exist for Web. https://developer.apple.com/documentation/corebluetooth/cbperipheral/openl2capchannel(_:) https://developer.android.com/reference/kotlin/android/bluetooth/BluetoothDevice?hl=en#createl2capchannel

I suggest this is added as an additional API in Kable. If this sounds good (despite the API missing on Web) I can start on an initial implementation.

ErikHellman avatar Dec 03 '24 12:12 ErikHellman

@ErikHellman this sounds like a great addition!

P.S. Loved your "Bluetooth Low Energy on Android" article series (that were posted on hellsoft); they helped shape Kable and avoid many Android pitfalls in its early development. ❤️

twyatt avatar Dec 03 '24 18:12 twyatt

Thanks! Kable is now my preferred library for this and also what I recommend when I end up with BLE code in apps. Great work! :)

ErikHellman avatar Dec 03 '24 19:12 ErikHellman

I haven't used Kable but I'm evaluating it. I came across this request for adding L2CAP support.

Is there a way to achieve this today without waiting for the library to implement this?

  • On Android, it would require access to the underlying BluetoothDevice object from Kable
  • On iOS, it would require access to both the CBPeripheral and the CBPeripheralDelegate that Kable already set internally

curioustechizen avatar Jun 02 '25 08:06 curioustechizen

I have created a PR with an initial draft of what an L2CAP interface could look like. It would be great if you guys could give feedback and let me know what is missing, or what you would do differently to make the interface useful and easy to use

zerodea avatar Sep 02 '25 13:09 zerodea