morrolinux/mpradio

Bluetooth streaming issues on RPI 3B+

Closed this issue ยท 40 comments

Hello, I have a problem with bluetooth streaming. After connecting with a phone and when I start audio player, the sound is being transmitted for a few seconds and then it stops. I assume that PiFmRds stops working because there is no RF signal. When I disconnect bluetooth, it starts transmitting audio from pendrive, and it works fine without issues. When I connect with bluetooth again it works for a few seconds and crashes. What logs do you need? Is there anything else I need to check? I use it on Raspbian lite on Raspberry Pi 3b+

Well, let's try with:

  • your pirateradio.config
  • /var/log/bluetooth_dev from before connecting to when it disconnects
  • systemctl status mpradio-bt@<tab here for bash completion on your BT mac address>

I've probably explained it wrong, the bluetooth device stays connected and plays audio via bluetooth but after few seconds RPi stops transmitting RF (107.0 MHz) but bluetooth stays connected. I assume it is not a bluetooth issue, but I'll post requested logs soon

Attaching requested logs:
mpradio.log
bluetooth_dev.txt

I'd really need logs from mpradio-bt when it's executing rather than when it's already dead. If you cannot catch it running, maybe try with journalctl -f --unit=...

Attaching another log. Unfrotunatelly I am unable to grab a log from mpradio-bt as it seems to be already dead when I try to grab a log immediatelly after bootup. The other thing is that in the moment that crash occurs, nothing new appears in mpradio log. I also attach screenshots from htop when BT streaming is fine and immediatelly after crash
log.txt

When playing over BT:
playing bt
After crash:
after crash

Does this happen also with other devices?
Have you disabled the Wi-Fi on the Pi3?

Yes, it happens with all bluetooth devices. I have not disabled the Wi-Fi

Then please try disabling wifi first (see README - Known issues)

I've disabled the Wi-Fi but this issue still exists, is there anything else I can try?

could be many things, I really would need to see the mpradio-bt logs. it's awkward that your logs are empty, here's what I see when I issue journalctl (with or without -f)

journalctl --unit=mpradio-bt@44\:C3\:46\:5B\:03\:DC.service
-- Logs begin at Thu 2016-11-03 17:16:44 UTC, end at Fri 2018-05-11 19:22:29 UTC. --
May 11 19:22:25 raspberrypi systemd[1]: Started mpradio bluetooth playback 44:C3:46:5B:03:DC.
May 11 19:22:25 raspberrypi mpradio[733]: freq: 88.0
May 11 19:22:25 raspberrypi mpradio[733]: btGain: 1.7 storageGain: 1
May 11 19:22:25 raspberrypi mpradio[733]: persistentPlaylist: 1
May 11 19:22:25 raspberrypi mpradio[733]: resumePlayback: 1
May 11 19:22:25 raspberrypi mpradio[733]: shuffle: 1
May 11 19:22:25 raspberrypi mpradio[733]: rdsUpdateInterval: 3
May 11 19:22:25 raspberrypi mpradio[733]: rdsCharsJump: 6
May 11 19:22:25 raspberrypi mpradio[733]: Output: fm
May 11 19:22:25 raspberrypi mpradio[733]: Format: mp3 -o -iname *.flac -o -iname *.wav
May 11 19:22:25 raspberrypi mpradio[733]: implementation: pi_fm_adv
May 11 19:22:25 raspberrypi mpradio[733]: Treble: 0
May 11 19:22:25 raspberrypi mpradio[733]: 44:C3:46:5B:03:DC
May 11 19:22:25 raspberrypi mpradio[733]: setting audio output to fm
May 11 19:22:26 raspberrypi mpradio[733]: sox WARN wav: Length in output .wav header will be wrong since can't seek to fix it
May 11 19:22:26 raspberrypi mpradio[733]: Recording WAVE 'stdin' : Signed 16 bit Little Endian, Rate 44100 Hz, Stereo
May 11 19:22:26 raspberrypi sudo[740]:       pi : TTY=unknown ; PWD=/ ; USER=root ; COMMAND=/usr/local/bin/pi_fm_adv --ps BLUETOOTH --rt A2DP BLUETOOTH --fr
May 11 19:22:26 raspberrypi sudo[740]: pam_unix(sudo:session): session opened for user root by (uid=0)

what else can you try... I couldn't really tell.. maybe just make sure you're running journalctl proprely, for example I see no escape backslashes in your command issues, have you used tab expansion?
PS: please prefer pastebin for pasting logs rather than sending attached txt(s)

Tried once more, the journalctl command syntax is like in your example with backslashes, but still no luck
https://pastebin.com/sg5jnjwE

Well, that's because you're passing it your Pi's BT:AD:DR:ES:S$ which you shouldn't: the service is executed on the connected client's address!

Finally, I managed to get this log
https://pastebin.com/H6aYKf7p

Ok great! now we should get something more comprehensible if you add -f option and start to capture before connecting the bluetooth, and keep logging until the RF signal gets lost

Hello, seems like everything starts fine but then something breaks during the playback.. could be bluetooth issues...
could you post me the logs of bluealsa as well?
Thanks

Maybe I've done something wrong but I got only this:
https://pastebin.com/V8spA5TU

can you try with another BT adapter? an unstable one could be the cause of broken pipes

Unfortunately I don't have any USB Bluetooth adapter, I use the Raspberry pi's onboard one. But it works properly with OSMC, Bluetooth streaming works properly there

could you try with the latest commit I've just pushed, and logging mpradio-bt just like you did last time?
I've just added more verbosity which I need to gather more data

I have updated using cd mpradio-master && git fetch origin && git reset --hard origin/master && cd install && sudo ./install.sh
This is the new log:
https://pastebin.com/dcc4zGDJ

Awkward, that doesn't quite look like the output of the latest version.. could you post here the content of your .git/refs/heads/master inside mpradio-master?
also try with $ git rev-parse HEAD

Content of master:
b76cc0a

pi@raspberrypi:~/mpradio-master/.git/refs/heads $ git rev-parse HEAD
b76cc0a

I uninstalled, removed mpradio-master folder and re-installed but mpradio-bt log looks the same so I'm not posting it

Then something went wrong with the installation I guess. try manually compiling and installing by cd mpradio-master/src && make && sudo cp mpradio /bin/mpradio
That's what I (and you should) see:

...
May 17 15:47:20 raspberrypi mpradio[815]: setting audio output to fm
May 17 15:47:20 raspberrypi mpradio[815]: CMDLINE: arecord -D bluealsa:HCI=hci0,DEV=44:C3:46:5B:03:DC -f cd -c 2 | sox -t raw -v 1.7 -G -b 16 -e signed -c 2 -r 44100 - -t wav -  | sudo /usr/local/bin/
May 17 15:47:20 raspberrypi mpradio[815]: sox WARN wav: Length in output .wav header will be wrong since can't seek to fix it
...

I cannot duplicate your results, @Eva850. (Note: this is on account of having a model 3B, not 3B+; please see my third comment here.)

I would bet that since you're comparing it to OSMC, this is an issue with installation rather than the bluetooth connection. (This is probably not as relevant as I thought, all things since then considered, but you might want to keep reading here.) If your Pi has OSMC installed on it, you must be you're probably using (Raspbian 8) Jessie, as I don't see any releases of OSMC available for (Raspbian 9) Stretch. Many, many bluetooth audio fixes came with Stretch that I'd have expected a project as large as OSMC to be able to just dance around and manage by hand, but I don't think mpradio actually runs with it. (You can check your release via cat /etc/issue.)

That having been said, I followed these steps:

  • Wipe my SD card and restore a Raspbian Lite image from March 13/14 (see this link for sources) to it

  • Mount the two partitions on the card, boot and rootfs, then sudo touch boot/ssh (I think that's the right one ... I just touched both boot/ssh and rootfs/boot/ssh). This enables ssh.

  • Insert the microSD card into the Pi 3B+

  • Connect Pi to >=2A power source and connect Pi with laptop via ethernet cable, configured for shared connection

  • ssh pi@IP_ADDR (I use nmap -sn <IP_RANGE_OF_ETH>/24 to find the address, which works if sshd is actually running on the Pi)

  • On the Pi, sudo apt update && sudo apt upgrade -y && sudo apt install git screen && reboot

  • Shell back in and git clone https://github.com/morrolinux/mpradio (this clones to mpradio, which works as well as mpradio-master since a recent merge)

  • cd mpradio/install/ && sudo ./install.sh

  • Wait for reboot, then pull out phone, scan and connect to mpradio, and run. I have a tuner that can pick up the default 107.0 FM, but you may want to actually shell in to make sure things are running.

If it's not to do with your OS version installed, then perhaps you forgot to update and upgrade before trying anything. In any case, let me know how the above works.

@morrolinux Following along with the above, it might be a good idea for me to open an issue and try some versioning compatibility, e.g. trying to run it on a fresh install of full-blown Raspbian, or (as with the above) on top of non-fresh installs. Just a thought.

The difference in interface / baud rate is because you're actually using 3B+, not 3B ... my apologies, I only just became aware of the existence of the model; I have a 3B revision 1.2. I'm currently digging around through issues pertaining to how bluealsa and the new model's bluetooth chip play together, but I'm not entirely sure that this is our territory ...

Go ahead and check sudo systemctl status bluealsa.service post-crash; if it's bluealsa crashing, I'm not entirely sure what can be done.

I'm going to go out on a limb here, @Eva850: try editing /usr/bin/btuart at line 12, replacing

$HCIATTACH /dev/serial1 bcm43xx 3000000 flow - $BDADDR

with

$HCIATTACH /dev/serial1 bcm43xx 921600 noflow - $BDADDR

then rebooting.

This should prevent flow control from ever being used, which is one major difference on the Pi3B+'s BT UART. Given the delay between starting and crashing, I'm throwing a guess that it might have to do with flow control trying to tell the transmitter to stop.

While I know it's possible to underclock a UART receiver, I don't know whether actually disabling flow control is possible, or whether it will make anything work better (actually, I have evidence to the contrary).

Whether or not this provides an adequate fix, this is probably all due to bluealsa not working on the new chip. It's not entirely unlikely that this could have something to do with the BT PCM being removed entirely (note that in some cases, bluealsa relies upon this, I think ... but I can't seem to explain why it would work for any amount of time if the BT module on the new Pi can't handle PCM sound at all ...)

Try what you can.

Thanks for instructions, I will try to install this older Raspbian image and reinstall mpradio, mayby it will work

@Hurricos Good job of digging. Could be added to the "known isues" section when we'll know something for sure.
@Eva850 keep us updated :)

@Eva850 is the above solved? should I close this issue?

Unfortunately I haven't got much free time recently, I will check some things at the weekend and keep you informed. Please keep this issue open, at least till the next week

UPDATE: The author of PiFmAdv just made an important change to the implementation, making it more stable and possibily fixing this issue as well. please update everything before you try again :)

Here is the log after updating and changing to pi_fm_adv. https://pastebin.com/amuMGij7
The issue is still there. But I must admit that I sometimes notice that during playback from pendrive song plays fine for a few seconds then transmission stops and the next song is being transmitted. I had this problem from the beginning but I haven't reported it, but now I think that the cause of both issues can be similar

Seems like there was an issue with the latest update, please update twice and test again :)
PS: I was able to reproduce your issue with my new Pi 0W

@morrolinux Do you mean the issue which occurs over Bluetooth, or the one which occurs via the pendrive? If this has to do with Bluetooth, perhaps it has to do with the interaction between bluez / bluealsa and the upgraded Bluetooth hardware, which may be able to be fixed in general.

I will soon be receiving a Pi Zero W myself, so I'll test this when I have time.

the pendrive one. But I think it's the same exact issue.
I'm currently running my Pi0w with mp3 and Bluetooth flawlessly

@Hurricos Oh, I forgot: I'm running mpradio not on the latest raspbian (I just haven't updated it in a while - April 2018) that said, no issues so far with the latest mpradio.
could come handy to download this image and just update mpradio
https://www.mediafire.com/folder/qn62j675htott/mpradio

It seems I solved my issue. I use my RPI with OSMC so I have connected TSOP ir receiver to gpio18, it have been connected during all my tests. When I disconnected it, bluetooth works fine. Sorry for creating this unnecessary issue.

Aahahah damn, that GPIO is reserved for the pushbutton, now I see why you got interrupted every 0.5 seconds.. that's the timing mpradio sets for checking the button state...
Anyway, good to hear you solved your issue, don't forget to try the app (remote bluetooth) as well!