45

Bluetooth earphones work fine until sleep. After resuming from sleep however, they appear to connect for a brief moment before disconnecting. On blueman, the error given is Resource temporarily unavailable. This issue arose only after updating to 18.04 LTS.

Here's the terminal output for lsusb:

Bus 001 Device 002: ID 8087:8001 Intel Corp. 
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 003 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 002 Device 004: ID 1bcf:0002 Sunplus Innovation Technology Inc. 
Bus 002 Device 003: ID 04f2:b477 Chicony Electronics Co., Ltd 
Bus 002 Device 002: ID 0a5c:21f1 Broadcom Corp. HP Portable Bumble Bee
Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
  • 3
    I have the same issue with JBL Go speaker and a fresh install of 18.04. Nothing like restarting bluetooth.service or removing btusb module and reinserting it again worked. I had to reboot. – solsTiCe May 14 '18 at 17:11
  • I have the same problem, whenever resuming from sleep there is a chance ubuntu acts like there is no bluetooth at all (hence why restarting the service doesn't work). Sleeping and resuming again solves it sometimes. – VFreguglia May 15 '18 at 23:16
  • @K7AAY for some reason hibernate doesn't work at all, so I can't verify that. – Nikhil Sadasivan May 16 '18 at 06:18
  • Please edit to include results from terminal for lsusb – Jeremy31 May 16 '18 at 11:30
  • Same problem here. I have to reboot to get the speakers working again. – DarrenRhodes May 17 '18 at 12:56

9 Answers9

35

update bluez to >=5.28.2

18.04 ships with a buggy bluez package for now; newer version is available from this PPA: https://launchpad.net/~bluetooth/+archive/ubuntu/bluez:

sudo add-apt-repository ppa:bluetooth/bluez
sudo apt install bluez

workaround for buggy Bluetooth applet (Unity specific?)

This is probably the issue @solstice mentioned - BT menu applet doesn't let me enable Bluetooth after resuming from sleep. No matter if the toggle switch is off or on, the BT icon is disabled, and rfkill output doesn't change:

$ rfkill list
0: phy0: Wireless LAN
    Soft blocked: no
    Hard blocked: no
12: hci0: Bluetooth
    Soft blocked: no
    Hard blocked: no

You can toggle BT manually by running (substitute your own ID):

rfkill block 12
rfkill unblock 12

and BT applet should pick it up correctly now. At this point, you should be able to connect to your devices. For now I've hacked it together using a script that does this automatically after resume:

$ cat /lib/systemd/system-sleep/bt
#!/bin/sh

case $1 in
  post)
    sleep 5
    rfkill block `rfkill list | grep hci | cut -d: -f1`
    sleep 1
    rfkill unblock `rfkill list | grep hci | cut -d: -f1`
    ;;
esac

The ID number next to hci0 in rfkill list output seems to increment after every suspend/resume. Disabling/enabling BT using the BT menu should change the output ('soft blocked: yes' for BT disabled via menu), but it doesn't. My guess is that the applet remembers the wrong device ID and is thus trying to enable a device that no longer exists.

17

For me this problem can be resolved by running

sudo service bluetooth restart

after waking from sleep

trts
  • 181
16

I run 19.04 and have this issue. I have a BT mouse so it really is annoying.

To enhanced @hinxnz answer:

Open an new file:

sudo nano /lib/systemd/system-sleep/bt

Paste in this script:

#!/bin/sh

case $1 in
  post)
    modprobe -r btusb
    sleep 1
    service bluetooth restart
    sleep 1
    modprobe btusb
    ;;
esac

An finally make it executable

chmod +x /lib/systemd/system-sleep/bt
Laurent
  • 616
3

Try in a terminal (no root needed)

btnum=`rfkill list|grep hci0| cut -f 1 -d ':'`
rfkill block $btnum
rfkill unblock $btnum

This might be related to a bug in gnome-control-center. Not sure. I have found this to work around that said bug and may be yours too.

solsTiCe
  • 9,231
2

This is what i did to get it working on 18.04 LTS

Updated bluetooth:

sudo add-apt-repository ppa:bluetooth/bluez
sudo apt install bluez

Create new file:

sudo nano /lib/systemd/system-sleep/bt

Write and save:

#!/bin/sh

modprobe -r btusb sleep 1 service bluetooth restart sleep 1 modprobe btusb

Changed permissions:

sudo chmod +x /lib/systemd/system-sleep/bt
hinxnz
  • 29
  • 1
    Using chmod +x would be a safer solution if you just want to make this executable. Doing this would allow any user on the system to run anything as root just by replacing the contents of this file. – Steeve McCauley Mar 29 '19 at 13:48
  • after saving this script, my Dell XPS (18.04lts) won't go to sleep. it looks like it goes to sleep and 2sec later wakes up, and that's it. – razor Apr 10 '19 at 06:56
  • Don't chmod 777, ever. Unless you know exactly what you are doing. You should wrap that script with case $1 in post) so it only run after wakeup. Also sudo is not needed in the script. – Laurent May 28 '19 at 05:54
0

Based on this answer, for pulseaudio & Ubuntu 18

sudo apt-get install pulseaudio-module-bluetooth
pactl load-module module-bluetooth-discover
0

For me changing bluetooth adapter to another USB port helped. A moment after waking up I heard that headset disconnect. My front panel USB has short power off time during the waking up and it disconnect and remove devices.

-1

The solution of upgrading to a newer version of bluez solved another problem for me of bluetooth connections disconnecting seconds after connecting, as described here: Ubuntu 18.04: Bluetooth device disconnects right after connect on Lenovo P50

Maarten
  • 692
  • 1
  • 6
  • 20
-1

In my case, laptop-mode-tools was the culprit:

$ sudo apt remove laptop-mode-tools

kolypto
  • 611
  • Please do not post the same answer to many posts. Instead, if the posts are similar enough to each other, flag the other posts as duplicates of one of the other ones. Simply reposting the same answer to multiple questions is very noisy. – Thomas Ward Dec 02 '19 at 13:54