Using GPIO add_event_detect() in non-priviledged mode

Hi - has anyone been able to use the RPi.GPIO edge detect when not running in privileged mode?

I was able to use the GPIO fine with the following settings:

    devices:
      - "/dev/gpiomem:/dev/gpiomem"
    cap_add:
      - SYS_RAWIO

Trying to use the above with GPIO.add_event_detect fails with RuntimeError: Failed to add edge detection.

I’ve had to go to privileged mode for this to work.

hey @mhazley,
According to the source code for RPi.GPIO, adding edge detection would start a thread. You can look here

The error seems related to permissions and I believe you need to add more capabilities to the docker-compose file. Perhaps this this will help.

Let us know if it works for you,
Cheers :slight_smile:

1 Like

Thanks for the links, checked out the source and seems it fails either calling:

epoll_create
epoll_ctl
or
pthread_create

Coming up a bit blank with the capabilities required… pthread_create says:

The new thread inherits copies of the calling thread’s capability sets

So perhaps theres a capability for creating threads… I will keep reading, thanks for the sign-posts!

@mhazley,
Perhaps you could also try adding
/dev/mem:/dev/mem to devices ?

Thanks - same error.

I will release as privileged for now and then work to optimise. I’ll report back here when I work it out!

Thanks. Very grateful if you could do that. Would be helpful for other community members too.

Cheers!

As a side note,
When working with interface and running in unprivileged containers , the io.balena.features.sysfs can be a good option. It is available as from supervisor v10.8.0.

Thanks, I’ll try that, I am running 10.6.27 currently so will upgrade and try.