[Help!] exec node + pulseaudio

Hi

That code referred to the fact that your code failed and I had to change the 0 to a 1 to get it to work.
Once I changed the zero to a 1, then the command worked in the terminal.

The errors I get are:

Google chrome on my laptop
Connecting to nodered via http://192.168.1.xxx:1880
Then running the commands via an exec node.
I get Connection failure: Connection refused
pa_context_connect() failed: Connection refused

and

amixer: Unable to find simple control 'Master',0

Regards
Brendon

have you done any configuration to pluseaudio?
the reason I ask is that if I use:
pactl -- set-sink-volume 0 20%
it works, but if I use
pactl -- set-sink-volume 1 20%
I get an error: Failed to get sink information: No such entity

I haven't made any configuration changes to pulseaudio.
I just tried again. Same result.
I am using a USB speaker connected via a USB hub - don't know if that makes a difference?

Try disconnecting the usb hub and speaker and see what happens

With the hub and speaker disconnected...

Terminal via VNC/SSH:
pactl -- set-sink-volume 1 20%
Failed to get sink information: No such entity

pactl -- set-sink-volume 0 20%
Failed to get sink information: No such entity

amixer set Master 70%
Simple mixer control 'Master',0
Capabilities: pvolume pswitch pswitch-joined
Playback channels: Front Left - Front Right
Limits: Playback 0 - 65536
Mono:
Front Left: Playback 45875 [70%] [on]
Front Right: Playback 45875 [70%] [on]

Via nodered using laptop chrome to connect:
pactl -- set-sink-volume 1 20%
Connection failure: Connection refused
pa_context_connect() failed: Connection refused

amixer set Master 70%
amixer: Mixer attach default error: No such file or directory

What do you get if you run
amixer -version
I get

console1@console1:~ $ amixer -version
amixer version 1.2.4

can you try accessing NR from another device and with a different browser to see if the laptop/chrome is part of the issue?

I have the same version
I tried from Edge on the laptop, and from Chrome on my phone - both browsers give the same errors as before

SSH into the pi and run
pacmd list-sinks | grep -e 'name:' -e 'index:'
copy and paste the results.

after flashing the SD card did you install anyother software (maybe to control the HAT)?

On my Pi I get:

console1@console1:~ $ pacmd list-sinks | grep -e 'name:' -e 'index:'
  * index: 0
	name: <auto_null>
console1@console1:~ $ 

You might want to read this: audio - Is there a consistent shell command for adjusting volume? - Unix & Linux Stack Exchange

I get

pacmd list-sinks | grep -e 'name:' -e 'index:'

  • index: 1
    name: <alsa_output.usb-Generic_USB2.0_Device_20130100ph0-00.analog-stereo>

Please answer all the questions

No, no other software:

  1. Raspbian via imager
  2. Node-red using standard installation instructions

I am using a hub, not a HAT.

I have just borrowed a Pi 4. I'm going to do a basic installation and will report on how that goes.

Thanks
Brendon

what is this device?

That is the USB hub or, more likely, the USB speaker.
What audio output device are you testing with on a Pi Zero?

So did you have to install anything or setup anything for the hub and/or speaker? That is probably where the issue is coming from.

I have no audio out device seeing that this is a pi zero with no headphone jack.

Hi. There are no installation steps or software for the hub or speaker - just plug and play.
I disconnected them so that I have the same setup as you.
This is what I got:

With the hub and speaker disconnected...

Terminal via VNC/SSH:
pactl -- set-sink-volume 1 20%
Failed to get sink information: No such entity

pactl -- set-sink-volume 0 20%
Failed to get sink information: No such entity

amixer set Master 70%
Simple mixer control 'Master',0
Capabilities: pvolume pswitch pswitch-joined
Playback channels: Front Left - Front Right
Limits: Playback 0 - 65536
Mono:
Front Left: Playback 45875 [70%] [on]
Front Right: Playback 45875 [70%] [on]

Via nodered using laptop chrome to connect:
pactl -- set-sink-volume 1 20%
Connection failure: Connection refused
pa_context_connect() failed: Connection refused

amixer set Master 70%
amixer: Mixer attach default error: No such file or directory

It seems like things keep changing for you. First you can run commands and then you can’t.

If you can’t get it to run on the pi it’s not going to work via node-red.

You could try reflashing the SD card of the pi zero w and follow the steps I posted earlier and do not attach anything else and testing.

All I can tell you is that it works for me.

I started again...

Raspberry Pi 4 without every having connected the hub or speaker.
Standard build using Raspberry Pi imager (64bit)
Ran updates

cat /etc/os-release: PRETTY_NAME="Debian GNU/Linux 11 (bullseye)"
cat /sys/firmware/devicetree/base/model: Raspberry Pi 4 Model B Rev 1.2

Accessed terminal via VNC:

pactl -- set-sink-volume 0 15% worked
amixer set Master 70% worked

groups pi is correct
pi : pi adm dialout cdrom sudo audio video plugdev games users input render netdev spi i2c gpio lpadmin

amixer -version
amixer version 1.2.4

pacmd list-sinks | grep -e 'name:' -e 'index:'

  • index: 0
    name: <alsa_output.platform-bcm2835_audio.analog-stereo>

Installed base Node-RED

Standard install, no additional nodes
bash <(curl -sL https://raw.githubusercontent.com/node-red/linux-installers/master/deb/update-nodejs-and-nodered)

Ran node-red admin init
No user security
No projects
Pass raspb3rry
Default theme
Default editor
Allow Function nodes to load external modules? (functionExternalModules) ¡ Yes

Started node-red

node-red-start
Starting as a systemd service.
27 May 15:14:14 - [info]
Welcome to Node-RED

27 May 15:14:14 - [info] Node-RED version: v2.2.2
27 May 15:14:14 - [info] Node.js version: v14.19.3
27 May 15:14:14 - [info] Linux 5.15.32-v8+ arm64 LE
27 May 15:14:15 - [info] Loading palette nodes
27 May 15:14:17 - [info] Settings file : /home/pi/.node-red/settings.js
27 May 15:14:17 - [info] Context store : 'default' [module=memory]
27 May 15:14:17 - [info] User directory : /home/pi/.node-red
27 May 15:14:17 - [warn] Projects disabled : editorTheme.projects.enabled=false
27 May 15:14:17 - [info] Flows file : /home/pi/.node-red/flows.json
27 May 15:14:17 - [info] Creating new flow file
27 May 15:14:17 - [info] Server now running at http://127.0.0.1:1880/
27 May 15:14:17 - [info] Starting flows
27 May 15:14:17 - [info] Started flows

Imported your nodes

Your code above, under the text "I then installed NR using the script and created the following flows"

Accessed from laptop

http://192.168.16.85:1880/ via laptop

Exec node: pactl -- set-sink-volume 0 20%
Connection failure: Connection refused
pa_context_connect() failed: Connection refused

Exec node: amixer set Master 70%
amixer: Unable to find simple control 'Master',0

Accessed directly

http://127.0.0.1:1880 via chromium on the Pi (access via VNC)
Got exactly the same error messages

I added another exec node with touch ~/Documents/hello3.txt
Running that worked correctly
So did examples like rm, date, amixer -version
However, pacmd list-sinks gave back " " not the full output.

Hmmmm

Just to clarify, you VNCed into the pi and ran the updates and tested the ‘pactl’ command and it worked. You then install NR and after that the ‘pactl’ command fails.

Can you run a ‘history’ and copy/paste the results in a reply so I can run the exact commands you have run. Thanks

Just to clarify, you VNCed into the pi and ran the updates and tested the ‘pactl’ command and it worked.

Yes

You then install NR and after that the ‘pactl’ command fails.

It continues to work in terminal. It fails in Node-RED exec node.
The Raspberry Pi build, Node-RED installation and your example flow are free of any other configuration steps, conflicting nodes etc.
The errors on this new build on the Pi 4 are exactly the same as I experienced on the Pi Zero.

1 raspi-config
2 sudo raspi-config
3 sudo iwconfig
4 sudo ifconfig
5 sudo killall wpa_supplicant
6 sudo wpa_supplicant -c/etc/wpa_supplicant/wpa_supplicant.conf -iwlan0
7 cd /var/run/
8 ls
9 cd /
10 ls
11 cd boot
12 ls
13 sudo nano wpa_supplicant.conf
14 sudo reboot
15 ifconfig
16 sudo apt update
17 sudo apt upgrade
18 sudo rpi-eeprom-update
19 sudo rpi-eeprom-update -d -a
20 sudo reboot
21 sudo rpi-eeprom-update
22 ifconfig
23 sudo raspi-config
24 cat /etc/os-release
25 cat /sys/firmware/devicetree/base/model
26 groups pi
27 amixer -version
28 pacmd list-sinks | grep -e 'name:' -e 'index:'
29 ls
30 cd Documents
31 ls
32 mk hello.txt
33 touch hello.txt
34 ls
35 cd ..
36 touch ~/Documents/hello2.txt
37 cd documents
38 cd Documents
39 ls
40 cd ..
41 rm ~/Documents/hello2.txt
42 pacmd list-sinks
43 cd /lib/systemd/system/
44 ls
45 sudo nano nodered.service
46 history
47 clear

Your last post said

Accessed from laptop

http://192.168.16.85:1880/ via laptop

Exec node: pactl -- set-sink-volume 0 20%
Connection failure: Connection refused
pa_context_connect() failed: Connection refused

Exec node: amixer set Master 70%
amixer: Unable to find simple control 'Master',0

So which is it?

And why are you doing a rpi-eeprom-update?