Libblepp should be replaced

Libblepp uses a legacy bluetooth command set that is disallowed on recent Linux kernels when the PC supports extended bluetooth commands.

When a PC issues an extended bluetooth command, no legacy commands will be allowed after that [1]. This wasn't enforced in older kernels, since the bluetooth extended commands weren't supported, but it is enforced now.

When your PC supports the bluetooth extended command set, and you use a recent kernel, some Warble functions will return errors like the one described in [2]. Specifically, that error happens because Libblepp issues the command "LE Set Scan Parameters" (0x08|0x000b), instead of "LE Set Extended Scan Parameters" (0x08|0x0041).

To fix this, there are 2 main alternatives: Implement the extended command set in Libblepp, or switch to another library that doesn't have that issue.

If the first option is chosen, someone would have to implement the corresponding HCI extended commands such as [3]. However, the preferred way of using bluetooth in Linux is using the D-Bus API. I haven't found a C/C++ library that implements the necessary high level functionality required by Warble, but libraries such as [4] may be a good option for Python support.

I know that this change implies a significant effort, but as people upgrade their PCs and use newer kernels, Libblepp will stop working for more and more users.

[1] https://bugs.launchpad.net/ubuntu/+source/linux/+bug/1870837/comments/35

[2] https://mbientlab.com/community/discussion/3388/scan-connect-py-error-on-ubuntu/p1

[3] https://github.com/torvalds/linux/blob/e767b3530acbf651593e3d357fe1168a024d8061/net/bluetooth/hci_request.c#L948-L987

[4] https://github.com/hbldh/bleak/

Comments

  • edited April 2021

    hey @stbnps,

    Our main library is written in CPP and it does not integrate any bluetooth libraries. The CPP is platform agnostic and we welcome folks to add any BLE library stack on top.

    Our APIs in Swift, Javascript and so on are only examples for folks and we used the bluetooth libraries available at the time (and there wasn't many options back then). Now there are more options and as I mentioned, we don't provide the Bluetooth libraries, we only provide the main APIs that communicate with our sensors, our users are welcome to use any Bluetooth libs they may prefer (and as you mentioned, there are many options available now).

    All Bluetooth libraries in our examples are third parties and of course, the quality varies as such.

  • Thanks for the clarification!
    Keep in mind that having broken examples in popular languages such as Python, my harm user experience.
    People (at least me), expect the examples to work out of the box.

  • The examples worked for me. If you have broken examples, please let me know but sometimes it will work on 90% of systems but not some obscure Linux distro (which is fine with me).
    We test on common systems like an Android tablet, an iPhone 11 or a RaspberryPi 4.

  • The scan_connect.py example [1] has the issue I mentioned before. It relies on Libblepp to perform the scan, so if your PC supports the extended command set and you have a recent linux kernel, it won't work.

    [1] https://github.com/mbientlab/MetaWear-SDK-Python/blob/master/examples/scan_connect.py

  • I see what you are saying.
    Actually this is the only examples that scans. The scanning examples is sort of an outlier.
    All other examples don't use this.

Sign In or Register to comment.