How to access gpio as non-root user

I am using gpio pin to control led. I have written shell script which monitor the network status of apalis imx8 and show it using led. I am using gpio from sysfs interface. to export and use the gpio i need to use it as root user. Is there any way I can use gpio as non-root user?

Computer on Module - Apalis iMX8
Carrier Board - Ixora Carrier Board
Computer on Module OS - Torizon
Development PC OS - Linux

If you use libgpiod instead of sysfs you don’t need root permissions to interact with GPIO. This is described in detail here: How to Use GPIO on TorizonCore

Best Regards,
Jeremias

@jeremias.tx
Actually i am working on script which use network manager. Using network manager in container is not easy task, so i am running script on torizon core itself. we can not use libgpiod on torizoncore. So is there any way i can access gpio as non root user or run bash script as root user without need to enter password at runtime?

Sorry for my ignorance, but I wonder why don’t you can using ligpiod in scripts? Are these libgpiod scripting friendly tools not available on torizoncore or do require special permissions?

# ls /usr/bin/gpio*
/usr/bin/gpiodetect  /usr/bin/gpioget     /usr/bin/gpiomon
/usr/bin/gpiofind    /usr/bin/gpioinfo    /usr/bin/gpioset

@bhagwat_99,

If you’re just using Network Manager to monitor the network status you can quite easily run it inside a container. All you need to do is the following:

  • In the docker run command add --network=host so that the container can see the host networking stack
  • In the docker run command add -v /var/run/dbus:/var/run/dbus. This will bindmount dbus into the container so Network Manager tools can work properly.
  • Install Network Manager tools inside the container with apt.

After that you should be able to use Network Manager at a basic level like so:

# This is from inside the container
$  nmcli c
NAME             UUID                                  TYPE      DEVICE
network0         958cc5e3-1bbf-3d64-beeb-020d4414e254  ethernet  ethernet0
br-d960f74aaa67  0e7830dd-352c-4530-857b-9e757819b891  bridge    br-d960f74aaa67
docker0          4b1c7c43-ddd2-4e53-bdcb-3f5a48ceee6a  bridge    docker0
network1         78c31df4-8c89-31a6-9aeb-d5603e230e4e  ethernet  --

@Edward,
With regards to libgpiod, on TorizonCore we do a bit of a different approach. Any extraneous tools/libraries/utilities required should be fetched with a container. That is to say the base TorizonCore system does not have these libgpiod toolings by default.

Best Regards,
Jeremias