iTranslated by AI

The content below is an AI-generated translation. This is an experimental feature, and may contain errors. View original article
🤪

Using a Bluetooth Mouse (USB Dongle) on Ubuntu 20.04 (Focal)

に公開

In Ubuntu 20.04, Bluetooth mice do not work with half-hearted measures. They aren't recognized. To be honest, it is incredibly frustrating. Just when you think it's connected, it gets forcibly disconnected 10 seconds later. I tried various things based on posts from Stack Overflow and other sites, but the symptoms only got worse, or in some cases, the dongle stopped being recognized altogether.

After much trial and error, I finally succeeded in getting my Bluetooth mouse to work properly by referring to the following article:
https://askubuntu.com/questions/1090149/bluetooth-mouse-lags-after-upgrading-to-18-10-cosmic/1090150#1090150

The following one was not helpful:
https://askubuntu.com/questions/1235456/issues-with-bluetooth-mouse-in-ubuntu-20-04
And this one was not helpful either:
https://askubuntu.com/questions/1231074/ubuntu-20-04-bluetooth-not-working
The two above may cause symptoms to worsen depending on your environment.

Below, I will summarize in English the method that worked for me. I hope this helps those who are stuck with the same issue.

1. Environment

  • Ubuntu 20.04 x86_64 Desktop PC, no built-in Bluetooth adapter
  • Bluetooth Mouse + USB Dongle

https://www.amazon.co.jp/gp/product/B0722XWTFR/ref=ppx_yo_dt_b_asin_title_o07_s00?ie=UTF8&psc=1
https://www.amazon.co.jp/gp/product/B017KPZ6LK/ref=ppx_yo_dt_b_asin_title_o00_s00?ie=UTF8&psc=1

2. Procedure

Install and launch the app called powertop.

$ sudo apt install -y powertop
$ sudo powertop

1

Press the Tab key several times to switch to the Tunables tab.
2

Look for your USB dongle device in the list. In my case, it was listed as Autosuspend for USB device USB1.1-A [1-11.2]. If there are multiple items starting with Autosuspend, you can identify the correct one by unplugging the dongle and pressing the R key to refresh the view; the one that disappears is your dongle. Once confirmed, please re-insert the dongle into the USB port.

Now, select Autosuspend for USB device USB1.1-A [1-11.2] using the up and down arrow keys and press Enter. Note that the USB1.1-A part will vary depending on your specific dongle.
3

When you press Enter, the part that said >> Good will toggle to >> Bad. Bad indicates that autosuspend is disabled, while Good indicates it is enabled. The reason the Bluetooth USB dongle was malfunctioning was that it would automatically enter a suspend state, causing the Bluetooth connection to drop frequently. Interestingly, this issue did not occur in Ubuntu 18.04; it feels like a bug in the Ubuntu 20.04 kernel. Confirm that it has switched to Bad. Also, immediately after switching to Bad, copy the command prompt displayed at the top of the console and save it somewhere. You will use it in a later step.

In my environment, it displayed: >> echo 'on' > '/sys/bus/usb/devices/1-11.2/power/control';.
4

Press the Esc key to exit powertop. It may take some time to exit after pressing Esc, so please wait patiently.

Execute the following command to open a blank file:

$ sudo nano /usr/bin/disable-bt-mouse-autosuspend

Enter the following into the opened file, save it, and exit nano. Please replace the 1-11.2 part with the numbers that were displayed immediately before /power in the string you noted earlier. In my case it was 1-11.2, but it will likely be a different set of numbers for you. By the way, to save in nano, press Ctrl + O, and to exit, press Ctrl + X.

#!/bin/sh

# Disable USB auto-suspend for my mouse on startup
sleep 5;
MOUSE="/sys/bus/usb/devices/1-11.2/power/control";
if [ -f "$MOUSE" ]; then
    echo 'on' > $MOUSE;
fi

Next, grant execution permissions to the created script. Run the following command:

$ sudo chmod u+x /usr/bin/disable-bt-mouse-autosuspend

Next, register it as a service with systemd. Execute the following command to open a blank file:

$ sudo nano /etc/systemd/system/disable-bt-mouse-autosuspend.service

Enter the following string, save, and exit nano:

[Unit]
Description=Disable USB auto-suspend for bluetooth mouse

[Service]
ExecStart=/usr/bin/disable-bt-mouse-autosuspend

[Install]
WantedBy=multi-user.target

Next, run the following commands to start and enable the service:

$ sudo systemctl start disable-bt-mouse-autosuspend
$ sudo systemctl enable disable-bt-mouse-autosuspend

Next, create a script to ensure the connection works correctly even after the PC wakes up from suspend. Execute the following command to open a blank file:

$ sudo nano /lib/systemd/system-sleep/00disable-bt-mouse-autosuspend

Enter the following content, save, and exit nano:

#!/bin/sh

# restart the service after suspend
if [ $1 = post ] && [ $2 = suspend ]
then systemctl start disable-bt-mouse-autosuspend.service
fi

Next, run the following command to grant execution permissions to the script:

$ sudo chmod u+x /lib/systemd/system-sleep/00disable-bt-mouse-autosuspend

Finally, restart your computer, and the procedure is complete.

Discussion