bluetooth no devices inside container


I am trying to scan for bluetooth devices in my application using btmgmt. On runing the command inside the container:

btmgmt find |grep rssi |sort -n |uniq -w 10

all I get is:

Unable to open socket

I found this thread where it says that in multicontainer setup, the container using bluetooth must be set to network_mode: host . So I did that, but after updating the application running hcitool dev returns only:

root@5dd2aa0:/usr/src/app hcitool dev

btmgmt doesn’t complain any more, but it doesn’t find anything.
Running hcitool dev in the host os also returns the same empty list of devices.

I have the UART enabled in the device configuration (if this is even relevant). The application is running on raspberry pi 3 coupled with the Monarco HAT. As far as I know, rpi 3 supports bluetooth. Do I need enable bluetooth explicitly as is the case for the raspbian image? (where you need to uncomment dtoverlay=pi3-disable-bt in boot/config.txt)


Bluetooth should be enabled by default. How exactly did you enable UART? There is some collision between UART and BT if I remember correctly.

Maybe you need the miniuart-bt overlay. Setting Overlays is documented here Advanced boot settings - Balena Documentation

UART is enabled via device configuration screen on balena dashboard (Enable / Disable UART option). The strange thing is that on the other device with the same codebase, but with the different base os ( balenaOS 2.53.9+rev1 ) everything works without problems. Current version of balenaOS (where things don’t work) is balenaOS 2.77.0+rev1.
I will try to set the miniuart-bt overlay in the higher version of balena os and report the results, hopefully this solves the issue.


I tried with the miniuart-bt overlay, but unfortunately it still doesn’t work:

root@5dd2aa0:/usr/src/app hcitool dev

The same thing happens if I run the command in the Host OS.

Is there some fix for this in the newer versions ob BalenaOS? Most of our devices are on 2.77 version. Otherwise the only solution I see right now is for us to downgrade the entire fleet.

It seems that the tool you are using is simply not supported anymore: "hcitool scan" does not return any results · Issue #128 · balena-os/balena-edison · GitHub

Generally we advice use of bluetooth via Bluez which also works from within the container of you set the io.balena.features.dbus=1 label

for scanning I am using btmgmt find command, is this also deprecated? Because it also returns an error:

root@5dd2aa0:/usr/src/app btmgmt find
Unable to start discovery. status 0x11 (Invalid Index)

Here is my docker-compose file, I am already using the io.balena.features.dbus=1 label:

version: '2'

    privileged: true
    build: ./app
    restart: always
        - "keystore:/keystore"
      io.balena.features.supervisor-api: '1'
      io.balena.features.dbus: '1'
      io.balena.features.kernel-modules: '1'
      - 'DBUS_SYSTEM_BUS_ADDRESS=unix:path=/host/run/dbus/system_bus_socket'
    network_mode: 'host'

Hey @VidGenI it looks like you are trying to use bluetooth from HostOS (as the raspbian app was doing) is that correct?

We are working in order to solve this with DBUS and BLUEZ services.

I will ping a colleague to try to help you!

Hey there!

What’s your use case for scanning bluetooth devices please? Are you looking to pair devices?

I’m asking because I have a colleague who developed bluetooth block. If you want to know more about blocks, you can read this

Anyway, maybe we can use some code snippets from the bluetooth block to figure out what is going on? Hopefully it is not a uart and bt collision.

Can you try running btmgmt --index hci0 find ?

If hci0 is not available, perhaps you can run

# Get available interfaces
HCI_INTERFACES=$(btmgmt info | awk 'BEGIN { ORS=" " }; /^ *hci/ {gsub(":", ""); print $1}')
echo "Available HCI interfaces: "${HCI_INTERFACES[@]}

to find available interfaces?

Hope this is helpful. You can look at bluetooth block source code and see how btgmt is used.


sorry for the late reply.
All I need to do is scan the MAC of the nearby BLE devices and show their rssi (inside the container). I don’t need to connect to any of them.
I tried runing btmgmt --index hci0 find:

root@5dd2aa0:/usr/src/app  btmgmt --index hci0 find 
Unable to start discovery. status 0x11 (Invalid Index)

Running the other thing gives me:

root@5dd2aa0:/usr/src/app HCI_INTERFACES=$(btmgmt info | awk 'BEGIN { ORS=" " }; /^ *hci/ {gsub(":", ""); print $1}')
root@5dd2aa0:/usr/src/app FS=' ' read -r -a HCI_INTERFACES <<< "$HCI_INTERFACES"
root@5dd2aa0:/usr/src/app echo "Available HCI interfaces: "${HCI_INTERFACES[@]}
Available HCI interfaces:

I also ran the command in the single line, just in case if the copying and pasting corrupted the command:

root@5dd2aa0:/usr/src/app HCI_INTERFACES=$(btmgmt info | awk 'BEGIN { ORS=" " }; /^ *hci/ {gsub(":", ""); print $1}') FS=' ' read -r -a HCI_INTERFACES <<< "$HCI_INTERFACES"
root@5dd2aa0:/usr/src/app echo "Available HCI interfaces: "${HCI_INTERFACES[@]}
Available HCI interfaces:

Running the same command on the same hardware but with a different base os version works normally:

root@7566fa4:/usr/src/app btmgmt --index hci0 find
Discovery started
hci0 type 7 discovering on
hci0 type 7 discovering off

Hi Vid, I have pinged some our OS folks to have a look, to ensure we haven’t accidentally introduced a bug somewhere along the way. It might be next week before they see the ping however, just FYI.

Hey @vidgeni, I tried the btmgmt --index hci0 find on my raspberrypi3 at 2.53, and then upgraded to 2.77, and it worked the same in both cases.

Have you tried without the Monarco HAT connected? Are there any configuration differences between the two devices you are testing with?