Feature request: Add bluetooth support to Python images

Hey folks,

I’ve spent the day trying to figure out how to talk with an arduino bluetooth module via python on a fin+cm3 and have hit quite a few walls. Most folks use PyBluez, and this was the initial route that I took, but I abandoned it after many dead ends. There’s evidence of others struggling with this here and here with varying success. Unfortunately it looks like the only options are editing an unsupported read-only system config file or settling for network_mode: host, but neither is a sure fire solution IMO.

Now I’m trying to use the new socket.AF_BLUETOOTH in Python 3.3. However, I quickly discovered that the python base images are not compiled with bluetooth support.

import sysconfig

Outputs ‘0’ - in other words no bluetooth support.

bluetooth.h is provided by libbluetooth-dev so I tried editing the fincm3-python base image and adding libbluetooth-dev to the installed packages prior to python getting installed but it makes no difference. It’s my understanding that you must compile python from source to enable bluetooth support.

Probably something like:

# install bluetooth headers
apt-get install libbluetooth-dev
# configure python and make
CFLAGS=-I/usr/include/bluetooth ./configure

will do the trick.

Is there a reason why this isn’t included in the current python images?
Can we get this feature?



We have a project called balena-sound which has a service for bluetooth audio. You can check the docker compose file for that here - https://github.com/balenalabs/balena-sound/blob/master/bluetooth-audio/Dockerfile.template

In that you’ll see we do some UDEV handling for bluetooth devices. Would that be something that also works for you here?

Hey Anuj,

Thanks for the quick response. I checked out the balena-sound UDEV stuff and it seems like a lot of work just to talk to a bluetooth device? My base case is to be able to use bluetooth as a serial device for simple byte data transfer. It seems like a lot of overhead to have to create all of the UDEV rules and talk to dbus even.

Is there a more straightforward way to use a BT/serial device on the Fin+CM3?


Could you please give us more details about your project for a better understanding so we can help you?

  • Do you want to transfer data between (Arduino Bluetooth module) and (Fin + CM3L) using Bluetooth?
  • Do you want to talk to the BT device from a container?
  • Have you explored the route of bluetoothctl?
  • What dead ends have you encountered with PyBluez?

Yes, over a BT serial connection.


bluetoothctl was helpful for initial setup and pairing but it’s not a programmatic solution, I don’t think

I gave up when there was a requirement to edit a system config file to put bluetoothd in compatibility mode. I can’t remember which file but I wasn’t sure how to persist that change across container restarts and whether there were other impacts from changing that file.

I ended up writing a small C program that uses sockets / AF_BLUETOOTH, which is the same API that Python wraps, and then piping the data into redis for my other python containers to consume.

The problem that I’m specifically seeing is that none of the Python builds properly recognize the presence of bluez/bluetooth.h and therefor you can’t using AF_BLUETOOTH sockets in Python.


Hi, glad it works for you with sockets and AF_BLUETOOTH.

We agree there is a lack of a good example how to organize BT communication between devices and plan to work on it. This thread will be updated once we have something to present.

Meanwhile, if you can share your example in C, it will be highly appreciated.