Exec Node and Terminal Problem ( Alsa)

Hello everyone,

i try to play music with the raspberry and also play random sound effects at the same time.
i followed this tutorial: http://pacmans-revenge.blogspot.com/2018/08/raspberry-pi-bluetooth-speakers.html
but it doesnt work like i want it to. while i am connected with my mobile to the raspberry and stream a song, i can run a music file from the terminal, but i can not trigger it with the same command from nodered.

In the tutorial link mentioned above, u can see what my config look like.
I just changed the /home/pi/.asoundrc to the following for a test.

pcm.!default {
        type plug
        slave.pcm "dmixer"
}

pcm.dmixer  {
        type dmix
        ipc_key 1024
        slave {
                pcm "hw:1,1"
                period_time 0
                period_size 1024
                buffer_size 4096
                rate 44100
        }
        bindings {
                0 0
                1 1
        }
}

ctl.dmixer {
        type hw
        card 1
}

and configured the pulse audio sink and source like that

pactl load-module module-loopback source=bluez_source.20_DA_22_73_84_1D.a2dp_source sink=alsa_output.platform-snd_aloop.0.analog-stereo

Hope anyone knows the solution... i try to find a way since 4 weeks or something ... :frowning:

okay i made a little work around ... my new strategy is to just build up an ssh connection inside nodered and send the play commands via that method. now the only problem i got is that the ssh connection does allways close after one command. anyone knows a strategy ?

iam currently useing sshpass.

You can send commands one at a time using ssh using
ssh user@server "some_command to execute remotely with params"
That way you don't need to build and maintain the connection.

1 Like

Hi, thanks for your help. Now it open the ssh connection without authentification via passwort and uses instead a key file.

My problem is, that everytime it open the connection, there is about 500ms delay. if i want to play an audiosample just in time, this is a problem.

so i need to have an connected ssh tunnel which, after first connection, can be used to pump more commands to that established connection... any idea how to do that in nodered ?

You could use mqtts to send the commands instead.

i can play sound just via and established ssh connection, mqtt wont help me in that case i think.

It means you don't need an ssh tunnel. Much simpler.

how can i use my "play" function via mqtt ?

Pick it up in node-red at the other end and run the command in an exec node.

but that is just another way to pump a command to the exec node. the problem still is, that the command "play /dedo.wav" pumped in the exec node doesnt work. i have to use a terminal or a ssh connection to be able to play a soundfile.
i still got the problem which i mentioned in the picture i postet at my thread start.
the ssh connection was just a work around.

Oh, sorry, I thought you were using a tunnel to get to another machine.
Can you give us a translation of the error message you showed earlier please.

If you are playing the music on the Pi and have the speakers attached to it, have you tried using node-red-contrib-playsound? Not sure if it will work with bluetooth speakers, but it worked fine in my Music Player project

If the command works in a terminal as the user pi then it should be possible to make it work in an exec node.

OK, worked that out myself "Error opening device or file not found".
Put a debug node showing what is going into the exec node and also show us the config of the exec node.

Hi,

i tried your example now and sadly i cant stream bluetooth music and parallel the play-sound node at the same time.

Screenshot is taken while the musik plays via blueetooth:

anyone got an idea ? :thinking:

Hello,
You get this error because alsa cant play two things at once. This is why alsa gives you the resource busy error.
If you ll want to play several things to one audio output at the same time you will have to use a middleware soundserver like pulseaudio to do it im afraid. You seem to be using pulse audio for your music so you would need to play whatever you want to play from nodered through pulse audio too. Aplay tries to play it directly it seems. If you have the pulse audio utils installed you could try use paplay instead of aplay.
Johannes

Seems there is also a problem with some permissions or something when i try to pump that command though the exec node. Via Putty it works just fine, also when iam playing in that moment a song from my mobilephone via bluetooth.

your missing a / at the start of you file path it should be something like /home/pi/your_audio.wav. That’s probably why your getting the error that the file couldn’t be found and you shouldn’t need sudo.