This is the example of my docker compose file:
services:
server:
privileged: true
build:
context: .
dockerfile: server/Dockerfile
restart: always
tty: true
network_mode: host
This is the example of my docker compose file:
services:
server:
privileged: true
build:
context: .
dockerfile: server/Dockerfile
restart: always
tty: true
network_mode: host
I am still facing the issue in loading GPIO Pins. Any one here can help me?
Hi,
I think some information got lost on the way here, because reading through the thread it sounds like the solution is already known.
The reason you can not write to /sys/class/gpio/export
is because you are trying to do it during image creation time ( with RUN
). At this time the image is being put together but the underlying hardware / kernel is not available yet.
You need to run the command when the image is being started as a container on the actual hardware / kernel.
This means that the script can not be invoked in the a RUN
statement in the dockerfile but instead as part of CMD
.
So if the command resides in a script you will need a COPY
statement to copy the script to the image and then a CMD
statement to execute it together with the startup command of your container.
Regards
Thomas
Thanks for the response
Yes, I am doing exactly as you mentioned I am copying the script on my container using COPY
and after that, I am using CMD
command to run the script.
Hey @Sharvin26 we are trying to reproduce this in a project. What exact OS version are you running? It is a development variant, right?
Yes, it is development version.
Version: BalenaOS 2.29.2+rev3
Okay, thanks, we are checking this.
Hey, I tried it out, and seems to work fine for me to just run echo 60 > /sys/class/gpio/export
, using this project to test:
https://github.com/balena-io-playground/bbb-gpio-test
and that outputs:
22.05.19 20:03:00 (+0100) GPIO 60 already exported
22.05.19 20:03:02 (+0100) GPIO 60 direction: in
22.05.19 20:03:02 (+0100) Idling...
as it should.
One important note, though, that if that GPIO is already enabled, you will receive an “operation not permitted error”, which is correct. Thus you have to check if that GPIO already exists and if it does, no need to run that export.
I.e. if the GPIO port is already exported (checking in the user application’s shell, that already enabled GIPO 60:
root@6af260a:/usr/src/app# echo 60 > /sys/class/gpio/export
bash: echo: write error: Operation not permitted
So:
echo GPIONUMBER > /sys/class/gpio/export
Sorry for the late response. I tested this seems to work for me. Thanks for the solution.