Enable Bluetooth

Hi, I need to enable Bluetooth on my dietpi (rpi 4) in order to expose a bluetooth device, how can I do so? I have it enabled in the advanced settings, but I don’t think it’s working. Here’s the logs:

root@DietPi:~# journalctl -u bluetooth -u hciuart
-- Journal begins at Fri 2022-09-02 16:24:25 BST, ends at Fri 2022-09-02 16:25:33 BST. --
Sep 02 16:24:26 DietPi systemd[1]: Starting Configure Bluetooth Modems connected by UART...
Sep 02 16:24:33 DietPi btuart[454]: bcm43xx_init
Sep 02 16:24:33 DietPi btuart[454]: Flash firmware /lib/firmware/brcm/BCM4345C0.hcd
Sep 02 16:24:33 DietPi btuart[454]: Set Controller UART speed to 3000000 bit/s
Sep 02 16:24:33 DietPi btuart[454]: Device setup complete
Sep 02 16:24:33 DietPi systemd[1]: Started Configure Bluetooth Modems connected by UART.
Sep 02 16:24:33 DietPi systemd[1]: Starting Bluetooth service...
Sep 02 16:24:33 DietPi bluetoothd[831]: Bluetooth daemon 5.55
Sep 02 16:24:33 DietPi systemd[1]: Started Bluetooth service.
Sep 02 16:24:33 DietPi bluetoothd[831]: Starting SDP server
Sep 02 16:24:33 DietPi bluetoothd[831]: Bluetooth management interface 1.21 initialized
Sep 02 16:24:33 DietPi bluetoothd[831]: profiles/sap/server.c:sap_server_register() Sap driver initialization failed.
Sep 02 16:24:33 DietPi bluetoothd[831]: sap-server: Operation not permitted (1)
Sep 02 16:24:34 DietPi bluetoothd[831]: Failed to set privacy: Rejected (0x0b)

This is maybe related to this: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=803265

Workaround ideas:

Starting bluetoothd with the option “–noplugin=sap” by default (as
already suggested) would be one way to do it. Another way would be to
patch the bootstrap-configure file in the source root directory, to
change --enable-sap to --disable-sap.

Option 1 is to go into dietpi-services, select the bluetooth service and hit the edit button.
Then you search in the [Service] section for the line which begins with #ExexStart= (be carefull, there are also maybe some ExexStartPre and ExexStartPost statements, but you need just ExexStart=. I have no time now to have a look into the actual service.config, it’s probably something like #ExecStart=/usr/libexec/bluetooth/bluetoothd)

Delete the # and add at the end of this line --noplugin=sap.
Also, add one line above ExecStart=, now you are left withsomething like:

ExecStart=
ExecStart=/usr/libexec/bluetooth/bluetoothd --noplugin=sap

Save and close the file and restart the bluetooth service and see what happens now.

I don’t have the bluetooth service in the dietpi-services but bluetooth seems to be working, when I run bluetoothctl.

I enabled bluetooth by going to advanced settings in the dietpi-config. What am I missing?

Do you try maybe to stream music/audio via bluetooth?

No, I’m just trying to enable it in order to get it to pair with an accessory (blinds motor) to later control with Node-Red.

Edit: I was able to pair it with devices (using bluetoothctl pair [mac address] and it worked. But for example, in NR, the device doesn’t show up when running the “scan bluetooth” option. They have in the docs to run

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

in order to disable sudo for it, however, even after doing it, it doesn’t show up there.

I suspect something could be wrong with my Bluetooth configuration of the device. It’s even weird that it doesn’t show up in the dietpi-services.

Alright I had now time to try this by myself on my RPi 4.
The service file is at /etc/systemd/system/bluetooth.target.wants/bluetooth.service. Edit the file and add the --noplugin=sap at the end of the ExecStart= line. This time it’s not needed to put another ExecStart in front.

Reload the service with

sudo systemctl daemon-reload && sudo service bluetooth restart

I can now scan and pair with bluetoothctl.

@Jappe was bluetoothd service failing for your as well before doing the change?

The service itself way running, with the same error message like the OP. I could also run bluetoothctl but was not able to find/ pair any device.

@Jappe after doing so, I got rid of one error, then, I have this line (last one) saying that privacy is rejected:

● bluetooth.service - Bluetooth service
     Loaded: loaded (/lib/systemd/system/bluetooth.service; enabled; vendor preset: enabled)
     Active: active (running) since Mon 2022-09-05 10:19:18 BST; 9s ago
       Docs: man:bluetoothd(8)
   Main PID: 37673 (bluetoothd)
     Status: "Running"
      Tasks: 1 (limit: 4531)
        CPU: 46ms
     CGroup: /system.slice/bluetooth.service
             └─37673 /usr/libexec/bluetooth/bluetoothd --noplugin=sap

Sep 05 10:19:18 DietPi systemd[1]: Starting Bluetooth service...
Sep 05 10:19:18 DietPi bluetoothd[37673]: Bluetooth daemon 5.55
Sep 05 10:19:18 DietPi systemd[1]: Started Bluetooth service.
Sep 05 10:19:18 DietPi bluetoothd[37673]: Starting SDP server
Sep 05 10:19:18 DietPi bluetoothd[37673]: Excluding (cli) sap
Sep 05 10:19:18 DietPi bluetoothd[37673]: Bluetooth management interface 1.21 initialized
Sep 05 10:19:18 DietPi bluetoothd[37673]: Failed to set privacy: Rejected (0x0b)

Edit: this solved

hmm we don’t do any magic on bluetooth.service as we just enabled it as is.

@MichaIng
We need to check if some additional steps might be needed to tweak bluetooth.service

It’s just a warning, It appeared too when I tested it but it doesn’t stopped me to comnect bt devices.

But you did enable Bluetooth via dietpi-config advanced options and rebooted right? That should setup everything needed on RPi.

Yes, but a connection was not possible, it couldn’t find any devices.