Bluetooth Audio on Raspberry/OSMC - working solution
#1
Maybe its interesting for some peoples out there...
with help of different pages and users on other forums i found a solution to get
bluetooth speakers working on a raspberry with OSMC OS (no idea if this also works for other distributions)

Hardware: Raspberry PI2, Trust 18187 Bluetooth Dongle (Cambridge Silicon Radio CHIP)
OS: OSCM Release 2015.09-2

First i made this:

Code:
sudo apt-get update
sudo apt-get install
sudo apt-get install bluez pulseaudio pulseaudio-module-bluetooth

once installed everything i've tested if i can pair and connect my speakers with the bluetoothctl tool:

Code:
sudo bluetoothctl -a

agent on
default-agent
scan on
wait for your device to show and make it discoverable
then
trust YOURMACADROFTHEDEVICE
pair YOURMACADROFTHEDEVICE
connect YOURMACADROFTHEDEVICE

after this i changed inside Kodi the audio output to pulseaudio server
and how wonder it worked so far... but it didn't connect after reboot... i found out that bluetooth is not powered on automatically and i need to change or make some files:

New File /etc/udev/rules.d/10-local.rules
Code:
# Set bluetooth power up
ACTION=="add", SUBSYSTEM=="bluetooth", KERNEL=="hci[0-9]*", RUN+="/usr/bin/hciconfig %k up"

add line in /etc/pulse/default.pa
Code:
# automatically switch to newly-connected devices
load-module module-switch-on-connect

this changes power up the bluetooth on start, but still not connect automatically

then i made a script in /var/scripts/ called startBTaudio.sh
Code:
#!/bin/sh
echo "connect YOURMACADROFTHEDEVICE" | bluetoothctl -a
echo "exit" | bluetoothctl -a

in /etc/systemd/system i create a file named BTspeaker.service
Code:
[Unit]
Description=Bluetooth Speaker automatic connect

[Service]
Type=simple
ExecStart=/var/scripts/startBTaudio.sh

in /etc/systemd/system i create a file named BTspeaker.timer
Code:
[Unit]
Description=Run Script after some time

[Timer]
# Time to wait after booting before activation
OnBootSec=15
Unit=BTspeaker.service

[Install]
WantedBy=multi-user.target

and enable this service with
Code:
systemctl enable BTspeaker.timer

so at the end, i was troubling around that connect script starts before before pulseaudio starts and this won't work... now it waits 15 seconds after boot and this work fine for me.

the sound quality is not perfect but enough for my case
Reply
#2
Hi

Good work -- we are working on A2DP streaming and hope to make this part of OSMC in the October release

Sam
Reply
#3
(2015-09-30, 16:16)dawed Wrote: this changes power up the bluetooth on start, but still not connect automatically

then i made a script in /var/scripts/ called startBTaudio.sh
Code:
#!/bin/sh
echo "connect YOURMACADROFTHEDEVICE" | bluetoothctl -a
echo "exit" | bluetoothctl -a

the above script starts bluetoothctl twice. the second time only to exit.
The following does what you intended:
Code:
#!/bin/sh
bluetoothctl -a << EOF
connect YOURMACADROFTHEDEVICE
exit
EOF
Reply
#4
Easier solution now:

sudo apt-get install a2dp-app-osmc
Reply
#5
Just wondering what kind of latency people get. Lip-sync issues? I guess it probably depends partly on the dongle but still interested in knowing.
Reply
#6
None here -- but I may be testing in an ideal environment Smile

If you can provide some further detail with a debug log, I can investigate. Also make sure that playback via HDMI or analog is in sync first.
Reply
#7
(2016-11-25, 02:12)Sam.Nazarko Wrote: None here -- but I may be testing in an ideal environment Smile

If you can provide some further detail with a debug log, I can investigate. Also make sure that playback via HDMI or analog is in sync first.

Actually, I'm just wondering whether this is something I should try. At the moment I'm using a bluetooth transmitter which is a bit of a pain to connect and pair. On the plus side it does support the AptX low-latency codec. I have a hearing loss and what I'm looking for is a solution that allows me to listen through a bluetooth headset while my wife listens through speakers. Any non-negligible latency sounds terrible in that situation.
Reply
#8
im looking for a similar solution to work on libreelec and kodi to connect to my google home bluetooth speaker
Reply
#9
So start a thread as your issue is completely unrelated to this topic.
Reply
#10
On OSMC you can now follow https://discourse.osmc.tv/t/testing-blue...-a2dp/9116
Reply

Logout Mark Read Team Forum Stats Members Help
Bluetooth Audio on Raspberry/OSMC - working solution0