iTranslated by AI
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:
The following one was not helpful: And this one was not helpful either: 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
2. Procedure
Install and launch the app called powertop.
$ sudo apt install -y powertop
$ sudo powertop
Press the Tab key several times to switch to the Tunables tab.
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.
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';.
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