"nrgpio python command not running" error

Hi! After not being able to solve this issue with a lot of Google, I decided to ask for help here. But first things first, the system:

Rpi 2B
Latest Raspberry OS Lite (installed today)
did a full apt-get update && apt-get upgrade right after
Installed node.red with the installer script recommended here: Running on Raspberry Pi : Node-RED
Python version: 3.9.2
Node-RED version: v3.1.1
Node.js version: v18.19.0
Linux 6.1.64-v7+ arm LE

Now my issue - all nodes/workflows (mainly reading tons of 1wire temp sensors and plotting data) work fine. However, I can not control GPIOs from within node.red:

I tried manually installing the gpio package as recommended elsewhere (sudo apt-get install rpi.gpio), no change. I can directly control the GPIO (and confirmed the pin changing status with a LED) the following way: sudo python .node-red/node_modules/node-red-node-pi-gpio/nrgpio.py out 12 {1|0}.

I am a bit lost how to further debug this issue... If anyone has some ideas, I would be very grateful.

I don't know if it will help but could you stop and restart node-red using
node-red-stop
node-red-start
and then post the full output here. Copy/paste please not screenshot.

Also please post the file .node-red/package.json.

Here you go:

pi@nodered:~ $ node-red-stop
Stop Node-RED

Use   node-red-start   to start Node-RED again

pi@nodered:~ $ node-red-start

Start Node-RED

Once Node-RED has started, point a browser at http://192.168.178.36:1880
On Pi Node-RED works better with the Firefox or Chrome browser

Use   node-red-stop                          to stop Node-RED
Use   node-red-start                         to start Node-RED again
Use   node-red-log                           to view the recent log output
Use   sudo systemctl enable nodered.service  to autostart Node-RED at every boot
Use   sudo systemctl disable nodered.service to disable autostart on boot

To find more nodes and example flows - go to http://flows.nodered.org

Starting as a systemd service.
3 Dec 14:57:45 - [info]
Welcome to Node-RED
===================
3 Dec 14:57:45 - [info] Node-RED version: v3.1.1
3 Dec 14:57:45 - [info] Node.js  version: v18.19.0
3 Dec 14:57:45 - [info] Linux 6.1.64-v7+ arm LE
3 Dec 14:57:50 - [info] Loading palette nodes
3 Dec 14:57:57 - [info] Dashboard version 3.6.1 started at /ui
3 Dec 14:57:59 - [info] Settings file  : /home/pi/.node-red/settings.js
3 Dec 14:57:59 - [info] Context store  : 'default' [module=memory]
3 Dec 14:57:59 - [info] User directory : /home/pi/.node-red
3 Dec 14:57:59 - [warn] Projects disabled : editorTheme.projects.enabled=false
3 Dec 14:57:59 - [info] Flows file     : /home/pi/.node-red/flows.json
3 Dec 14:57:59 - [info] Server now running at http://127.0.0.1:1880/
3 Dec 14:57:59 - [warn]
---------------------------------------------------------------------
Your flow credentials file is encrypted using a system-generated key.
If the system-generated key is lost for any reason, your credentials
file will not be recoverable, you will have to delete it and re-enter
your credentials.
You should set your own key using the 'credentialSecret' option in
your settings file. Node-RED will then re-encrypt your credentials
file using your chosen key the next time you deploy a change.
---------------------------------------------------------------------
3 Dec 14:58:00 - [info] Starting flows
3 Dec 14:58:00 - [info] Started flows
3 Dec 14:58:02 - [error] [rpi-gpio out:3bb6a3d2f961c981] nrgpio python command not running
3 Dec 14:59:09 - [error] [rpi-gpio out:3bb6a3d2f961c981] nrgpio python command not running
3 Dec 15:00:09 - [error] [rpi-gpio out:3bb6a3d2f961c981] nrgpio python command not running

package.json:

{
  "name": "node-red-project",
  "description": "initially created for you by Node-RED 3.1.1",
  "version": "0.0.1",
  "private": true,
  "dependencies": {
    "node-red-contrib-1wire": "~0.0.2",
    "node-red-contrib-bigtimer": "~2.8.5",
    "node-red-contrib-bool-gate": "~1.0.2",
    "node-red-contrib-buffer-parser": "^3.2.2",
    "node-red-contrib-play-audio": "^2.5.0",
    "node-red-dashboard": "~3.6.1",
    "node-red-node-pi-gpio": "^2.0.6",
    "node-red-node-ping": "^0.3.3",
    "node-red-node-random": "^0.4.1",
    "node-red-node-serialport": "^2.0.0",
    "node-red-node-smooth": "^0.1.2"
  }
}

I can't see anything wrong there. I think we need an expert on gpio.

Thanks for your help so far - much appreciated!

My best guess is, it is either a PATH or permission issue (nodered can not access the GPIOs), or a python version incompatibility (maybe the GPIO control plugin was installed to the system python version and nodered uses its own it brings along?), or it has issues with my ancient Pi and I would need a newer Pi or an older application version?

Just guessing in the dark there though, I'm at wits end.

If you haven't put much work in on it, I would personally try it again but with the last not the current OS version and see if that's the issue

I would mainly have to copy my flow over, not that big of a deal, but the pi is in the boiler room in the basement and not easy to reach (to swap the SD), the less on-hardware-time I have to spend, the better. Would be my last resort.

can you cd into your /home/pi/.node-red/node_modules/node-red-node-pi-gpio directory and run ./nrgpio ver on the command line and show us the result. And also run python --version and report that as well

Thanks

Check! Here is the output.

pi@nodered:~ $ cd /home/pi/.node-red/node_modules/node-red-node-pi-gpio
pi@nodered:~/.node-red/node_modules/node-red-node-pi-gpio $ ./nrgpio ver
0.7.0
pi@nodered:~/.node-red/node_modules/node-red-node-pi-gpio $ python --version
Python 3.9.2

ok - now confused as that is the command the runtime should be running... and it seems to be installed ok and python is ok as well...

can you try running node-red locally - ie node-red-stop to stop the service then in your /home/pi/.node-red directory just run node-red

Thank you for the suggestion, sadly this led me to the exact same result:

pi@nodered:~/.node-red $ node-red
3 Dec 23:48:03 - [info]

Welcome to Node-RED
===================

3 Dec 23:48:03 - [info] Node-RED version: v3.1.1
3 Dec 23:48:03 - [info] Node.js  version: v18.19.0
3 Dec 23:48:03 - [info] Linux 6.1.64-v7+ arm LE
3 Dec 23:48:08 - [info] Loading palette nodes
3 Dec 23:48:14 - [info] Dashboard version 3.6.1 started at /ui
3 Dec 23:48:16 - [info] Settings file  : /home/pi/.node-red/settings.js
3 Dec 23:48:16 - [info] Context store  : 'default' [module=memory]
3 Dec 23:48:16 - [info] User directory : /home/pi/.node-red
3 Dec 23:48:16 - [warn] Projects disabled : editorTheme.projects.enabled=false
3 Dec 23:48:16 - [info] Flows file     : /home/pi/.node-red/flows.json
3 Dec 23:48:16 - [info] Server now running at http://127.0.0.1:1880/
3 Dec 23:48:16 - [warn]

---------------------------------------------------------------------
Your flow credentials file is encrypted using a system-generated key.

If the system-generated key is lost for any reason, your credentials
file will not be recoverable, you will have to delete it and re-enter
your credentials.

You should set your own key using the 'credentialSecret' option in
your settings file. Node-RED will then re-encrypt your credentials
file using your chosen key the next time you deploy a change.
---------------------------------------------------------------------

3 Dec 23:48:17 - [info] Starting flows
3 Dec 23:48:17 - [info] Started flows
3 Dec 23:48:19 - [error] [rpi-gpio out:3bb6a3d2f961c981] nrgpio python command not running

I take it that these logs were not helpful in narrowing it down? Anything left for me to do that's not a clean install of the system? Might actually switch over to a Pi 3B I recently freed up elsewhere, so I'll probably have to do it anyway. If I can help with any logs until then, pls tell :slight_smile:

There should be no problem running on an older Raspberry Pi.

I don't know but I doubt if Node-red calls nrgpio.py with sudo.
What happens if you run your command line without sudo or python?
What does ls -l ~/.node-red/node_modules/node-red-node-pi-gpio/nrgpio.py show you?

There have been significant changes to GPIO handling with RPiOS Bookworm, you might find everything works with the latest Bullseye version.

ls -l ~/.node-red/node_modules/node-red-node-pi-gpio/nrgpio.py
-rwxr-xr-x 1 pi pi 7185 Dec  2 15:22 /home/pi/.node-red/node_modules/node-red-node-pi-gpio/nrgpio.py
./.node-red/node_modules/node-red-node-pi-gpio/nrgpio.py out 12 1
./.node-red/node_modules/node-red-node-pi-gpio/nrgpio.py: line 3: import: command not found
./.node-red/node_modules/node-red-node-pi-gpio/nrgpio.py: line 4: import: command not found
./.node-red/node_modules/node-red-node-pi-gpio/nrgpio.py: line 5: import: command not found
./.node-red/node_modules/node-red-node-pi-gpio/nrgpio.py: line 6: import: command not found
./.node-red/node_modules/node-red-node-pi-gpio/nrgpio.py: line 7: import: command not found
./.node-red/node_modules/node-red-node-pi-gpio/nrgpio.py: line 8: from: command not found
./.node-red/node_modules/node-red-node-pi-gpio/nrgpio.py: line 10: try:: command not found
./.node-red/node_modules/node-red-node-pi-gpio/nrgpio.py: line 11: raw_input: command not found
./.node-red/node_modules/node-red-node-pi-gpio/nrgpio.py: line 12: except: command not found
./.node-red/node_modules/node-red-node-pi-gpio/nrgpio.py: line 13: raw_input: command not found
./.node-red/node_modules/node-red-node-pi-gpio/nrgpio.py: line 15: bounce: command not found
./.node-red/node_modules/node-red-node-pi-gpio/nrgpio.py: line 17: syntax error near unexpected token `sys.argv'
./.node-red/node_modules/node-red-node-pi-gpio/nrgpio.py: line 17: `if len(sys.argv) > 2:'
python ./.node-red/node_modules/node-red-node-pi-gpio/nrgpio.py out 12 1
Traceback (most recent call last):
  File "/home/pi/./.node-red/node_modules/node-red-node-pi-gpio/nrgpio.py", line 70, in <module>
    GPIO.setup(pin,GPIO.OUT)
RuntimeError: No access to /dev/mem.  Try running as root!

That's good to know, thanks!

Oh, I'm still on Bullseye - that was what the rpi imager offered me as the latest stable when I set it up.

OK that shows it does need to run with sudo and python and it was apparently not installed by root.

I have no more ideas, all I can suggest is using the exec node to call it instead of the gpio node.
Put a debug node on the 2nd output to show any errors

Thats RPiOS Legacy then. Perhaps I was too hasty saying an old Pi should be OK (I know Node-red runs on a Pi Zero but I don't use the gpio nodes)

1 Like

@ebastler I just

  1. flashed an SD card with 2023-05-03-raspios-bullseye-armhf-lite.img then
  2. Put it in a Pi 2 Model B v1.1 and then
  3. ran sudo apt update then
  4. ran sudo apt full-upgrade -y then
  5. ran bash <(curl -sL https://raw.githubusercontent.com/node-red/linux-installers/master/deb/update-nodejs-and-nodered) --node18

Node-red starts fine and adding a inject connected to a rpi-gpio out sending 0 or 1 or true or false they all work fine.

pmw@gpiopi:~ $ node-red
16 Dec 09:43:03 - [info] 

Welcome to Node-RED
===================

16 Dec 09:43:03 - [info] Node-RED version: v3.1.3
16 Dec 09:43:03 - [info] Node.js  version: v18.19.0
16 Dec 09:43:03 - [info] Linux 6.1.21-v7+ arm LE
16 Dec 09:43:07 - [info] Loading palette nodes
16 Dec 09:43:13 - [info] Settings file  : /home/pmw/.node-red/settings.js
16 Dec 09:43:13 - [info] Context store  : 'default' [module=memory]
16 Dec 09:43:13 - [info] User directory : /home/pmw/.node-red
16 Dec 09:43:13 - [warn] Projects disabled : editorTheme.projects.enabled=false
16 Dec 09:43:13 - [info] Flows file     : /home/pmw/.node-red/flows.json
16 Dec 09:43:13 - [warn] 

---------------------------------------------------------------------
Your flow credentials file is encrypted using a system-generated key.

If the system-generated key is lost for any reason, your credentials
file will not be recoverable, you will have to delete it and re-enter
your credentials.

You should set your own key using the 'credentialSecret' option in
your settings file. Node-RED will then re-encrypt your credentials
file using your chosen key the next time you deploy a change.
---------------------------------------------------------------------

16 Dec 09:43:13 - [warn] Encrypted credentials not found
16 Dec 09:43:13 - [info] Server now running at http://127.0.0.1:1880/
16 Dec 09:43:13 - [info] Starting flows
16 Dec 09:43:13 - [info] Started flows

This leads me to believe that you have installed or uninstalled something else that is causing the conflict.

2 Likes

Wow I admire your patience running apt -y full-upgrade on a Pi2 :slight_smile:

@zenofmud huh, this is very weird, I can not remember having done anything else. Thank you for your patience - this clearly shows the issue is local to my system and likely due to some config error or package conflict.

I did not run the apt full-upgrade (what does that do?) but I think apt update and apt upgrade should be enough. Only thing I did was change some things in config.txt because I'm using a 800x480 touchscreen on the pi, and enable 1wire temp sensors.

I think at this point I will give up debugging, export my workflows and reinstall the whole thing. Faster and less effort than trying to find the conflict.

Since I freed a Pi3B from another application yesterday, I'll probably swap the controller anyway - Pi3 should be a whole lot faster than Pi2. Then the effort of going through a reinstall will hurt less :smile:

I will report back next week when I found the time to swap the Rpi over and do a clean install!

Thanks to everybody for the help in debugging and narrowing down my issue.

Hopefully, at 2.5 you did sudo apt update