nicokaiser / rpi-audio-receiver

Raspberry Pi Audio Receiver with Bluetooth A2DP, AirPlay 2, and Spotify Connect
MIT License
1.39k stars 148 forks source link

connection dropping #71

Closed cvdwl closed 4 years ago

cvdwl commented 4 years ago

First: many thanks for this repo! I went through many iterations of blindly fumbling at StackOverflow suggestions before landing here. I'm basically Linux capable, but the dark inner workings of Pulse, Alsa, and various flavors of Bluetooth are way out of my wheelhouse.

Disclaimer aside; when I try to connect or reconnect my Moto X4 as a BT sound source, sometimes it works, and sometimes it goes into a drop and reconnect cycle. The only obvious logs I could find are (note, host and BT id obfuscated):

/var/log/auth.log:Sep 22 08:15:12 foo systemd-logind[327]: Watching system buttons on /dev/input/event0 (01:23:45:67:89:0A)
/var/log/auth.log:Sep 22 08:15:22 foo systemd-logind[327]: Watching system buttons on /dev/input/event0 (01:23:45:67:89:0A)
/var/log/auth.log:Sep 22 08:15:38 foo systemd-logind[327]: Watching system buttons on /dev/input/event0 (01:23:45:67:89:0A)
/var/log/auth.log:Sep 22 08:15:53 foo systemd-logind[327]: Watching system buttons on /dev/input/event0 (01:23:45:67:89:0A)
/var/log/daemon.log:Sep 22 08:15:09 foo bt-agent[318]: Device: Mort (01:23:45:67:89:0A) for UUID 0000110d-0000-1000-8000-1234567890ab
/var/log/daemon.log:Sep 22 08:15:09 foo bluetoothd[459]: /org/bluez/hci0/dev_D0_04_01_3A_91_2B/fd3: fd(22) ready
/var/log/daemon.log:Sep 22 08:15:12 foo systemd-udevd[2898]: Process '/usr/sbin/th-cmd --socket /var/run/thd.socket --passfd --udev' failed with exit code 1.
/var/log/daemon.log:Sep 22 08:15:18 foo bt-agent[318]: Device: Mort (01:23:45:67:89:0A) for UUID 0000110d-0000-1000-8000-1234567890ab
/var/log/daemon.log:Sep 22 08:15:18 foo bluetoothd[459]: a2dp-source profile connect failed for 01:23:45:67:89:0A: Device or resource busy
/var/log/daemon.log:Sep 22 08:15:18 foo bluetoothd[459]: Reconnecting services failed: Device or resource busy (16)
/var/log/daemon.log:Sep 22 08:15:22 foo systemd-udevd[2909]: Process '/usr/sbin/th-cmd --socket /var/run/thd.socket --passfd --udev' failed with exit code 1.
/var/log/daemon.log:Sep 22 08:15:34 foo bluetoothd[459]: connect error: Connection refused (111)
/var/log/daemon.log:Sep 22 08:15:34 foo bt-agent[318]: Device: Mort (01:23:45:67:89:0A) for UUID 0000110d-0000-1000-8000-1234567890ab
/var/log/daemon.log:Sep 22 08:15:38 foo systemd-udevd[2928]: Process '/usr/sbin/th-cmd --socket /var/run/thd.socket --passfd --udev' failed with exit code 1.
/var/log/daemon.log:Sep 22 08:15:48 foo bluetoothd[459]: connect error: Connection refused (111)
/var/log/daemon.log:Sep 22 08:15:49 foo bt-agent[318]: Device: Mort (01:23:45:67:89:0A) for UUID 0000110d-0000-1000-8000-1234567890ab
/var/log/daemon.log:Sep 22 08:15:53 foo systemd-udevd[2942]: Process '/usr/sbin/th-cmd --socket /var/run/thd.socket --passfd --udev' failed with exit code 1.
/var/log/kern.log:Sep 22 08:15:11 foo kernel: [63356.142943] input: 01:23:45:67:89:0A as /devices/virtual/input/input4
/var/log/kern.log:Sep 22 08:15:21 foo kernel: [63366.393836] input: 01:23:45:67:89:0A as /devices/virtual/input/input5
/var/log/kern.log:Sep 22 08:15:37 foo kernel: [63382.155195] input: 01:23:45:67:89:0A as /devices/virtual/input/input6
/var/log/kern.log:Sep 22 08:15:52 foo kernel: [63397.151423] input: 01:23:45:67:89:0A as /devices/virtual/input/input7

...

/var/log/daemon.log:Sep 22 08:18:07 foo bluetoothd[459]: connect error: Host is down (112)
/var/log/daemon.log:Sep 22 08:18:14 foo bluetoothd[459]: connect error: Host is down (112)
/var/log/daemon.log:Sep 22 08:18:23 foo bluetoothd[459]: connect error: Host is down (112)
/var/log/daemon.log:Sep 22 08:18:36 foo bluetoothd[459]: connect error: Host is down (112)
/var/log/daemon.log:Sep 22 08:18:43 foo bt-agent[318]: Device: Mort (01:23:45:67:89:0A) for UUID 0000110d-0000-1000-8000-1234567890ab
/var/log/daemon.log:Sep 22 08:18:46 foo systemd-udevd[3143]: Process '/usr/sbin/th-cmd --socket /var/run/thd.socket --passfd --udev' failed with exit code 1.

Rebooting the phone (after input7 ) allowed a reconnect.

pi@foo:~> neofetch
  `.::///+:/-.        --///+//-:``    pi@foo 
 `+oooooooooooo:   `+oooooooooooo:    ---------- 
  /oooo++//ooooo:  ooooo+//+ooooo.    OS: Raspbian GNU/Linux 10 (buster) armv7l 
  `+ooooooo:-:oo-  +o+::/ooooooo:     Host: Raspberry Pi 3 Model B Plus Rev 1.3 
   `:oooooooo+``    `.oooooooo+-      Kernel: 5.4.51-v7+ 
     `:++ooo/.        :+ooo+/.`       Uptime: 17 hours, 58 mins 
        ...`  `.----.` ``..           Packages: 575 (dpkg) 
     .::::-``:::::::::.`-:::-`        Shell: bash 5.0.3 
    -:::-`   .:::::::-`  `-:::-       Terminal: /dev/pts/0 
   `::.  `.--.`  `` `.---.``.::`      CPU: BCM2835 (4) @ 1.400GHz 
       .::::::::`  -::::::::` `       Memory: 51MiB / 975MiB 
 .::` .:::::::::- `::::::::::``::.
-:::` ::::::::::.  ::::::::::.`:::-                           
::::  -::::::::.   `-::::::::  ::::
-::-   .-:::-.``....``.-::-.   -::-
 .. ``       .::::::::.     `..`..
   -:::-`   -::::::::::`  .:::::`
   :::::::` -::::::::::` :::::::.
   .:::::::  -::::::::. ::::::::
    `-:::::`   ..--.`   ::::::.
      `...`  `...--..`  `...`
            .::::::::::
             `.-::::-`

I realize this is likely a driver/hardware issue (possibly on the phone side) but would welcome any guidance.

Thanks again for this. In general it works really well!

nicokaiser commented 4 years ago

Hello @cvdwl! Two questions,

  1. Does it work at all? So, can you play music from your phone to the Raspi (at least for some time until the connection drops)?
  2. Which Bluetooth hardware do you use? A Bluetooth USB dongle or the internal one of the Raspi?

In case it does work sometimes it seems more like a hardware issue, and if you use the Raspi 3 Bluetooth chip, you might consider getting a cheap USB Bluetooth dongle. The internal Bluetooth of the Raspberry Pi (all models) is very limited and unstable, especially when using audio. For some people it works slightly better when disabling Wi-Fi (at least while a BT device is connected, see /usr/local/bin/bluetooth-udev how to achieve this), but all in all it's not fun at all.

JasonLG1979 commented 4 years ago

Disable the triggerhappy service and see if that helps.

nicokaiser commented 4 years ago

Closed due to inactivity.

cvdwl commented 3 years ago

Sorry, was offline for a while. The problem appears to be much deeper than mentioned. One app (Radio Paradise) on one phone (Moto X4) doesn't work. Basic workarounds exist.

Awbmilne commented 3 years ago

As @nicokaiser Referenced with the Bluetooth/Wifi

I had a similair issue with audio dropping in and out on my Pi Zero. This was due to interferance between the Wifi and Bluetooth on the Pi Zero chip. It was solved by allowing the Bluetooth Module to Disable Wifi when a device is connected over bluetooth. This has worked for me so far and hasnt gotten stuck with Wifi disabled or had audio dropout.

This issue is referenced in the README: Limitations Section\ NicoKaiser Casually added a solution to this in d6d6c17e7cd267e32d0f0bc6743350a173d4dd45

The solution (at least for me) is to uncomment 2 lines in the Bluetooth install script:

These were intentionally left for this purpose. Then reinstall.

If you dont want to reinstall, just edit the config file /usr/local/bin/bluetooth-udev\ Uncomment lines 9 and 14