Hilscher Forum
error when using GPIO from Python - Printable Version

+- Hilscher Forum (https://forum.hilscher.com)
+-- Forum: netPI - Ruggedized Raspberry Pi with Industrial Ethernet (https://forum.hilscher.com/Forum-netPI-Ruggedized-Raspberry-Pi-with-Industrial-Ethernet)
+--- Forum: Software (https://forum.hilscher.com/Forum-Software)
+--- Thread: error when using GPIO from Python (/Thread-error-when-using-GPIO-from-Python)



error when using GPIO from Python - dcatteeu - September-9th-2019

Hi,

I have a docker that runs a Python application which uses GPIOs (via the Python RPi.GPIO library).

This docker runs fine on the Raspberry Pi 3B, but not on the netPI. I get:
Code:
RuntimeError: No access to /dev/mem.  Try running as root!

Further information:
- I do start the docker container with the `--priviliged` option.
- I have not yet attached a DI DO extension the netPI. I assume the module is "just" extending the GPIOs to the outside.
- On the Raspberry Pi, I don't use portainer.
- I've upgraded the firmware of the netPI to the latest version on September 5.

Are there any differences between the netPI and Raspberry Pi concerning the GPIOs or am I doing something wrong?

Thanks,
david.


RE: error when using GPIO from Python - Armin@netPI - September-9th-2019

This is very easy to explain: netPI has a special Docker daemon software that does not map all "/dev/" devices automatically into a container even if you configured it to "--privileged" mode. This is because of security reasons. You have to add all devices manually in any case.

With netPI you have to map the device /dev/mem into the container when you start it. That's all.

Thx
Armin


RE: error when using GPIO from Python - dcatteeu - September-9th-2019

Thanks, Armin.

I tried that, but it gives another error: "Linux runtime spec devices: not allowing /dev/mem for security reasons".

I guess i am missing something or the linux in my container is also "too" secure.

Any ideas?

Thanks,
david.


RE: error when using GPIO from Python - Armin@netPI - September-9th-2019

Yes please follow the idea of the example container https://hub.docker.com/r/hilschernetpi/netpi-nodered.

For this container we mapped /dev/gpiomem.

This should work.


RE: error when using GPIO from Python - dcatteeu - September-10th-2019

It does. Thanks!