Forum

Full Version: Bluetooth disconnects
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
(18th Feb, 2023 05:28 AM)Nachteule Wrote: [ -> ]
(17th Feb, 2023 07:18 PM)grandcanyon Wrote: [ -> ]The problem is that bluetooth creates a new pulseaudio socket every time it connects since I am seeing a

rfcomm_bind: Address already in use

so bluetooth won't bind to the existing pulseaudio socket

I have the feeling you have completely screwed up your pulseaudio/bluetooth by now

My recommendation: remove everything that has to do with pulseaudio (apt-get purge ...) and start again from scratch
Make sure that the directory /home/xbian/.config/pulse and /etc/pulse do not exist anymore before you reinstall the packages

After reinstall, run the following script as root:
Code:
#!/bin/sh
su xbian -c "mkdir -p -m 0700 /home/xbian/.config/pulse && sed 's/; autospawn = yes/autospawn = yes/g' /etc/pulse/client.conf > /home/xbian/.config/pulse/client.conf
su xbian -c "mkdir -p -m 0700 /home/xbian/.config/pulse && cp /etc/pulse/daemon.conf /home/xbian/.config/pulse"
echo -e "If you need to modify client.conf or daemon.conf, please use\nthe files in folder /home/xbian/.config/pulse" > /etc/pulse/README.XBian
find /etc/rc?.d/ -name S??pulseaudio-enable-autospawn -delete

This will copy daemon.conf and client.conf to the xbian user area and changes have to be made there. Making changes in the orginal conf files I don't think is a very good idea

Thanks for writing the script. I have tried this and it still makes a second instance of pulseaudio and then drops the headphones and kills the second instance of pulseaudio.

I tried it with both dtparam=audio=on commented and uncommented out.

I still have RPiOS Lite on my other card and I am not seeing the same behavior so I am not sure what is different between debian and ubuntu since ubuntu is based on debian.
The problem is that PA is being started by spawning it when Kodi starts. BT needs PA started before it can start so since BT naturally starts before Kodi which starts PA is started , BT is not connected to PA. When you turn on your headphones BT thinks there isn't a PA so it spawns a new one and connects to this which causes the disconnects.

I ended up wrote/found an upstart for pulseaudio and turned off autospawn. The downside is for some reason PA doesn't work with Kodi but once the BT HPs are connected Kodi pipes the audio through the BT HPs without creating a new PA. Since I use PI:HDMI when not using headphones it doesn't matter to me that PA through HDMI has no sound.
In my opinion, you are mistaken here

At least with all my installations this is not the case. I can switch on my BT speakers whenever I want, there is never a new pulseaudio instance started. That would be totally absurd too

Here it works like this:

1) bluez is started long before Kodi and pulseaudio.
2) when Kodi starts, the PA libraries cause the pulseaudio daemon to be loaded
3) at some point I can turn on the BT speakers, they are then properly integrated

No respawn of pulseaudio daemon or whatever

I have no idea anymore why this should not work for you
Other people saw multiple instances of PA with xbian

http://forum.xbian.org/thread-3549-post-31969.html#pid31969

I am not sure why we are seeing this and you are not, assuming they didn't find a solution, as in my opinion PA has to be started before bluetooth and I was able to do this in an upstart file by adding wait for a started PA in the bluetooth.conf file.

Anyhow, mine is working they way I want it to. For unknown reasons, it wouldn't load the module-bluetooth-discover module so I ended up loading it with a sleep and pactl command in the rc.local.
Well, I cannot and do not have to understand everything.
Anyway, it's nice that you have found a functional solution for you.

Purely out of interest, it would certainly be interesting to publish your (modified) scripts here.

Maybe you can learn something from it and adopt it if necessary.
/etc/init/pulseaudio.conf

Code:
start on runlevel [2345]
stop on runlevel [016]

exec pulseaudio --system --realtime --log-target=syslog

respawn

description "PulseAudio system server"

line 4 of /etc/init/bluetooth.conf
Code:
start on (started rpi-bluetooth or started imx-bluetooth or bluetooth) and started pulseaudio

added to /etc/rc.local for this xbian has to be in the sudoers file and xbian has to be added to the pulse group
Code:
bash -c "sleep 30; sudo -u xbian /usr/bin/pactl load-module module-bluetooth-discover"
exit 0

Please note, only headphones work with PA no PA itself. I switch back to PI:HDMI. Sometimes PA works as it must be some boot sequence issue. Anyhow, PA hasn't been stable with xbian nor RpiOS Lite as I end up with no sound after about 10 channel changes. I just use the BT HP when I want to and then switch back to PI:HDMI to avoid this.

Also in $HOME/.config/pulse/default.pa I changed autospawn to no

2/20/23 Update: I had to comment out #dtparam=audio=on in the /boot/config.txt
Oops, I don't have to understand all that now, do I?

But the main thing for you it does what it should, no matter how it works. and that is the most important

Thanks for that. When I have time I'll try to configure it like this to see how it behaves here. according to my current understanding it can't really work at all, but we'll see...
It's a bit of a hack. When you have to add stuff to the rc.local with sleep commands Blush you know it's a hack.

I thought that I was running BT through on board BT but I was running through the dongle since it was turned to the back. I unplugged the dongle and reconnected and the on board BT wouldn't work until I commented out dtparam=audio=on. It worked for awhile with dtparam=audio=on with the dongle so keeping this on could have caused my PA issues in general.

There are some boot timing issues since load-module module-bluetooth-discover won't load on boot plus sometimes PA works and doesn't work through HDMI.

It works for me so I just posted it in case someone else runs into the same issue and wants to give it a try. Xbian is the best if you like something that is open (can add packages) but also is a complete Kodi package (don't have to compile addons for kodi).
In the day, this is for me a hack of the worst kind

For me there is the problem that I just do not understand what all this is supposed to have a meaning

If I run PA in system mode - which the man-page already advises against - the only consequence for me is that no user instance is started and therefore Kodi does not offer any PA devices.

Only if I manual before Kodi start PA as user xbian, Kodi sees again the PA Devices

Also the sentence

Quote:Please note, only headphones work with PA no PA itself. I switch back to PI:HDMI. Sometimes PA works as it must be some boot sequence issue. Anyhow, PA hasn't been stable with xbian nor RpiOS Lite as I end up with no sound after about 10 channel changes. I just use the BT HP when I want to and then switch back to PI:HDMI to avoid this.

sounds completely confused to me and is totally incomprehensible to me

The command

Code:
sudo -u xbian /usr/bin/pactl load-module module-bluetooth-discover

does not work at any time, because PA is not available for the user xbian.

By the way, rc.local is run as root, so a sudo is not required, a su -c xbian would be quite enough

Also it is not a good idea to modify the bluetooth.conf file, because it might be overwritten.

It would make much more sense to create an override file bluetooth.override with the following content

Code:
start on (started rpi-bluetooth or started imx-bluetooth or bluetooth) and started pulseaudio

But these are basically only minor details

I'm sorry I can't help you with this problem, as I obviously don't understand it somehow and understand the hack even less
I know it's a hack in the worst way but it works for me.

You can't run pactl as root and since rc.local runs as root pactl won't work hence the reason I had to add sudo -u xbian. I tried su -c xbian but it didn't work.

My problem all along could have been #dtparam=audio=on so I may ty to back out my hack and see if this solves it to make my system cleaner.
Pages: 1 2
Reference URL's