Libmraa, mraa-gpio needs sudo

I’m trying to port an existing application from RPI to the RockPI s.
This is a node.js application. It’s running fine on the rockPi except for the following:

I installed libmraa. So when i do:

sudo mraa-gpio get 16

I get : Pin 16 = 0
Or : Pin 16 = 1 when button is pressed.

So this is already something. However, I’ve been struggling to make this work without sudo.
The NPM package mraa is unusable since it’s not updated and requires a very old version of node.

So i should be able to change / poll GPIO’s in CLI without sudo, to use GPIO on the rockPi.

I use the default ubuntu image.

Could somebody help me with this?

I found a working solution at last!

First, create a group and add the user that needs access to the GPIOs to it (this is for the current user;
replace $USER with an explicit username if you want).

sudo groupadd gpio

sudo usermod -a -G gpio $USER

Now reboot

Second, add the following lines to /etc/rc.local (you will have to edit it as root, using sudo vi or whatever).
chown -R root:gpio /sys/class/gpio

chmod -R ug+rw /sys/class/gpio

Third, create a new udev rule in a file, say /etc/udev/rules.d/80-gpio-noroot.rules (you will have to edit it as root again):

# /etc/udev/rules.d/80-gpio-noroot.rules

 
# Corrects sys GPIO permissions on the Joule so non-root users in the gpio group can manipulate bits

 
# Change group to gpio

 
SUBSYSTEM=="gpio", PROGRAM="/bin/sh -c '/bin/chown -R root:gpio /sys/devices/platform/INT34D1:*/gpio'"

 
# Change user permissions to ensure user and group have read/write permissions

 
SUBSYSTEM=="gpio", PROGRAM="/bin/sh -c '/bin/chmod -R ug+rw /sys/devices/platform/INT34D1:*/gpio'"

Fourth, reboot or restart udev using
sudo udevadm trigger --subsystem-match=gpio

And finally test:
mraa-gpio get 16

The first call will not do anything but set up the GPIO, so the value will be -1, but following calls should work. And return a value between 0-1.