kable
kable copied to clipboard
Add support for L2CAP
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 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. ❤️
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! :)
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
BluetoothDeviceobject from Kable - On iOS, it would require access to both the
CBPeripheraland theCBPeripheralDelegatethat Kable already set internally
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