RuntimeError: This module can only be run on a Raspberry Pi!

Hi, I'm trying to set up my Node-red with balena and have managed to get everything pushing correctly, and it is running the correct flow files. The issue I'm getting, however, is that my GPIO pins don't seem to be running at all.

I'm getting this error when the node-red starts in my container:

Traceback (most recent call last):
    File "/usr/local/lib/node_modules/node-red-node-pi-gpio/", line 4, in <module>
        import RPi.GPIO as GPIO
    File "/usr/lib/python2.7/dist-packages/RPi/GPIO/", line 23, in <module>
        from RPi._GPIO import *
RuntimeError: This module can only be run on a Raspberry Pi!

I have checked that the rpi.gpio was in my dockerfile, but it still isn't working.

This is a copy of my docker file:

# Build step
FROM balenalib/raspberrypi4-64-debian-node:latest-build as build

RUN JOBS=MAX npm install -g --production --unsafe-perm \
        node-red \
        node-red-admin \
	node-red-node-pi-gpio \
        node-red-contrib-azure-iot-hub \
	node-red-contrib-frequency-meter \
        node-red-contrib-ibm-watson-iot \
	node-red-contrib-os \
	node-red-dashboard \
# Runtime image
FROM balenalib/raspberrypi4-64-debian-node:latest-run

RUN apt-get update && apt-get install -yq --no-install-recommends \
	build-essential \
	rpi.gpio \
  	python-dev \
  	python-rpi.gpio \
  	&& apt-get clean && rm -rf /var/lib/apt/lists/* && \

# Defines our working directory in container
WORKDIR /usr/src/app

# Copy over the files created in the previous step, including lib/, bin/
COPY --from=build /usr/local/bin /usr/local/bin
COPY --from=build /usr/local/lib/node_modules /usr/local/lib/node_modules

# This will copy all files in our root to the working  directory in the container
COPY . ./

# server.js will run when container starts up on the device
CMD ["bash", "/usr/src/app/"]

This is what it looks like from my flow:

Can anyone help?


Is your docker container set up to be able to access the GPIO pins of the underlying host system?

I'm not sure. I had a read of the link you sent me but I wouldn't know where to put it into my Dockerfile/container settings as it's on Balena.

Could it be something to do with this?

How would I set up my dockerfile so that it uses this?

Have you read the full thing?

Start by doing exactly that. And no, I wouldn't have a clue how to do that with Docker/Balena, as I've never used either for this. But start by reading documentation and try to figure it out by yourself, then post back by the time you're absolutely stuck and can't find anything else how to do. While there are a quite a few topics about node-red inside docker, there are not so many about using it with Balena, so you might need to find different resources for that, then combine those with what you learned elsewhere.

Yeah, I read the full thing. I understand how to install the node-red-node-pi-gpiod module through the dockerfile, and it should already be installed. The error message is listing files from this module. I can't work out what is causing the traceback error as I should have these installed already by the dockerfile.

You are correct - it is hard to find topics about using Node-red in balena. I'll keep trying different things and update this thread if I get it working.

Thanks for your help.

What it says is that you need to installs those node(s) within the docker container, but also run the daemon mentioned on the host system aka the pi itself. And how to set that up with Balena I wouldn't have a clue at all.

I do have a script that runs on container start that I could possibly use to run the daemon

I tried adding this to it, but it didn't fix the error.

/usr/bin/pigpiod -l

I managed to get rid on the traceback error by removing node-red-node-pi-gpio from my dockerfile and replacing it with node-red-node-pi-gpiod. I've installed node-red-node-pi-gpiod on my dev Pi, however I can't get it to control my GPIOs. I've set up a test flow to flash an LED - it works with the standard RPi gpio node, but not with the pi gpiod node.

Here is my flow:

[{"id":"2968f5ec.06947a","type":"inject","z":"a332f9fb.e84ee8","name":"","topic":"","payload":"1","payloadType":"num","repeat":"2","crontab":"","once":true,"onceDelay":0.1,"x":250,"y":180,"wires":[["aceda92.ac54d58"]]},{"id":"aceda92.ac54d58","type":"trigger","z":"a332f9fb.e84ee8","op1":"1","op2":"0","op1type":"num","op2type":"num","duration":"1","extend":false,"units":"s","reset":"","bytopic":"all","name":"","x":420,"y":180,"wires":[["ce128624.cbd188","40ffb5d.021444c"]]},{"id":"ce128624.cbd188","type":"debug","z":"a332f9fb.e84ee8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":610,"y":180,"wires":[]},{"id":"40ffb5d.021444c","type":"pi-gpiod out","z":"a332f9fb.e84ee8","name":"","host":"localhost","port":8888,"pin":"21","set":"","level":"0","out":"out","sermin":"1000","sermax":"2000","x":600,"y":140,"wires":[]}]

In addition to the gpio pins not working on my development pi, when I push this to balena it gives me this error on node red startup:


Have you set up the gpio daemon on the host as well, so not just installed, but set up for usage following the instructions and have it running?
Furthermore, the IP address that the connection got refused to is localhost port 8888. If this runs inside a docker container, localhost means "within that same docker container". If the container is set up so that things inside are forward to outside it (I can't remember how to do this, check the docker docs), that might be different but make sure you check that too.

Hi I set up the daemon in the /etc/rc.local as shown here.

I'll see if I can find anything about that in the Balena docs.


The issue with docker accessing the gpiod of the host was talk of the #docker channel discussion on the Node-RED Slack yesterday. If you join that channel (or join slack first if needed) it might be worth reading back or seeing if people can help you there.