LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Slackware (https://www.linuxquestions.org/questions/slackware-14/)
-   -   Using Slackware to make a Bluetooth speaker (https://www.linuxquestions.org/questions/slackware-14/using-slackware-to-make-a-bluetooth-speaker-4175688688/)

louigi600 01-16-2021 12:36 PM

Using Slackware to make a Bluetooth speaker
 
I would like to setup a Slackware box (with a BT device and appropriate audio amp) as a Bluetooth speaker.
I know it is possible to use blueman to do that but I cant find a way to do it automatically without having to actually log into the Slackware box.
Basically I would like it to behave much like a normal Bluetooth speaker: ounce you power it up it automatically is listening for for something to bind and send audio to it.

Anyone know ho to go about it ?

I found this but not sure if it is too Debian oriented to to be any use on a Slackware system.

Tonus 01-16-2021 02:35 PM

Appart from the systemd thing, it should work.

Tell us if ur stuck somewhere.

louigi600 01-17-2021 02:21 AM

I did the same things as described in that tutorial disregarding systemd stuff and also the pulseaudio start (because on slackware it is already running) but it's not working right:
on the phone I get "cannot connect" and on the slackware box's /var/log/syslog I get:
Code:

Jan 17 10:27:49 e11old bluetoothd[1833]: Authentication attempt without agent
Jan 17 10:27:49 e11old bluetoothd[1833]: Access denied: org.bluez.Error.Rejected

Not sure how to mend that.

Tonus 01-17-2021 02:35 AM

Not at my computer today but that might be interesting :
https://stackoverflow.com/questions/...pin-on-bluez-5

louigi600 01-17-2021 03:29 AM

Intresting ... that got the phone to connect but it still requires interaction after each boot to get the phone to connect even after initial pairing.
Looking for a fully automatic solution.

Tonus 01-17-2021 06:17 AM

I'm interested too :-)

What interactions do you have after reboot ?

louigi600 01-17-2021 06:37 AM

The pairing
Code:

root@e11old:~/bt_speaker# bluetoothctl
[NEW] Controller 3C:77:E6:FE:19:6C E11Old [default]
[NEW] Device 6C:B7:49:CD:2A:85 HUAWEI Mate 10 lite
[NEW] Device 34:DE:34:CA:B6:F4 ZTE Blade A430
[NEW] Device 80:6A:B0:F5:DF:29 wiko davide
[NEW] Device 30:23:B5:72:B2:8A SBS BT500 RED
Agent registered
[bluetooth]# agent off
Agent unregistered
[bluetooth]# agent DisplayOnly
Agent registered
[bluetooth]# default-agent
Default agent request successful
[bluetooth]# discoverable on
Changing discoverable on succeeded
[CHG] Controller 3C:77:E6:FE:19:6C Discoverable: yes
[bluetooth]# pairable on
Changing pairable on succeeded
[NEW] Device D4:11:A3:D8:2E:3C Galaxy A40
Request PIN code
[agent] Enter PIN code: 1234
[CHG] Device D4:11:A3:D8:2E:3C Class: 0x005a020c
[CHG] Device D4:11:A3:D8:2E:3C Icon: phone
[CHG] Device D4:11:A3:D8:2E:3C Connected: yes
[CHG] Device D4:11:A3:D8:2E:3C Modalias: bluetooth:v0075p0100d0201
[CHG] Device D4:11:A3:D8:2E:3C UUIDs: 00001105-0000-1000-8000-00805f9b34fb
[CHG] Device D4:11:A3:D8:2E:3C UUIDs: 0000110a-0000-1000-8000-00805f9b34fb
[CHG] Device D4:11:A3:D8:2E:3C UUIDs: 0000110c-0000-1000-8000-00805f9b34fb
[CHG] Device D4:11:A3:D8:2E:3C UUIDs: 0000110e-0000-1000-8000-00805f9b34fb
[CHG] Device D4:11:A3:D8:2E:3C UUIDs: 00001112-0000-1000-8000-00805f9b34fb
[CHG] Device D4:11:A3:D8:2E:3C UUIDs: 00001115-0000-1000-8000-00805f9b34fb
[CHG] Device D4:11:A3:D8:2E:3C UUIDs: 00001116-0000-1000-8000-00805f9b34fb
[CHG] Device D4:11:A3:D8:2E:3C UUIDs: 0000111f-0000-1000-8000-00805f9b34fb
[CHG] Device D4:11:A3:D8:2E:3C UUIDs: 0000112d-0000-1000-8000-00805f9b34fb
[CHG] Device D4:11:A3:D8:2E:3C UUIDs: 0000112f-0000-1000-8000-00805f9b34fb
[CHG] Device D4:11:A3:D8:2E:3C UUIDs: 00001132-0000-1000-8000-00805f9b34fb
[CHG] Device D4:11:A3:D8:2E:3C UUIDs: 00001200-0000-1000-8000-00805f9b34fb
[CHG] Device D4:11:A3:D8:2E:3C UUIDs: 00001800-0000-1000-8000-00805f9b34fb
[CHG] Device D4:11:A3:D8:2E:3C UUIDs: 00001801-0000-1000-8000-00805f9b34fb
[CHG] Device D4:11:A3:D8:2E:3C ServicesResolved: yes
[CHG] Device D4:11:A3:D8:2E:3C Paired: yes
[CHG] Device D4:11:A3:D8:2E:3C ServicesResolved: no
[CHG] Device D4:11:A3:D8:2E:3C Connected: no
[bluetooth]#

And also another issue ... after some fiddling even when I pair interactively the audio is not setup properly and from the phone I do not see it as and audio device.
I think the one time I got it to work was because there was some residue from blueman pairing and setting up as audio.
I found a python script that does the pairing ... but not sure how to set it as the default agent.
And not sure how to go about stetting the Slackware box to present itself as a BT audio device all from command line.

Tonus 01-17-2021 09:19 AM

I've got some bash scripts that deal with bluetoothctl and might be adapted.
IIRC one had sticky bit to pair.

louigi600 01-17-2021 11:00 AM

Can yo upload them here ?
I've not logged into IRC in a long time.
Maybe I just need to tell pulseaudio there is a new audio source ... since the binding works.
For the automatic binding I will try tell bluetoothctl where the new simmple-pin python script is ... it might be enough.
I will see, once I bind, if I can see the new audio source in pavucontrol ... if so I will try to figure out how to do it form command line ... if not I guess there is more to know.

Tonus 01-17-2021 11:06 AM

IIRC stands for "if I recall correctly" ;-)

I will post it here in the evening.

louigi600 01-17-2021 11:31 AM

Cool ...
Here's a bit more I found out: if I do the pairing with blueman I do see this in the kernel ring buffer (which I do not see if I pair with the bluetoothctl procedure)
Code:

[ 1257.696422] input: D4:11:A3:D8:2E:3C as /devices/virtual/input/input15
and in messages
Code:

Jan 17 19:39:25 e11old kernel: [ 1257.696422] input: D4:11:A3:D8:2E:3C as /devices/virtual/input/input15
Jan 17 19:40:00 e11old bluetoothd[1227]: /org/bluez/hci0/dev_D4_11_A3_D8_2E_3C/fd0: fd(32) ready

also when I quit blueman end X I also see this in messages
Code:

Jan 17 20:00:06 e11old bluetoothd[1227]: Endpoint unregistered: sender=:1.17 path=/MediaEndpoint/A2DPSource
Jan 17 20:00:06 e11old bluetoothd[1227]: Endpoint unregistered: sender=:1.17 path=/MediaEndpoint/A2DPSink

I also noticed that if I do it when X is running I do get a slightly better result: on the phone I do get the audio device recognized (but fails to connect) : I suspect the's more dbus integration then I hoped. The target would be a headless RPI with no X at all: will I need to recompile bluez ?

Quote:

Originally Posted by Tonus (Post 6208780)
IIRC stands for "if I recall correctly" ;-)

I will post it here in the evening.

I thought it was some IRC client :-D
after all if there exists mIRC why not also IIRC ;-)

Richard Cranium 01-17-2021 06:05 PM

I would like to setup a Slackware box (with a BT device and appropriate audio amp) as a Bluetooth speaker.

Yeah.

So, you need something that can handle the possibilities that the BT device wasn't in range when you started OR was in range and then moved out of range while things are running and then moved back into range OR wasn't in range when you started but then later came into range.

Maybe you don't care about how those scenarios happen; maybe you don't care that someone could bring a BT device near that your box would connect to that simply looped someone stating that you were a pedophile or loved goats more than one would expect.

Please provide a better use case than that which you have given here.
  • Describe what you believe to be the normal use case.
  • Describe what you believe to be those slightly abnormal cases
  • Describe those cases that you do not ever wish to happen

If you absolutely know what BT device with which you need to pair, that will simplify things a bit.

I've gone through this with pairing a heart beat monitor against a Netbeans application running on a Slackware machine so I could watch my heart rate on a graph while exercising.

Tonus 01-17-2021 06:47 PM

For the bluetoothctl, that's what I scripted :

Code:

echo -e "agent off\nagent DisplayOnly\ndefault-agent\ndiscoverable on\npairable on\nquit\n" | bluetoothctl
For the pulse part, this script changed to next sound card. Have to be adapted to the use case :
Code:

#! /bin/bash

# $totalsc: Number of sound cards available
totalsc=$(pacmd "list-sinks" | grep card: | wc -l)
if [ $totalsc -le 1 ]; then
  notify-send -u critical -t 5000 "No new sound card."
  exit
fi

# $scindex: The Pulseaudio index of the current default sound card
scindex=$(pacmd list-sinks | awk '$1 == "*" && $2 == "index:" {print $3}')

# $cards: A list of card Pulseaudio indexes
cards=$(pacmd list-sinks | sed 's|*||' | awk '$1 == "index:" {print $2}')
PICKNEXTCARD=1 # Is true when the previous card is default
count=0 # count of number of iterations

for CARD in $cards; do
  if [ $PICKNEXTCARD == 1 ]; then
# $nextsc: The pulseaudio index of the next sound card (to be switched to)
    nextsc=$CARD
    PICKNEXTCARD=0
# $nextind: The numerical index (1 to totalsc) of the next card
    nextind=$count
  fi
  if [ $CARD == $scindex ]; then # Choose the next card as default
    PICKNEXTCARD=1
  fi
  count=$((count+1))
done
pacmd "set-default-sink $nextsc" # switch default sound card to next

# $inputs: A list of currently playing inputs
inputs=$(pacmd list-sink-inputs | awk '$1 == "index:" {print $2}')
for INPUT in $inputs; do # Move all current inputs to the new default sound card
  pacmd move-sink-input $INPUT $nextsc
done
# $nextscdec: The device.description of the new default sound card
# NOTE: This is the most likely thing to break in future, the awk lines may need playing around with
nextscdesc=$(pacmd list-sinks | awk '$1 == "device.description" {print substr($0,5+length($1 $2))}' \
                        | sed 's|"||g' | awk -F"," 'NR==v1{print$0}' v1=$((nextind+1)))
notify-send "Default sound-card changed to $nextscdesc"
exit


hpfeil 01-17-2021 07:39 PM

Thank you for mentioning bluetoothctl.

louigi600 01-18-2021 02:24 AM

Quote:

echo -e "agent off\nagent DisplayOnly\ndefault-agent\ndiscoverable on\npairable on\nquit\n" | bluetoothctl
I think this should do the same but without having to redirect the output of echo
Code:

bluetoothctl << EOF
agent off
agent DisplayOnly
default-agent
discoverable on
pairable on
quit
EOF

I will see if I can modify the pulseaudio script to work on my system ... should I run that after pairing or before pairing ?
Not sure which is the head and which the tail of the cat chasing it's tail: do I need to setup pulse before pairing so that the audio output is presented via BT or do I need to tell pulse that there is a new audio source after pairing ?
Anyway seem to have run into trouble with the very first line:
Code:

root@e11old:~/bt_speaker# pacmd "list-sinks" | grep card: | wc -l
No PulseAudio daemon running, or not running as session daemon.
0
root@e11old:~/bt_speaker#

Remember I'm on the text console ... not sure how X starts pulseaodio but I don't have rc.plulseaudio executable.
In any case even if I start it I still get much the same:
Code:

root@e11old:~/bt_speaker# . /etc/rc.d/rc.pulseaudio start
Starting system PulseAudio daemon:  /usr/bin/pulseaudio --system --disallow-module-loading &
root@e11old:~/bt_speaker# pacmd "list-sinks" | grep card: | wc -l
No PulseAudio daemon running, or not running as session daemon.
0
root@e11old:~/bt_speaker#

Quote:

So, you need something that can handle the possibilities that the BT device wasn't in range when you started OR was in range and then moved out of range while things are running and then moved back into range OR wasn't in range when you started but then later came into range.
Not really because the plan is to add analog audio out to a RPIzeroW and have it devoted just to doing BT audio playback ... so when I turn it on I know I want to stream audio to it and phone will be in range. Concerning the temporarily out of range I was thinking that a simple BT reconnect on phone would fix it. But it might be nice if the slackware box would remember pared devices across restarts.

Quote:

Please provide a better use case than that which you have given here.
Describe what you believe to be the normal use case.
Describe what you believe to be those slightly abnormal cases
Describe those cases that you do not ever wish to happen
I'm trying to find how to do something not complaining of abnormalities so not really sure what you want me to explain here.
Any information I posted is just to share my findings so people can help me.

I want to be able to have a headless slackware box (will be a RPIzeroW once I figure out how) pair automatically with let's say one and one only specific phone (maybe a list in the future) and be able to to playback music like an ordinary off the shelf BT speaker system.


All times are GMT -5. The time now is 11:39 PM.