Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Receive "noble warning: adapter state unauthorized" when Homebridge runs in Docker container #48

Closed
mrdc opened this issue Apr 13, 2019 · 11 comments

Comments

@mrdc
Copy link

mrdc commented Apr 13, 2019

Expected Behavior

homebridge-mi-hygrothermograph works fine in Homebridge@Docker container.

Current Behavior

homebridge-mi-hygrothermograph is not working when used inside of Docker container.

Steps to Reproduce (for bugs)

Versions

  • homebridge: 0.4.48
  • homebridge-mi-hygrothermograph: v2.1.0
  • node: 10.15.3
  • OS: LibreELEC 9.0.1

Homebridge Log / Command Output

[4/13/2019, 8:17:12 PM] [Temperature & Humidity] Start scanning.
noble warning: adapter state unauthorized, please run as root or with sudo
               or see README for information on running without root/sudo:
               https://github.com/sandeepmistry/noble#running-on-linux
[4/13/2019, 8:17:12 PM] [Temperature & Humidity] Stop scanning. (unauthorized)
[4/13/2019, 8:17:12 PM] [Temperature & Humidity] Stopped scanning.
[4/13/2019, 8:17:15 PM] [Temperature & Humidity] Start scanning.
[4/13/2019, 8:17:15 PM] [Temperature & Humidity] Error: Could not start scanning, state is unauthorized (not poweredOn)
    at Noble.scan (/homebridge/node_modules/@abandonware/noble/lib/noble.js:97:19)
    at Noble.startScanning (/homebridge/node_modules/@abandonware/noble/lib/noble.js:126:10)
    at Scanner.start (/homebridge/node_modules/homebridge-mi-hygrothermograph/lib/scanner.js:34:13)
    at Timeout.setTimeout [as _onTimeout] (/homebridge/node_modules/homebridge-mi-hygrothermograph/lib/scanner.js:70:14)
    at ontimeout (timers.js:436:11)
    at tryOnTimeout (timers.js:300:5)
    at listOnTimeout (timers.js:263:5)
    at Timer.processTimers (timers.js:223:10)

@hannseman
Copy link
Owner

hannseman commented Apr 15, 2019

How are you running the container? Docker can't access bluetooth on the host by default. I think you might need to pass --net=host and possibly --privileged. Anyway this is not an issue directly related to this plugin but how to run bluetooth related stuff through docker so I'll close this.

@mrdc
Copy link
Author

mrdc commented Apr 15, 2019

I run it like this:

docker run -d --restart=always --net=host \ --name=homebridge \ -v /storage/homebridge:/homebridge \ -e HOMEBRIDGE_CONFIG_UI=1 \ -e HOMEBRIDGE_CONFIG_UI_PORT=8581 \ oznu/homebridge:raspberry-pi

Adding --privileged, makes no difference: "noble warning: adapter state unauthorized, please run as root or with sudo"

@hannseman
Copy link
Owner

You might need to add some capabilities to the container. I use CAP_NET_RAW when running homebridge in systemd to allow access to the bluetooth socket without sudo. You can try to add it with --cap-add=NET_RAW you might also want to try --cap-add=SYS_ADMIN --cap-add=NET_ADMIN.

You can probably find a lot more information by googling for "docker bluetooth" or something like that. Good luck!

@mrdc
Copy link
Author

mrdc commented Apr 16, 2019

I've tried to turn off BT on host (systemctl stop bluetooth) - it helped a little bit - now I see this in logs:

[4/16/2019, 8:49:04 PM] Loaded plugin: homebridge-mi-hygrothermograph
[4/16/2019, 8:49:05 PM] [homebridge-config-ui-x] Console v4.0.0-beta16 is listening on port 8581
[4/16/2019, 8:49:06 PM] Registering accessory 'homebridge-mi-hygrothermograph.Hygrotermograph'
[4/16/2019, 8:49:06 PM] ---
[4/16/2019, 8:49:06 PM] Loaded plugin: homebridge-config-ui-x
[4/16/2019, 8:49:06 PM] Registering platform 'homebridge-config-ui-x.config'
[4/16/2019, 8:49:06 PM] ---
[4/16/2019, 8:49:06 PM] Loading 0 platforms...
[4/16/2019, 8:49:06 PM] Loading 1 accessories...
[4/16/2019, 8:49:06 PM] [Temperature & Humidity] Initializing Hygrotermograph accessory...
[4/16/2019, 8:49:06 PM] [Temperature & Humidity] Stop scanning. (poweredOff)
[4/16/2019, 8:49:06 PM] Homebridge is running on port 51826.

@hannseman
Copy link
Owner

hannseman commented Apr 17, 2019

Can you try running hciconfig hci0 up before starting homebridge?

Some discussion regarding bluetooth in docker can be found here moby/moby#16208

@mrdc
Copy link
Author

mrdc commented Apr 17, 2019

@hannseman
When bluetooth is enabled on host (LibreELEC@Raspberry Pi 3 B+) I receive:

[4/13/2019, 8:17:12 PM] [Temperature & Humidity] Stop scanning. (unauthorized)

When I disable bluetooth on host (systemctl stop bluetooth) I receive this:

[4/16/2019, 8:49:06 PM] [Temperature & Humidity] Stop scanning. (poweredOff)

In case I'll run hciconfig hci0 on host it will enable bluetooth and I will get again:

[4/13/2019, 8:17:12 PM] [Temperature & Humidity] Stop scanning. (unauthorized)

With external bluetooth dongle I receive the same error:

Stop scanning. (unauthorized)

Some discussion regarding bluetooth in docker can be found here moby/moby#16208

Unfortunately :( I've tried everything: like docker run -ti --net=host,docker run -ti --privileged --net=host etc.

@ferdinand
Copy link

ferdinand commented Aug 1, 2019

@mrdc Did you install the noble dependencies via sudo apt-get install bluetooth bluez libbluetooth-dev libudev-dev and run sudo setcap cap_net_raw+eip $(eval readlink -f `which node`) as the suggested by the noble README which is referred to in the log? Of course, both must executed inside the Docker container.

@mrdc
Copy link
Author

mrdc commented Sep 15, 2019

@mrdc Did you install the noble dependencies via sudo apt-get install bluetooth bluez libbluetooth-dev libudev-dev and run sudo setcap cap_net_raw+eip $(eval readlink -f `which node`) as the suggested by the noble README which is referred to in the log? Of course, both must executed inside the Docker container.

Yes, I've fixed it with

sudo setcap cap_net_raw+eip $(eval readlink -f which node)

@plantoschka
Copy link

I have to run "sudo setcap cap_net_raw+eip $(eval readlink -f which node)" after every restart to make bluetooth work. Is there a way to do this automatically in the docker-compose?

@vladtsit
Copy link

vladtsit commented Apr 11, 2021

@plantoschka have you found a way to automate it? To run it after restart?

@plantoschka
Copy link

@plantoschka have you found a way to automate it? To run it after restart?

Unfortunately not.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants