BLE connection with pybluez

I am trying to connect to a BLE device using colibri-imx6ull.
(BSP6.8)

I added
IMAGE_INSTALL:append = " obexftp obex-data-server python3 python3-dbus python3-pygobject python3-pybluez"
to local.conf and tried running the example at GitHub - karulis/pybluez: Bluetooth Python extension module, but although pybluez/examples/simple/inquiry.py worked, pybluez/examples/ble/scan.py did not. The error message is below.

Traceback (most recent call last):
File “/home/root/pybluez/examples/ble/scan.py”, line 1, in
from bluetooth.ble import DiscoveryService
File “/usr/lib/python3.10/site-packages/bluetooth/ble.py”, line 1, in
from gattlib import *
ModuleNotFoundError: No module named ‘gattlib’

I added gattlib to IMAGE_INSTALL:append but it didn’t work and the error message didn’t change. Is there anything else I should do?

Hi, I’m the Toradex AI Assistant. The Toradex Support team will follow up with you shortly!

Did you like my answer?

:+1: :-1:


Hello there!

To address the ‘ModuleNotFoundError’ for ‘gattlib’ when using PyBluez on your Colibri iMX6ULL with BSP 6.8, please follow these steps:

  1. Verify gattlib Installation:

    • First, check if ‘gattlib’ is installed in your Python environment by running:
      pip3 show gattlib
      
    • If it’s not installed, you can add it using:
      pip3 install gattlib
      
    • Be aware that ‘gattlib’ might have additional dependencies or require specific library versions. Ensure your system meets these requirements.
  2. Check Python Path:

    • Confirm that the Python path includes the directory where ‘gattlib’ is installed. You can do this by executing:
      python3 -c "import sys; print(sys.path)"
      
    • If the path is missing, you may need to adjust your PYTHONPATH environment variable accordingly.
  3. Ensure Compatibility:

    • Make sure the version of ‘gattlib’ is compatible with your BSP and Python version. Sometimes, specific package versions are necessary for compatibility.
  4. Rebuild the Image:

    • If you have added ‘gattlib’ to your Yocto build configuration, verify that the build process completed successfully and that the package is included in the final image. Check the build logs for any errors related to ‘gattlib’.
  5. Consider Alternative Installation:

    • If the issue persists, you might try manually downloading and installing ‘gattlib’ from its source, ensuring all dependencies are satisfied.

By following these steps, you should be able to resolve the ‘ModuleNotFoundError’ and successfully run the BLE scan example with PyBluez on your Colibri iMX6ULL module.

Best regards, Toradex AI Assistant.

Please, also check if these links can help you solve your problem:

https://git.yoctoproject.org/poky-contrib/refs/?h=mazliana/qa-revamp-manual

BLE connection issue on Colibri IMX6ULL.

I added the pip3 package and tried the pip3 show command.

pip3 show gattlib
WARNING: Package(s) not found: gattlib

Apparently, gattlib could not be added.
Does this mean that the gattlib recipe for bsp6.8 doesn’t work?