Exec node - Bash file - error "VCHI initialization failed"

Hi all, new here.

I simply try to run a bash one-liner and not getting the stdout of it. Read all previous post around this topic and tried many things.

My script is this:

root@DietPi:/bin# ls -l GetTemp.bash
-rwxr-xr-x 1 root root 76 Dec 7 06:48 GetTemp.bash

#!/bin/bash
vcgencmd measure_temp | awk -F= '{printf("%.2f%.0d\n", $2, 0)}'

Running fine on SSH:

root@DietPi:/bin# GetTemp.bash
32.60

It's executable by all, did a chmod +x on it.

In node-red, I'm using an exec node, tried with a simple "hostname" command and it works fine

When I try to run my bash GetTemp.bash, it give this:

07/12/2020 Ă  07:10:02[node: b7b7f98f.11c0a8] msg.payload : string[0]
""

07/12/2020 Ă  07:10:02[node: b7b7f98f.11c0a8] msg.payload : string[27]
"VCHI initialization failed↵"

07/12/2020 Ă  07:10:02[node: b7b7f98f.11c0a8] msg.payload : Object
{ code: 0 }

I'v tried many variations in the command box in node-red.

  • bash -c GetTemp.bash
  • bash -c /bin/GetTemp.bash

I changed my code to do this:

#!/bin/bash
echo "hello World!"
vcgencmd measure_temp | awk -F= '{printf("%.2f%.0d\n", $2, 0)}'

And I get the "hello World".. but I don't get the output of measure_temp

07/12/2020 Ă  07:19:19[node: b7b7f98f.11c0a8] msg.payload : string[13]
"hello World!↵"

07/12/2020 Ă  07:19:19[node: b7b7f98f.11c0a8] msg.payload : string[27]
"VCHI initialization failed↵"

07/12/2020 Ă  07:19:19[node: b7b7f98f.11c0a8] msg.payload : Object
{ code: 0 }

I'm suspecting something with awk messing my stdout somehow, so I add tee

vcgencmd measure_temp | awk -F= '{printf("%.2f%.0d\n", $2, 0)}'|tee

But still not getting the output in node-red!

I then did this:
#!/bin/bash

echo "hello World!"
vcgencmd measure_temp | awk -F= '{printf("%.2f%.0d\n", $2, 0)}' > /tmp/t
cat /tmp/t

Now in node-red I get the temperature! But also errors:

07/12/2020 Ă  07:24:45[node: b7b7f98f.11c0a8] msg.payload : string[19]
"hello World!↵34.70↵"

07/12/2020 Ă  07:24:45[node: b7b7f98f.11c0a8] msg.payload : string[80]
"/bin/GetTemp.bash: line 3: /tmp/t: Permission denied↵VCHI initialization failed↵"

07/12/2020 Ă  07:24:45[node: b7b7f98f.11c0a8] msg.payload : Object
{ code: 0 }

Any clues anyone?

Permission denied

node-red does (or should) not run under root and has no permissions to execute.

There is a vcgencmd node available, makes it perhaps a bit easier.

1 Like

Maybe relocate to a different path and/or change ownership?

Cool. Didn't know about that.

Thanks for the info about the vcgencmd node, will try that.

It's not 100% accurate that the nodered user cannot execute. Since I do execute and get the output of the cat /tmp/t file. The chmod +x makes runnable by everyone.

The issue I think is related to awk and stdout running through bash... seen that before but don't remember the solution.

I did try to put the file in the nodered user directory, same issue.

The chmod applies to the script only, not to the underlying call to vcgencmd, which in turn also needs different permissions for other subsystems.

You could solve that by adding additional permissions to the video subsystem

sudo usermod -a -G video <username - not root>
1 Like

The node does not work unfortunately

The /usr/bin/vcgencmd command is not supported by this hardware platform

On SSH:

root@DietPi:~# vcgencmd measure_temp
temp=37.9'C
root@DietPi:~# which vcgencmd
/usr/bin/vcgencmd

I did this: usermod -a -G video nodered
and still have this error running the bash script.

/bin/GetTemp.bash: line 2: /tmp/t: Permission deniedVCHI initialization failed

But in the end, my script can output the temperature, so I'm good.

Did you see this possible answer ? VCHI initialization failed Raspberry Pi Fixed – The Chewett blog

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