Command works in terminal but not in exec node

The following command works fine in the console, but not in the exec node in Buster, but used to work in Stretch.

ffplay Desktop/audio.mp3 >/dev/null 2>&1 -vn -autoexit -nodisp

[{"id":"866572cd.1cabb","type":"comment","z":"0f9a9065356bf9a1","name":"https://translate.google.com/translate_tts?ie=UTF-8&client=tw-ob&tl=en&q=Hello+World","info":"https://translate.google.com/translate_tts?ie=UTF-8&client=tw-ob&tl=en&q=Hello+World","x":380,"y":60,"wires":[]},{"id":"b1e32597.2c78a8","type":"inject","z":"0f9a9065356bf9a1","name":"","repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"Goodbye","payloadType":"str","x":80,"y":180,"wires":[["597a0b09.032f54"]]},{"id":"67bd15e7.7e05cc","type":"inject","z":"0f9a9065356bf9a1","name":"","repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"Hello","payloadType":"str","x":90,"y":120,"wires":[["597a0b09.032f54"]]},{"id":"bae924d9.b41608","type":"play audio","z":"0f9a9065356bf9a1","name":"","voice":"0","x":750,"y":180,"wires":[]},{"id":"597a0b09.032f54","type":"function","z":"0f9a9065356bf9a1","name":"TTS","func":"msg.url =\"https://translate.google.com/translate_tts?ie=UTF-8&client=tw-ob&tl=en&q=\"+msg.payload;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":290,"y":140,"wires":[["1a67f7f4.ceebf8"]]},{"id":"1a67f7f4.ceebf8","type":"http request","z":"0f9a9065356bf9a1","name":"Download mp3","method":"GET","ret":"bin","paytoqs":"ignore","url":"","tls":"","persist":false,"proxy":"","authType":"","x":460,"y":140,"wires":[["fb043dc9.03987"]]},{"id":"5aa18234.1e1cfc","type":"exec","z":"0f9a9065356bf9a1","command":"ffplay Desktop/audio.mp3","addpay":"","append":">/dev/null 2>&1 -vn -autoexit -nodisp","useSpawn":"false","timer":"","winHide":false,"oldrc":false,"name":"","x":790,"y":240,"wires":[[],[],[]]},{"id":"fb043dc9.03987","type":"file","z":"0f9a9065356bf9a1","name":"File write to Buffer","filename":"/home/pi/Desktop/audio.mp3","appendNewline":false,"createDir":false,"overwriteFile":"true","encoding":"none","x":470,"y":180,"wires":[["5aa18234.1e1cfc","bae924d9.b41608"]]},{"id":"819b3cfeb9606e49","type":"comment","z":"0f9a9065356bf9a1","name":"Output on Browser","info":"","x":770,"y":140,"wires":[]},{"id":"bc3fe0386551d616","type":"comment","z":"0f9a9065356bf9a1","name":"Output to Bluetooth Speaker","info":"","x":800,"y":300,"wires":[]},{"id":"a1f9ee40e25fa20d","type":"comment","z":"0f9a9065356bf9a1","name":"ffplay Desktop/audio.mp3 >/dev/null 2>&1 -vn -autoexit -nodisp","info":"So by specifying > /dev/null 2>&1 you tell the system that you want to redirect the command's standard output into /dev/null, then redirect standard error into standard output (which in turn is redirected into /dev/null). This has the effect of silencing the command by throwing away all of its output that is sent to either stdout or stderr.","x":680,"y":340,"wires":[]}]

Is there an issue with Node Red Exec Node in Buster?

There's no known issue with the exec node.

I just tried your flow out on my Pi4 Buster and it worked without error (except I don't have a bluetooth speaker connected so I don't know if that bit would actually make a sound)

maybe add full path to the audio.mp3 file? /home/Pi/Desktop/audio.mp3

Thanks, so does the ffplay work through the command node on your system and output to a wire connected speaker to your Pi4?
The ffplay in the terminal outputs to my bluetooth speaker without issues, but does not output from the exec node.
Changing the output to the full path had no effect.

Or is there an issue with the exec node in Node Red Version 2?

Resolved

Prefixing the ffplay in the exec node with the following appears to resolve the issue.

DISPLAY=:0

[{"id":"0f9a9065356bf9a1","type":"tab","label":"Flow 1","disabled":false,"info":""},{"id":"866572cd.1cabb","type":"comment","z":"0f9a9065356bf9a1","name":"https://translate.google.com/translate_tts?ie=UTF-8&client=tw-ob&tl=en&q=Hello+World","info":"https://translate.google.com/translate_tts?ie=UTF-8&client=tw-ob&tl=en&q=Hello+World","x":380,"y":60,"wires":[]},{"id":"b1e32597.2c78a8","type":"inject","z":"0f9a9065356bf9a1","name":"","repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"Goodbye","payloadType":"str","x":80,"y":180,"wires":[["597a0b09.032f54"]]},{"id":"67bd15e7.7e05cc","type":"inject","z":"0f9a9065356bf9a1","name":"","repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"Hello","payloadType":"str","x":90,"y":120,"wires":[["597a0b09.032f54"]]},{"id":"bae924d9.b41608","type":"play audio","z":"0f9a9065356bf9a1","name":"","voice":"0","x":750,"y":180,"wires":[]},{"id":"597a0b09.032f54","type":"function","z":"0f9a9065356bf9a1","name":"TTS","func":"msg.url =\"https://translate.google.com/translate_tts?ie=UTF-8&client=tw-ob&tl=en&q=\"+msg.payload;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":290,"y":140,"wires":[["1a67f7f4.ceebf8"]]},{"id":"1a67f7f4.ceebf8","type":"http request","z":"0f9a9065356bf9a1","name":"Download mp3","method":"GET","ret":"bin","paytoqs":"ignore","url":"","tls":"","persist":false,"proxy":"","authType":"","x":460,"y":140,"wires":[["fb043dc9.03987"]]},{"id":"5aa18234.1e1cfc","type":"exec","z":"0f9a9065356bf9a1","command":"DISPLAY=:0 ffplay Desktop/audio.mp3 ","addpay":"","append":">/dev/null 2>&1 -vn -autoexit -nodisp","useSpawn":"false","timer":"","winHide":false,"oldrc":false,"name":"","x":830,"y":240,"wires":[[],[],[]]},{"id":"fb043dc9.03987","type":"file","z":"0f9a9065356bf9a1","name":"File write to Buffer","filename":"/home/pi/Desktop/audio.mp3","appendNewline":false,"createDir":false,"overwriteFile":"true","encoding":"none","x":470,"y":180,"wires":[["5aa18234.1e1cfc","bae924d9.b41608"]]},{"id":"819b3cfeb9606e49","type":"comment","z":"0f9a9065356bf9a1","name":"Output on Browser","info":"","x":770,"y":140,"wires":[]},{"id":"bc3fe0386551d616","type":"comment","z":"0f9a9065356bf9a1","name":"Output to Bluetooth Speaker","info":"","x":800,"y":300,"wires":[]},{"id":"a1f9ee40e25fa20d","type":"comment","z":"0f9a9065356bf9a1","name":"ffplay Desktop/audio.mp3 >/dev/null 2>&1 -vn -autoexit -nodisp","info":"So by specifying > /dev/null 2>&1 you tell the system that you want to redirect the command's standard output into /dev/null, then redirect standard error into standard output (which in turn is redirected into /dev/null). This has the effect of silencing the command by throwing away all of its output that is sent to either stdout or stderr.","x":680,"y":340,"wires":[]}]

Why this should be necessary now, but wasn't in previous versions of Raspbian/Node Red I have no idea. Any explanation appreciated.

In the exec node, I notice you are not providing the full path to the audio file. Try adding the full path and see if you can remove the DISPLAY=:0

As I said above, already tried, and changing the output in the exec node to the full path had no effect. Only seems to work if DISPLAY=:0 is added.

Incidentally the purpose of the code is usually for communicating with an Amazon Alexa Dot speaker, but is also being tested here using bluetooth earphones.

I don't have a bluetooth speaker, but I just ran it without the 'DISPLAY=:0" on a Pi3 (Buster lite) with the full path to the file and I hear sound from the audio jack (earphones plugged in)

Have you added debug nodes (set to display the complete msg object) to the three outputs of the exec node to see if they show anything?

There is only output from Stdout and the Return Code, nothing from Stderr. Hope the following output gives you some insight. Incidentally when it works over bluetooth by including the DISPLAY=:0, there is a considerable 5 sec delay before output of sound.

13/12/2021, 14:08:37node: 0873e50e140abde5
msg : Object
object
msgid: "3763f73409a045f9"
topic: ""
url: "https://translate.google.com/translate_tts?ie=UTF-8&client=tw-ob&tl=en&q=Hello"
statusCode: 200
headers: object
content-type: "audio/mpeg"
cache-control: "no-cache, no-store, max-age=0, must-revalidate"
pragma: "no-cache"
expires: "Mon, 01 Jan 1990 00:00:00 GMT"
date: "Mon, 13 Dec 2021 14:08:36 GMT"
p3p: "CP="This is not a P3P policy! See P3P and Google's cookies - Google Account Help for more info.""
content-security-policy: "require-trusted-types-for 'script';report-uri /
/TranslateApiHttp/cspreport, script-src 'report-sample' 'nonce-Lyv8scDErHIZC5WF9zHYRw' 'unsafe-inline';object-src 'none';base-uri 'self';report-uri //TranslateApiHttp/cspreport;worker-src 'self'"
cross-origin-resource-policy: "cross-origin"
cross-origin-opener-policy: "same-origin"
transfer-encoding: "chunked"
server: "ESF"
x-xss-protection: "0"
x-frame-options: "SAMEORIGIN"
x-content-type-options: "nosniff"
set-cookie: array[1]
alt-svc: "h3=":443"; ma=2592000,h3-29=":443"; ma=2592000,h3-Q050=":443"; ma=2592000,h3-Q046=":443"; ma=2592000,h3-Q043=":443"; ma=2592000,quic=":443"; ma=2592000; v="46,43""
connection: "close"
x-node-red-request-node: "4326cab4"
responseUrl: "https://translate.google.com/translate_tts?ie=UTF-8&client=tw-ob&tl=en&q=Hello"
redirectList: array[0]
retry: 0
responseCookies: object
NID: object
payload: ""
rc: object
code: 0
13/12/2021, 14:08:38node: 1c579e8dcde38857
msg : Object
object
msgid: "3763f73409a045f9"
topic: ""
url: "https://translate.google.com/translate_tts?ie=UTF-8&client=tw-ob&tl=en&q=Hello"
statusCode: 200
headers: object
content-type: "audio/mpeg"
cache-control: "no-cache, no-store, max-age=0, must-revalidate"
pragma: "no-cache"
expires: "Mon, 01 Jan 1990 00:00:00 GMT"
date: "Mon, 13 Dec 2021 14:08:36 GMT"
p3p: "CP="This is not a P3P policy! See P3P and Google's cookies - Google Account Help for more info.""
content-security-policy: "require-trusted-types-for 'script';report-uri /
/TranslateApiHttp/cspreport, script-src 'report-sample' 'nonce-Lyv8scDErHIZC5WF9zHYRw' 'unsafe-inline';object-src 'none';base-uri 'self';report-uri /
/TranslateApiHttp/cspreport;worker-src 'self'"
cross-origin-resource-policy: "cross-origin"
cross-origin-opener-policy: "same-origin"
transfer-encoding: "chunked"
server: "ESF"
x-xss-protection: "0"
x-frame-options: "SAMEORIGIN"
x-content-type-options: "nosniff"
set-cookie: array[1]
0: "NID=511=K1hvWZFJNwX6TAdr4ZHxOOiSrVJmVhx-CrkezP4YSSqvbIGUunkAlHONx0aS76oNljmBs006adUTC3F8BeOr2pe-VcgCPaUt9qPwcpH-CaSKeaydzA3e4btuVQNjpesBF9m6NOoO9N92UvH9o55xnxFj0889Sz1ZgWNvE_ErI2g; expires=Tue, 14-Jun-2022 14:08:36 GMT; path=/; domain=.google.com; HttpOnly"
alt-svc: "h3=":443"; ma=2592000,h3-29=":443"; ma=2592000,h3-Q050=":443"; ma=2592000,h3-Q046=":443"; ma=2592000,h3-Q043=":443"; ma=2592000,quic=":443"; ma=2592000; v="46,43""
connection: "close"
x-node-red-request-node: "4326cab4"
responseUrl: "https://translate.google.com/translate_tts?ie=UTF-8&client=tw-ob&tl=en&q=Hello"
redirectList: array[0]
retry: 0
responseCookies: object
NID: object
expires: "Tue, 14-Jun-2022 14:08:36 GMT"
path: "/"
domain: ".google.com"
value: "511=K1hvWZFJNwX6TAdr4ZHxOOiSrVJmVhx-CrkezP4YSSqvbIGUunkAlHONx0aS76oNljmBs006adUTC3F8BeOr2pe-VcgCPaUt9qPwcpH-CaSKeaydzA3e4btuVQNjpesBF9m6NOoO9N92UvH9o55xnxFj0889Sz1ZgWNvE_ErI2g"
payload: object
code: 0

since you have already translated a word, you could add an inject directly to the exec node to play the file.

Have you inserted a set of headphons to the audio jace to see if you hear sound from them with the DISPLAY=:0 removed (copy the exec node to a seperate fow to experiment with)

I'm using raspberry pi zeros, so no headphone jack. I've used an inject node into the exec and it still needs the DISPLAY=:0 to work. Admittedly the output to Stdout and return code are much more succinct when using the inject node.

without DISPLAY=:0 the debug output is

13/12/2021, 15:09:23node: 0873e50e140abde5msg : Object

object

_msgid: "727da33416e68966"

topic: ""

payload: ""

rc: object

code: 0

13/12/2021, 15:09:23node: 1c579e8dcde38857msg : Object

object

_msgid: "727da33416e68966"

topic: ""

payload: object

code: 0

I assume you are using the 'Desktop' version of Buster on the PiZero. Is it a PiZero W model 1 or 2?

Were your prior installs of raspbian the desktop version too?

Yes desktop version of Buster. When it worked without DISPLAY=:0 on Stretch I was using version 1 of Node Red and PiZero W model 2. There has always been a delay in the bluetooth audio output via exec node, whereas from VNC Viewer using the terminal it is instant. I believe there was a change in BlueZ with Buster, but why node red should require DISPLAY=:0 for the exec node, I have no idea, but at least I managed to resolve the issue by it's inclusion. It would have been nice to have got a slicker response on the bluetooth output, but I guess it is what it is, and 5 sec is not too bad.

Thanks for your interest in trying to address the issue.

You might try asking on the raspberrypi foundation’s forum.

True, perhaps I should raise a query there, but it does seem to be associated with a peculiarity as to how executable code in the terminal doesn't get implemented as expected in node red EXEC node.

If you connect to the pi using SSH and run the command there, does it work?

Yes,

ffplay Desktop/audio.mp3 >/dev/null 2>&1 -vn -autoexit -nodisp ssh

works fine using ssh or via VNC Viewer, but in node red EXEC node requires prefixing with DISPLAY=:0

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.