Debug bluetooth in ubuntu

Debug bluetooth in ubuntu

In my PC running Ubuntu (19.04), the bluetooth keyboard occasionally stops working unconditionally. I tried to open system settings, navigate to the bluetooth control, try switching on/off the bluetooth, but the on/off button never responses or it always reflects incorrect status.

In this situation, a soft reset normally allows the bluetooth back to work, but that solution is inelegant. In this post, I will show some commands which you can use to debug your bluetooth adapter and obtain more grain control over the bluetooth driver.

  • For any kernel-related issue, such as (bluetooth) driver, it is always good to watch for system and kernel log.
sudo tail -f /var/log/kern.log
sudo tail -f /var/log/syslog.1
  • To view bluetooth driver log and manipulate the bluetooth adapter interactively, use sudo bluetoothctl. From the command prompt, you can use show, power on, power off to display status, power on/off the adapter. A very detailed log of the bluetooth driver is also streamed to this command prompt console.
    In my case, the show command displays the bluetooth adapter in normal status power off command successfully accomplish its task and shows
Changing power off succeeded

while the power on command failed with the message

Failed to set power on: org.bluez.Error.Blocked
  • The bluetooth driver is controlled by a systemd service named bluetooth which can be supervised with systemctl status/(re)start/stop bluetooth.
    When I tried these commands, the console logs following error
Failed to set mode: Blocked through rfkill (0x12)
  • The error log from systemctl made me notice the rfkill command. To show blocking status, I used sudo rfkill list
0: hci0: Bluetooth
	Soft blocked: yes
	Hard blocked: no
1: phy0: Wireless LAN
	Soft blocked: no
	Hard blocked: no

This result indicates that my bluetooth adapter is soft-blocked. I tried sudo rfkill unblock bluetooth, then the Soft blocked status of the bluetooth changed to no.

After a try to restart the bluetooth service with sudo systemctl restart bluetooth, the bluetooth adapter backed to work normally. Voilà.

  • Note useful in my case but I also used some other commands. For a reference purpose: sudo hcitool dev, sudo hciconfig hci0.

Happy coding!

Buy Me A Coffee