Bluetooth daemon
In the default installation a daemon (bluetoothd) runs in the background (run from the file /etc/init.d/bluetooth
). This daemon takes care on recognizing and connecting to known bluetooth devices and may be cofigured with configuration files in /etc/bluetooth
. For autoconneting a headset the following line in audio.conf
should be uncommented (remove #
):
AutoConnect=true
To restart the daemon type sudo /etc/init.d/bluetooth restart
.
Remark: Using the command line tool sudo hcitool cc <MAC-Adress>
did not lead to a stable connection to a known device in the test environment here when the daemon was running.
DBus
In order to connect a disconnected but physically present and paired headset we can use D-Bus from a script. Here's an example in python:
#!/usr/bin/python
# Toggles headset connection
import dbus
from dbus.mainloop.glib import DBusGMainLoop
dbus_loop = DBusGMainLoop()
bus = dbus.SystemBus(mainloop=dbus_loop)
#Get dbus interface for headset
manager = bus.get_object('org.bluez', '/')
iface_m = dbus.Interface(manager, 'org.bluez.Manager')
adapterPath = iface_m.DefaultAdapter()
adapter = bus.get_object('org.bluez', adapterPath)
iface_a = dbus.Interface(adapter, 'org.bluez.Adapter')
devicePath = iface_a.ListDevices()[0] # assuming first device
device = bus.get_object('org.bluez', devicePath)
iface_h = dbus.Interface(device, 'org.bluez.Headset')
#Check state of connection
connected = iface_h.IsConnected()
print 'Toggling connection. Please wait'
# toggle connection
if not connected:
try:
iface_h.Connect()
print 'Connecting: ', devicePath
except:
print 'Device not found'
else:
iface_h.Disconnect()
print 'Disconnecting: ', devicePath
In case we have more than one Bluetooth device we will have to adapt the devicePath
appropriately, of course. The example above will connect a Headset
. Change the interface to a different protocol for any other service (e.g. AudioSink
).
Pulseaudio
If you know the MAC adress of your Bluetooth device you can connect it as an output sink for pulseaudio by:
pacmd set-default-sink bluez_sink.xx_xx_xx_xx_xx_xx
Where xx_xx_xx_xx_xx_xx is the MAC address (replace ':' by '_' for pulseaudio to recognize it).
See also this answer for more details.
It looks like the underlying problem was similar to the one for this question:
https://stackoverflow.com/questions/31380594/linux-bluez-dbus-communication
Except that I'm running a systemd linux setup so I had to do as the comment on that answer suggested:
With newer Systemd-based systems, copy
/lib/systemd/system/bluetooth.service
to
/etc/systemd/system/bluetooth.service
and change the ExecStart
line to
ExecStart=/usr/lib/bluetooth/bluetoothd -E
.
– Arto Bendiken
So I did that, restarted, and then started bluetoothctl
, and connected manually:
[Bose QuietComfort 35]# connect 04:52:C7:32:68:16
Attempting to connect to 04:52:C7:32:68:16
[CHG] Device 04:52:C7:32:68:16 Paired: yes
Connection successful
This time when I paired, my headphones recognised the connection (they didn't previously, even though GNOME seemed to think the pairing had worked) and the output device appeared in my devices list.
Best Answer
first of all start your Bluetooth from System settings.
Open terminal and type:
then you will see the list of devices you have paired with and their corresponding MAC address. To un-pair a device type:
replace
aa:bb:cc:dd:ee:ff
with the MAC address of the device to un-pair.there is no un-pair commmand