Invalid input: NaN using rpi gpio

I'm trying to get the following flow working. According to the debug output of "on" or "off", msg.payload is "1" or "0" as a number. But the status of pump says Invalid input: NaN and nrgpio python command not running, but

sudo -u nodejs-node-red ./nrgpio 11 1

works fine.

Flow in json:

[{"id":"9c89b46.7714ec8","type":"mqtt in","z":"8ce28174.9fb388","name":"","topic":"moisture","qos":"2","datatype":"auto","broker":"4eca0d68.048e1c","x":110,"y":140,"wires":[["6e2d378b.4cead"]]},{"id":"9f0cdea8.902a58","type":"switch","z":"8ce28174.9fb388","name":"moisture-check","property":"payload","propertyType":"msg","rules":[{"t":"lte","v":"150","vt":"num"},{"t":"gt","v":"150","vt":"num"}],"checkall":"false","repair":false,"outputs":2,"x":280,"y":140,"wires":[["6e928127.00bcb"],["cbd6ccf6.bdd2f"]]},{"id":"6e928127.00bcb","type":"change","z":"8ce28174.9fb388","name":"on","rules":[{"t":"set","p":"payload","pt":"msg","to":"1","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":540,"y":100,"wires":[["9dfe863e.05ef28","4cbb16b7.84f4"]]},{"id":"cbd6ccf6.bdd2f","type":"change","z":"8ce28174.9fb388","name":"off","rules":[{"t":"set","p":"payload","pt":"msg","to":"0","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":500,"y":180,"wires":[["9dfe863e.05ef28","4cbb16b7.84f4"]]},{"id":"904486c0.910a88","type":"inject","z":"8ce28174.9fb388","name":"","topic":"","payload":"100","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":130,"y":220,"wires":[["9f0cdea8.902a58"]]},{"id":"bc7c5992.5168","type":"status","z":"8ce28174.9fb388","name":"","scope":null,"x":520,"y":300,"wires":[["4cbb16b7.84f4"]]},{"id":"6e2d378b.4cead","type":"debug","z":"8ce28174.9fb388","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":280,"y":80,"wires":[]},{"id":"9dfe863e.05ef28","type":"debug","z":"8ce28174.9fb388","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":740,"y":60,"wires":[]},{"id":"4cbb16b7.84f4","type":"rpi-gpio out","z":"8ce28174.9fb388","name":"pump","pin":"11","set":"","level":"0","freq":"","out":"out","x":740,"y":180,"wires":[]},{"id":"4eca0d68.048e1c","type":"mqtt-broker","z":"","name":"localhost","broker":"localhost","port":"1883","clientid":"","usetls":false,"compatmode":false,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""}]

@bjo welcome to the forum!

Why are you sending the output of the status node to the gpio node? that is what is causing the issue.
send it to a debug node.

Hi, pretty sure you shouldn't be running node-red as sudo but hey ho.

Put debug nodes on all outputs of all nodes & see what is actually going into the pump. Trace it back to see where the problem originates.

If you get stuck, put a unique name all your debug nodes, screen shot the flow and debug output. (The named debug nodes help someone correlate each message in the debug window to the screenshot)

I just tried to get an idea why nrgpio python command not running happens, I thougt the status node could tell me that. But the python command is also not running when pump gets triggered correctly.

It can tell you some information, but you don't want to send it to the gpio node since that expect to see a 1 or 0 ot true or false. Send it to a debug node

Or are you saying you want to see the status displayed in the backend but not in the debug node?

where are you seeing that?

According to the debug node, the sent numbers to the gpio node are correct. But the debug window still tells nrgpio python command not running and I have no clue why the python command fails.

How did you install node-red? Did you use the recommended script from

Try running sudo apt install rpi.gpio and restart NR and see what happens

It's already installed, from node-red-node-pi-gpio throws no exception.
But running ./nrgpio out 11 1 as node-red-user throws

Traceback (most recent call last):
  File "./", line 84, in <module>
RuntimeError: No access to /dev/mem.  Try running as root!

So I should check the udev rules.

It's installed from AUR: as also python-raspberry-gpio, node-red-node-pi-gpio was installed manually.

Google suggests that error can be caused by mis-matched versions of s/w. Are you running Arch Linux rather than Raspbian?

Thanks for all your help! Finally I stumpled upon, put

SUBSYSTEM=="bcm2835-gpiomem", KERNEL=="gpiomem", GROUP="gpio", MODE="0660"
SUBSYSTEM=="gpio", KERNEL=="gpiochip*", ACTION=="add", PROGRAM="/bin/sh -c 'chown root:gpio /sys/class/gpio/export /sys/class/gpio/unexport ; chmod 220 /sys/class/gpio/export /sys/class/gpio/unexport'"
SUBSYSTEM=="gpio", KERNEL=="gpio*", ACTION=="add", PROGRAM="/bin/sh -c 'chown root:gpio /sys%p/active_low /sys%p/direction /sys%p/edge /sys%p/value ; chmod 660 /sys%p/active_low /sys%p/direction /sys%p/edge /sys%p/value'"

into a udev rule and got it working. Raspbian has this rule out of box, but not Arch Linux.

1 Like

@bjo Did you also have to add the user to gpio group or was that already in place ?

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