Pi4J Now Supports Non-Privileged Access (no more root/sudo)

494 views
Skip to first unread message

Robert Savage

unread,
Dec 14, 2015, 12:21:53 PM12/14/15
to Pi4J

NON-PRIVILEGED ACCESS

The Pi4J Project now supports non-privileged access to the basic GPIO input and output functions of the Raspberry Pi as well as serial (UART), I2C and SPI communication.  What this means is that launching your Java application with "sudo" or running as a user account with "root" permissions is no longer required!  

HOW DOES IT WORK?

The latest Raspbian images now includes kernel support for a user accessible mapped memory access to the GPIO hardware via the "/dev/gpiomem" interface.  The latest images also include the predefined UDEV rules configuration allowing read/write access to the GPIO interfaces for users accounts that are members of the "gpio" group.  The UDEV rules also permit SPIDEV access to users who are members of the "spi" group and I2C access to users who are members of the "i2c" group.  Be default the "pi" user is a member of all three of these groups.

 ...


Please see the full article here:

http://www.savagehomeautomation.com/pi4j-nonprivileged

simon

unread,
Dec 28, 2015, 5:26:02 AM12/28/15
to Pi4J
Hey

so i'm working on a project witch is using sockets to Connect to a Client running on a port 444 with is not accesable with out root acces is this an issue that might be fixed and well as the gpio acces ?


also
i been working a bit with i2c and i wasent able to have device tree enabled wile using i2c this might just be a problem i hade for unkown reasons but you might wanna have a look at it 

Robert Savage

unread,
Dec 28, 2015, 12:41:07 PM12/28/15
to pi...@googlegroups.com
so i'm working on a project witch is using sockets to Connect to a Client running on a port 444 with is not accesable with out root acces is this an issue that might be fixed and well as the gpio acces ?

No, this change is only for GPIO access.  The newer kernel includes a gpiomem device that can provide access to the raw GPIO memory space.  The gpiomem device can be granted explicit permissions via the new device tree implementation.    
Linux-based systems restrict access to ports 1024 and below.   You way want to investigate "authbind", I know some applications use authbind to get around this protected ports issue.  https://en.wikipedia.org/wiki/Authbind 

The spidev and i2c devices can also be granted explicit permissions via the new device tree implementation.    

 
also
i been working a bit with i2c and i wasent able to have device tree enabled wile using i2c this might just be a problem i hade for unkown reasons but you might wanna have a look at it 

I can access I2C and SPI with device tree enabled.  Please note that there is a newer method to enable I2C and SPI in the boot config file.  Its easiest if you just use the raspi-config utility and enable I2C/SPI in the Advanced menu area. 


Thanks, Robert  
 

manfred....@gmail.com

unread,
Feb 5, 2016, 11:13:58 AM2/5/16
to Pi4J
That's great news. In your article on savagehomeautomation you're writing that this requires the latest Raspbian Jesse image. I'm running on Raspbian Wheezie with latest dist-upgrades and I do see /dev/gpiomem. So can I assume that the non-privileged gpio access will work on this, too? I don't see any gpiomem specific rule file under /etc/udev though.

Thanks for your great work!
Manfred

Robert Savage

unread,
Feb 5, 2016, 1:58:13 PM2/5/16
to Pi4J
Hi Manfred,

So technically I think you just need device tree support and the gpiomem device that is available in kernel version 4.1.7 or greater.  The older Wheezy distro may not include the udev rule for GPIO but you can easily add it.

Check out Gordon's blog post for details on the udev rule for GPIO:

Thanks, Robert

Robert Savage

unread,
Jul 27, 2016, 2:48:27 PM7/27/16
to Pi4J
This feature is now available in the latest v1.1 release of Pi4J.

Reply all
Reply to author
Forward
0 new messages