2

I have been experimenting with the Bluetooth capability's of the pi and i came across two commands bluetoothd and bluetoothctl.

When i run bluetoothd i get:

pi@raspberrypi:~ $ bluetoothd
D-Bus setup failed: Connection ":1.34" is not allowed to own the service     
"org.bluez" due to security policies in the configuration file
pi@raspberrypi:~ $ sudo bluetoothd
D-Bus setup failed: Name already in use

But when i run bluetoothctl i get:

pi@raspberrypi:~ $ bluetoothctl 
[NEW] Controller B8:27:EB:52:E8:AB raspberrypi [default]
[NEW] Device 00:1D:43:C0:15:D0 Coda Pop
[NEW] Device CC:6D:A0:EB:B6:24 Roku Player
[NEW] Device A4:77:33:3E:10:8F A4-77-33-3E-10-8F
[bluetooth]# 

First: what is the difference between these commands?

Second:why does bluetoothd not work?

  • 1
    I'm having the same issue and my understanding is also shallow. However, bluetoothd is the Bluetooth daemon. That's why you can do systemctl status bluetoothd. bluetoothctl is the primary control tool for Bluetooth devices. – ZX9 Sep 30 '16 at 17:23
  • When you do systemctl status bluetooth, does your bluetooth.service also show as failed? Mine does, but given your different devices connected, I'm assuming that's not the case for you. – ZX9 Sep 30 '16 at 17:26
  • man bluetoothd, man bluetoothctl, unix.stackexchange.com/q/193815/271585 (this is not RPi specific) – Fabian May 16 '18 at 8:43
2

TL;DR

This error means that bluetoothd (the daemon/process) is already running. You can use bluetoothctl (the controller/manager) to connect to a BLE device as normal! :-)

Explanation

Hey there. Also a student of bluetooth here. From my understanding (and from ZX9's comment)...

bluetoothd is called a daemon, or a background process. It is inextricably linked to bluetooth services. bluetoothctl is the main controller/manager, who knows how to use this daemon and these bluetooth services. bluetoothctl exposes human-readable methods and data, which is why we mainly interface with the bluetoothctl. The error "D-Bus setup failed: Name already in use" means that bluetooth is already working just fine! :-)

You can see this by pstree which shows a graphical hierarchy of your daemons like below:

systemd─┬─avahi-daemon───avahi-daemon
        ├─bluetoothd
        ├─cron
        ├─dbus-daemon
        ├─dhcpcd
        ├─hciattach
        ...

Now that we know the bluetooth daemon is running, we can connect to a BLE (Bluetooth Low Energy) device through bluetoothctl. I do not mess with BR/EDR (Classic Bluetooth), but if would appreciate if someone can comment if that works, too!

pi@raspberrypi:~ $ bluetoothctl
Agent registered
[bluetooth]# power on
Changing power on succeeded
[bluetooth]# scan on
Discovery started
[CHG] Controller B8:27:EB:DD:65:21 Discovering: yes
[CHG] Device 34:15:13:87:98:37 RSSI: -61
...
[bluetooth]# connect 34:15:13:87:98:37
Attempting to connect to 34:15:13:87:98:37
[CHG] Device 34:15:13:87:98:37 Connected: yes
Connection successful
[NEW] Primary Service
...
[NEW] Characteristic
...

What happens if bluetoothd is NOT running?

bluetooth services come to a halt, and so does bluetoothctl. Let me first identify my that bluetooth daemon PID = 3614. This PID (process ID, maybe?) will, most likely, be different on your machine.

pi@raspberrypi:~ $ ps aux |grep bluetooth
USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root      3614  0.0  0.9   7176  4096 ?        Ss   01:22   0:00 /usr/libexec/bluetooth/bluetoothd
pi        3842  0.0  0.4   4364  1908 pts/0    S+   01:37   0:00 grep --color=auto bluetooth

Now kill it with either sudo kill 3614 or sudo systemctl stop bluetooth. Prove to yourself it is dead by pstree

systemd─┬─avahi-daemon───avahi-daemon
        ├─cron
        ├─dbus-daemon
        ├─dhcpcd
        ├─hciattach
        ...

See that you cannot connect back to bluetoothctl. The command line hangs at

pi@raspberrypi:~ $ bluetoothctl
Waiting to connect to bluetoothd...

So you have to ctrl+C out. If you want to restart bluetoothd, we are actually not going to call the command sudo bluetoothd. I'm not sure what this accomplishes besides making command line hang. Use sudo bluetooth -d for debugging information if you are curious, but I could not see it doing anything useful for the current question.

To restart bluetoothd, use sudo systemctl start bluetooth or sudo service bluetooth start . To confirm that it's back, you can use pstree , or just bluetoothctl to connect to your devices.

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.