1

I am currently trying to create a script to connect a Bluetooth printer to my raspberry device using CLI commands. So far I have tried using bluetoothctl but it freezes/crashes whenever I try to connect. Here are the steps I've been doing:

First, I search for the device's MAC address.

pi@raspberrypi:~ $ hcitool scan
Scanning ...
    66:22:EA:B3:EA:18   BlueTooth Printer

Then, I open bluetoothctl command and try to pair/connect with the device.

pi@raspberrypi:~ $ sudo bluetoothctl 
[bluetooth]# agent on
Agent is already registered
[bluetooth]# scan on
[...]
[bluetooth]# pair 66:22:EA:B3:EA:18
Attempting to pair with 66:22:EA:B3:EA:18
[CHG] Device 66:22:EA:B3:EA:18 Connected: yes
[CHG] Device 66:22:EA:B3:EA:18 Connected: no
Failed to pair: org.bluez.Error.AlreadyExists # it was paired before, but if I pair them for the first time the device won't be connected.
[bluetooth]# connect 66:22:EA:B3:EA:18
Attempting to connect to 66:22:EA:B3:EA:18
[CHG] Device 66:22:EA:B3:EA:18 Connected: yes
Connection successful
Agent unregistered
[DEL] Controller B8:27:EB:D7:52:CA raspberrypi [default]
[bluetooth]# 

In the end, I received this Bluetooth empty prompt that is frozen. If I enter bluetoothctl again I still can't enter any command. The only way to make it responsive is to restart the Bluetooth service.

sudo service bluetooth restart

I have used journalctl -f -u bluetooth.service and sudo btmon to read the logs:

pi@raspberrypi:~ $ sudo btmon
Bluetooth monitor ver 5.50
= Note: Linux version 5.4.79+ (armv6l)                                 0.945328
= Note: Bluetooth subsystem version 2.22                               0.945347
= New Index: B8:27:EB:D7:52:CA (Primary,UART,hci0)              [hci0] 0.945356
= Open Index: B8:27:EB:D7:52:CA                                 [hci0] 0.945362
= Index Info: B8:27:EB:D7:52:CA (Broadcom Corporation)          [hci0] 0.945369
@ MGMT Open: bluetoothd (privileged) version 1.14             {0x0001} 0.945377
@ MGMT Open: btmon (privileged) version 1.14                  {0x0002} 0.945534

pi@raspberrypi:~ $ journalctl -f -u bluetooth.service
-- Logs begin at Thu 2021-01-14 20:17:02 GMT. --
Jan 16 12:52:11 raspberrypi systemd[1]: Starting Bluetooth service...
Jan 16 12:52:12 raspberrypi bluetoothd[7535]: Bluetooth daemon 5.50
Jan 16 12:52:12 raspberrypi systemd[1]: Started Bluetooth service.
Jan 16 12:52:12 raspberrypi bluetoothd[7535]: Starting SDP server
Jan 16 12:52:12 raspberrypi bluetoothd[7535]: Bluetooth management interface 1.14 initialized
Jan 16 12:52:12 raspberrypi bluetoothd[7535]: Sap driver initialization failed.
Jan 16 12:52:12 raspberrypi bluetoothd[7535]: sap-server: Operation not permitted (1)
Jan 16 12:52:12 raspberrypi bluetoothd[7535]: Failed to set privacy: Rejected (0x0b)
Jan 16 12:52:12 raspberrypi bluetoothd[7535]: Endpoint registered: sender=:1.27 path=/MediaEndpoint/A2DPSource
Jan 16 12:52:12 raspberrypi bluetoothd[7535]: Endpoint registered: sender=:1.27 path=/MediaEndpoint/A2DPSink

If I modify from the file /etc/systemd/system/bluetooth.target.wants/bluetooth.service the line containing ExecStart by adding --noplugin=sap, after reloading daemon and Bluetooth my raspberry will not scan any Bluetooth device.

ExecStart=/usr/lib/bluetooth/bluetoothd --noplugin=sap
judge
  • 11
  • 1

0 Answers0