Hello, All.
I've done a bit of searching, and I can't see to find anything answering my question.
I'm trying to run node-red in a docker image on a Raspberry Pi 3, and am having issues triggering GPIOs.
I'm using the following image:
Using the following path:
/usr/src/node-red/node_modules/@node-red/nodes/core/hardware
I run nrgpio out 5 1 (set pin 5 high )
Traceback (most recent call last):
File "./nrgpio.py", line 84, in
GPIO.setup(pin,GPIO.OUT)
RuntimeError: No access to /dev/mem. Try running as root!
I can't seem to find the special sauce to access /dev/mem.
Does anyone have any suggestions on how to move forward with this or should I abandon the effort and install it natively on the Pi?
docker-compose.yml bits:
nodered:
restart: always
privileged: true
image: nodered/node-red-docker:rpi
ports:
- "1880:1880"
#configs:
# - etcgroup:/etc/group
devices:
- /dev/mem:/dev/mem
- /dev/gpiomem:/dev/gpiomem
volumes:
# Add /etc/group with node-red user as member of group kmem
- ./etc-group:/etc/group
# add sudoers to add extra software not in the hypriot image.
- ./sudoers:/etc/sudoers
# sysfs for 1wire support - could also use for GPIO but would have to write my own functions?
- /sys:/sys
- nodered:/data
links:
- postgresql
- mqtt
volumes:
nodered:
external: true
-Darth
Do the standard Pi nodes not work in a Docker image?
I'm using the standard Pi GPIO output node.
I'm a rank beginner with Node-RED, but not necessarily sysadmin. I'm believe the RPi.GPIO package depends on /dev/mem, which seems to be an issue getting permissions to match up so it can write properly.
i modified my function to return {payload: 1} and my switch to test that it's 1. Now I get
For Debug from the RPI-GPIO node.
msg : string[33]
"nrpgio python command not running"
node-red@b5e7218c1461:~/node_modules/@node-red$ cd nodes/core/hardware/
node-red@b5e7218c1461:~/node_modules/@node-red/nodes/core/hardware$ ls
36-rpi-gpio.html 36-rpi-gpio.js direction nrgpio nrgpio.py
node-red@b5e7218c1461:~/node_modules/@node-red/nodes/core/hardware$ ./nrgpio
Bad parameters - in|out|pwm|buzz|byte|borg|mouse|kbd|ver|info {pin} {value|up|down}
node-red@b5e7218c1461:~/node_modules/@node-red/nodes/core/hardware$ ./nrgpio out 5
Traceback (most recent call last):
File "./nrgpio.py", line 84, in
GPIO.setup(pin,GPIO.OUT)
RuntimeError: No access to /dev/mem. Try running as root!
node-red@b5e7218c1461:~/node_modules/@node-red/nodes/core/hardware$ ls -l /dev/mem
crw-rw-rw- 1 root kmem 1, 1 Mar 20 16:12 /dev/mem
node-red@b5e7218c1461:~/node_modules/@node-red/nodes/core/hardware$ sudo !nrgpio
bash: !nrgpio: event not found
node-red@b5e7218c1461:~/node_modules/@node-red/nodes/core/hardware$ sudo ./nrgpio out 5
^C^C^C^C^./nrgpio: line 17: 394 Quit (core dumped) python -u BASEDIR/nrgpio.py @
node-red@b5e7218c1461:~/node_modules/@node-red/nodes/core/hardware$
node-red@b5e7218c1461:~/node_modules/@node-red/nodes/core/hardware$ sudo ./nrgpio info 5
node-red@b5e7218c1461:~/node_modules/@node-red/nodes/core/hardware$ sudo ./nrgpio info 1
I managed to get a hacked sudoers into the docker image so I could attempt to run things as "root". I suspect docker is being a nitwit here, even if I'm running in privileged mode.
Do you have python installed? I think you have to have V5.1 minimum
Have you tried the “accessing GPIO” instructions on the Raspberry Pi page in the docs?
https://nodered.org/docs/hardware/raspberrypi
the version of ubuntu in docker is not the same as raspbian for Pi so is not set up the same way, with things like GPIO already enabled and working. You would need to add in the extra driver libraries for the gpio and so on into the docker image and then give them permission to access the GPIO on the host side of the container etc...
Alternatively you could install the pigpiod on the host side of the device - and then use the node-red-node-pi-gpiod nodes - https://flows.nodered.org/node/node-red-node-pi-gpiod - to connect out to it over the local network instead.
1 Like
My understanding is that the version of node-red-pi in docker is based off of the hypriot Node image. Since the kernel is shared by docker and the host, the drivers should only be required in the host, no?
http://blog.hypriot.com/post/lets-get-physical/
I'm going to have to try this, it suggests the following:
docker run --rm --cap-add SYS_RAWIO --device /dev/mem hypriot/rpi-gpio write 0 on
Maybe there's something special about hypriot/rpi-gpio that isn't present in the base image node-red-pi is using.
I have tested a native host install, and it's working, so it's definitely because of the docker shims.
Seems like using the sysfs interface is the way to go, but that'll require rewriting the plugin. Something I haven't even looked at yet.