Bluetooth binding 3.0.0, OpenHAB3, docker, RPi4

I’m on a RPi 4, 2mb memory - just migrating from openhab 2.5.9 to openhab 3.0.0 and switching from a openhabian based setup to a docker based setup.

I started rebuilding from scratch (switching from a file based setup to a setup configured within the web interface) and I’m on RaspiOS lite: 2021-01-11-raspios-buster-armhf-lite.zip, and Docker version 20.10.2, build 2291f61 - Openhab3 image is pulled as the latest from docker hub.

Openhab 3.0.0 docker image works fine, is configured to run in network mode “host”, wifi devices is found by the correct bindings, zwave and zigbee usb sticks working fine after adding the USB devices to the container

But I have not found any working way of making the Rpi’s built-in bluetooth work - I’ve also tried with the cotainer in privileged mode.

running “hcitool dev” at the host returns the mac address of hci0
There’s no hcitool inside the openhab image from docker hub

I’ve be trying to add a bluetooth bridge as “Bluetooth BlueZ adapter” - manually specifying the MAC adress retrieved from “hcitool dev” at the host, but always get communication error.
I have the same problem when trying to do the same in a docker image of “openhab 2.5.9”

Anyone know how to solve this issue? - I’m already running the container in “host” mode, and privileged mode does not make any difference.

Regards

Maybe you can get it working if you first install the bluez package into the container.

That’s the package providing that command, see:

https://packages.debian.org/search?searchon=contents&keywords=hcitool&mode=path&suite=stable&arch=any

It’s 70+ MB so probably not a good idea to install by default into the container for everyone.

You can add a script to install it on startup, or create your own image based on the openHAB images so it is installed. :slight_smile:

I can install bluez and bluetooth into the container with

apt install bluez bluetooth

and after that scanning devices from the shell inside the container works fine, eg

hcitool lescan

But seems like DBus is missing inside the container for bluetooth binding to work

2021-01-30 11:47:52.999 [WARN ] [th.bluez.internal.BlueZBridgeHandler] - Unknown exception
java.util.concurrent.CompletionException: org.freedesktop.dbus.exceptions.DBusException: Failed to connect to bus: No such file or directory
at java.util.concurrent.CompletableFuture.encodeThrowable(CompletableFuture.java:331) ~[?:?]
at java.util.concurrent.CompletableFuture.completeThrowable(CompletableFuture.java:346) ~[?:?]
at java.util.concurrent.CompletableFuture$UniCompose.tryFire(CompletableFuture.java:1063) ~[?:?]
at java.util.concurrent.CompletableFuture.postComplete(CompletableFuture.java:506) ~[?:?]
at java.util.concurrent.CompletableFuture.completeExceptionally(CompletableFuture.java:2088) ~[?:?]
at org.openhab.binding.bluetooth.util.RetryFuture$CallableTask.run(RetryFuture.java:76) ~[?:?]
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515) [?:?]
at java.util.concurrent.FutureTask.run(FutureTask.java:264) [?:?]
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:304) [?:?]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128) [?:?]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628) [?:?]
at java.lang.Thread.run(Thread.java:834) [?:?]

Maybe you can try this approach:

It seems to be an issue with a lot of info on this topic. :slight_smile:

For accessing bluez, openhab seems to rely on dbus.
So you need to have a dbus deamon accessible for openhab.
Instead of setting up dbus within docker i just mounted another volume to my container.

/var/run/dbus/system_bus_socket:/var/run/dbus/system_bus_socket

Maybe this works for you

Hi I have try to configure the container like indicated:

But I have the same problem.
By openhab I can’t able to use bluetooth

The error is:
org.freedesktop.dbus.exceptions.DBusException: Failed to connect to bus: Failed to auth*emphasized

Here the docker configuration:

sudo docker run --name openhab
-v /etc/localtime:/etc/localtime:ro
-v /etc/timezone:/etc/timezone:ro
-v /opt/openhab/conf:/openhab/conf
-v /opt/openhab/userdata:/openhab/userdata
-v /opt/openhab/addons:/openhab/addons
-v /etc/firmware/:/etc/firmware/:ro
-v /var/run/dbus/system_bus_socket:/var/run/dbus/system_bus_socket
-d
–privileged
–network=host
–restart=unless-stopped
openhab/openhab

I haven’t solved this yet …

Isn’t bluetooth stuff based on dbus binding to bluez objects? If so it should be sufficient to mount dbus socket within docker.

I’ve tried to bind /var/run/dbus/system_bus_socket to /var/run/dbus/system_bus_socket inside the container (rw mode) and also running the container in privileged mode - still I’m not able to use bluez and the pi4s native BT adapter - i’ve even tried installing bluez inside the conatiner in my previous attempts to make this work…