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

**URL:** https://discourse.nodered.org/t/runtimeerror-this-module-can-only-be-run-on-a-raspberry-pi/16255
**Category:** General
**Created:** [3 October 2019 12:04 UTC](https://discourse.nodered.org/t/runtimeerror-this-module-can-only-be-run-on-a-raspberry-pi/16255 "2019-10-03T12:04:45Z")
**Posts on this page:** 12
**Page:** 1

<div class="post-metadata">

### Author: ![GregorR1](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/gregorr1/32/12263_2.png) [@GregorR1](https://discourse.nodered.org/u/GregorR1)
#### Post date: [3 October 2019 12:04 UTC](https://discourse.nodered.org/t/runtimeerror-this-module-can-only-be-run-on-a-raspberry-pi/16255/1 "2019-10-03T12:04:45Z")

</div>

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:

```auto
Traceback (most recent call last):
    File "/usr/local/lib/node_modules/node-red-node-pi-gpio/testgpio.py", line 4, in <module>
        import RPi.GPIO as GPIO
    File "/usr/lib/python2.7/dist-packages/RPi/GPIO/ __init__.py", 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:

```auto
###
# 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 \
	node-red-contrib-simpletime
	
###
# 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/start.sh"]

```

This is what it looks like from my flow:  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/a/a808a1337f04f22720eea4520297a46f1030767b.png)

Can anyone help?

Thanks

---

<div class="post-metadata">

### Author: ![afelix](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/afelix/32/9743_2.png) [@afelix](https://discourse.nodered.org/u/afelix)
#### Post date: [3 October 2019 12:09 UTC](https://discourse.nodered.org/t/runtimeerror-this-module-can-only-be-run-on-a-raspberry-pi/16255/2 "2019-10-03T12:09:35Z")

</div>

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

> <https://stackoverflow.com/questions/30059784/docker-access-to-raspberry-pi-gpio-pins>

---

<div class="post-metadata">

### Author: ![GregorR1](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/gregorr1/32/12263_2.png) [@GregorR1](https://discourse.nodered.org/u/GregorR1)
#### Post date: [3 October 2019 12:17 UTC](https://discourse.nodered.org/t/runtimeerror-this-module-can-only-be-run-on-a-raspberry-pi/16255/3 "2019-10-03T12:17:13Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![GregorR1](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/gregorr1/32/12263_2.png) [@GregorR1](https://discourse.nodered.org/u/GregorR1)
#### Post date: [3 October 2019 12:25 UTC](https://discourse.nodered.org/t/runtimeerror-this-module-can-only-be-run-on-a-raspberry-pi/16255/4 "2019-10-03T12:25:45Z")

</div>

Could it be something to do with this?  
[https://nodered.org/docs/getting-started/docker#raspberry-pi---native-gpio-support](https://nodered.org/docs/getting-started/docker#raspberry-pi---native-gpio-support)

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

---

<div class="post-metadata">

### Author: ![afelix](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/afelix/32/9743_2.png) [@afelix](https://discourse.nodered.org/u/afelix)
#### Post date: [3 October 2019 12:41 UTC](https://discourse.nodered.org/t/runtimeerror-this-module-can-only-be-run-on-a-raspberry-pi/16255/5 "2019-10-03T12:41:23Z")

</div>

Have you read the full thing?

> [@](#):
>
> Disadvantages of the native GPIO support are:
> 
> - Your Docker container needs to be deployed on the same Docker node/host on which you want to control the gpio.
> - Gain access to /dev/mem of your Docker node/host
> - privileged=true is not supported for `docker stack` command
> 
> `node-red-node-pi-gpiod` solves all these disadvantages. With `node-red-node-pi-gpiod` it is possible to interact with gpio of multiple Raspberry Pi’s from a single Node-RED container, and for multiple containers to access different gpio on the same Pi.
> 
> #### Quick Migration steps to `node-red-node-pi-gpiod`
> 
> 1. Install `node-red-node-pi-gpiod` through the Node-RED pallette
> 2. Install and run `PiGPIOd daemon` on the host Pi.
> 3. Replace all native gpio nodes with `pi gpiod` nodes.
> 4. Configure `pi gpiod` nodes to connect to `PiGPIOd daemon`
> 
> For install instruction details please refer to the `node-red-node-pi-gpiod` [README](https://github.com/node-red/node-red-nodes/tree/master/hardware/pigpiod#node-red-node-pi-gpiod)

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.

---

<div class="post-metadata">

### Author: ![GregorR1](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/gregorr1/32/12263_2.png) [@GregorR1](https://discourse.nodered.org/u/GregorR1)
#### Post date: [3 October 2019 12:50 UTC](https://discourse.nodered.org/t/runtimeerror-this-module-can-only-be-run-on-a-raspberry-pi/16255/6 "2019-10-03T12:50:50Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![afelix](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/afelix/32/9743_2.png) [@afelix](https://discourse.nodered.org/u/afelix)
#### Post date: [3 October 2019 13:02 UTC](https://discourse.nodered.org/t/runtimeerror-this-module-can-only-be-run-on-a-raspberry-pi/16255/7 "2019-10-03T13:02:55Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![GregorR1](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/gregorr1/32/12263_2.png) [@GregorR1](https://discourse.nodered.org/u/GregorR1)
#### Post date: [3 October 2019 13:13 UTC](https://discourse.nodered.org/t/runtimeerror-this-module-can-only-be-run-on-a-raspberry-pi/16255/8 "2019-10-03T13:13:29Z")

</div>

I do have a start.sh 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.

```auto
/usr/bin/pigpiod -l

```

---

<div class="post-metadata">

### Author: ![GregorR1](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/gregorr1/32/12263_2.png) [@GregorR1](https://discourse.nodered.org/u/GregorR1)
#### Post date: [4 October 2019 11:48 UTC](https://discourse.nodered.org/t/runtimeerror-this-module-can-only-be-run-on-a-raspberry-pi/16255/9 "2019-10-04T11:48:49Z")

</div>

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:

```auto
[{"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:

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/b/b8fc1bd490adb88c1c31691902baa5c8ba4e29d6.png)

---

<div class="post-metadata">

### Author: ![afelix](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/afelix/32/9743_2.png) [@afelix](https://discourse.nodered.org/u/afelix)
#### Post date: [4 October 2019 11:57 UTC](https://discourse.nodered.org/t/runtimeerror-this-module-can-only-be-run-on-a-raspberry-pi/16255/10 "2019-10-04T11:57:35Z")

</div>

> [@GregorR1](#):
>
> I've installed node-red-node-pi-gpiod on my dev Pi, however I can't get it to control my GPIOs.

> [@](#):
>
> 4 Oct 10:15:07 - [error] [pi-gpiod out:1638628e.c6711d] Error: connect ECONNREFUSED 127.0.0.1:8888

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.

---

<div class="post-metadata">

### Author: ![GregorR1](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/gregorr1/32/12263_2.png) [@GregorR1](https://discourse.nodered.org/u/GregorR1)
#### Post date: [4 October 2019 12:07 UTC](https://discourse.nodered.org/t/runtimeerror-this-module-can-only-be-run-on-a-raspberry-pi/16255/11 "2019-10-04T12:07:04Z")

</div>

Hi I set up the daemon in the /etc/rc.local as shown [here](https://flows.nodered.org/node/node-red-node-pi-gpiod).

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

Thanks,  
Gregor

---

<div class="post-metadata">

### Author: ![afelix](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/afelix/32/9743_2.png) [@afelix](https://discourse.nodered.org/u/afelix)
#### Post date: [4 October 2019 13:22 UTC](https://discourse.nodered.org/t/runtimeerror-this-module-can-only-be-run-on-a-raspberry-pi/16255/12 "2019-10-04T13:22:27Z")

</div>

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.
