1 1
brian hewart

GPIO requires sudo

Recommended Posts

Rock64. Running mosquitto. Running my python script for home automation, measures temps, does a bit of control and uses an SIM900 for SMS outside access with no IP address issues. I've run this for ages with an Rpi doing mosquitto and an ESP8266 doing the SMS part. I tried using the RPi for everything but it can't keep up with the 19200b SIM900. The Rock64 does it beautifully.

 

So, all works beautifully but for pulsing the SIM900 to power it up. I have R64.GPIO which works only if I sudo into idle or python. Otherwise I get the dreaded "cannot export GPIO".

 

So close, so far. My eyes and the lcd are dim from searching for an answer.

 

Trying to add me to gpio results in no gpio found.

 

Surely there's a one line answer to this ?

Share this post


Link to post
Share on other sites
4 hours ago, brian hewart said:

I have R64.GPIO which works only if I sudo into idle or python.

 

4 hours ago, brian hewart said:

Surely there's a one line answer to this ?

Copy /usr/bin/python to /usr/bin/python-suid, then do "chown root:<same_group_as_user> /usr/bin/python-suid" and "chmod ug+s /usr/bin/python-suid" where <same_group_as_user> is the same group as the user you wish to grant gpios, and then run your python script using "python-suid".

Share this post


Link to post
Share on other sites

and just in case, but I guess Martin already solved your problem.

 

Within armbian you find following User-Supported options for GPIO and more:
ArmbianIO (sysFS) or
UserSpaceIO (libgpiod),
pyGPIO accesses 'pins' directly through /dev/mem


 ArmbianIO API - in C
https://forum.armbian.com/topic/5655-armbianio-api-proposal/

 

 User Space IO - is Python 3 and Java 8 bindings for user space GPIO, SPI, I2C, PWM and Serial interfaces
https://forum.armbian.com/topic/6523-user-space-io-is-python-3-and-java-8-bindings-for-user-space-gpio-spi-i2c-pwm-and-serial-interfaces/

 

 pyGPIO - A 'more general' python GPIO library based on pyA20
https://forum.armbian.com/topic/5662-pygpio-a-more-general-python-gpio-library/

 

Share this post


Link to post
Share on other sites
12 hours ago, martinayotte said:

 

Copy /usr/bin/python to /usr/bin/python-suid, then do "chown root:<same_group_as_user> /usr/bin/python-suid" and "chmod ug+s /usr/bin/python-suid" where <same_group_as_user> is the same group as the user you wish to grant gpios, and then run your python script using "python-suid".

 

Thanks for a quick reply Martin. You have replied to someone who has spent half a lifetime programming embedded systems since before MSDOS. Linux is new to me, I jumped to Mint when W10 got totally intolerable.  ( before MSDOS - that would be 6809 FLEX )

 

I have many pythons in bin/ I'm using idle-3.5 so do I copy from python python3.5 or python3.5m ?

 

where <same_group_as_user> is the same group as the user you wish to grant gpios:  user is me "brian" and there is a group "brian"

So - chown root:brian /usr/bin/python-suid    ??

 

Then I'd call "python3-suid MQTTsms2.py"   sort of thing.

 

Will this work in idle3 ?

 

Sorry for all the questions, it's working so well I don't want to screw it up at this stage. Rock64 is hard work, I've had so many failures.

Share this post


Link to post
Share on other sites
1 hour ago, Tido said:

and just in case, but I guess Martin already solved your problem.

 

 

 

Not quite for the moment but it's looking hopeful. It's very frustrating but I'm retired and this keeps my brain going. Everything has been developed on a Mint PC ( apart from this one control signal ). Move it to an RPi and it drops incoming serial chars. Move it to the Rock64 and it works like the PC then I hit this GPIO problem.

 

Do your libraries still hit the sudo GPIO problem ?

Share this post


Link to post
Share on other sites
23 minutes ago, brian hewart said:

It's very frustrating but I'm retired and this keeps my brain going.

much better than sudoku, isn't it?   Sorry, I know I read about other solutions, but while I keep the text above in a document for reference.. I have never done that for the sudo thingy. However, I searched with Google:  gpio sudo site:forum.armbian.com  and somewhere in here you find your solution.  You can see in the link the Thread-Topic  all sound promising

 

https://forum.armbian.com/topic/5737-web-python-gpio-access/

 

https://forum.armbian.com/topic/1886-gpio-access-from-user-space/

 

https://forum.armbian.com/topic/5776-opizero-and-gpio-rootless-access-from-python/

 

https://forum.armbian.com/topic/4052-problem-using-gpio-pins-on-legacy-kernel/

 

Please let me know, how you finally solve it.

Share this post


Link to post
Share on other sites
14 minutes ago, Tido said:

much better than sudoku, isn't it?  

 

Please let me know, how you finally solve it.

 

I must admit to enjoying freecell.

 

Everything is looking like a fudge. I've looked at all the links and all basically say "this does not work properly".

 

I returned a Tinker Board soon after they came out, I assumed that with the name ASUS on it that it might work, but no. The Rock64 tried the same job, screwed on the back of a TV for watching bike racing via Eurosport. That failed too, not reliable. A bog standard second hand Dell running Mint works faultlessly. Eurosport seems to lack enough servers for race day internet and the little boards ( inc RPi ) can't buffer it sufficiently.

 

I do have an LCD running on the i2c bus, as a last desperate move I could add an PCF8574 expander board and use that to pulse the start SIM900 signal. In fact this is probably the best idea, it's using a service that is properly implemented. Watch this space.

 

Just as a matter of interest, this is what is running perfectly right now:

mosquitto - brokering many ESP8266 boards

20x4 LCD on i2c - status display so monitor can be turned off.

SIM900 - send/receive text messages with no changing ip address problems

Android phones/tables works well with mosquitto.

Share this post


Link to post
Share on other sites
2 hours ago, brian hewart said:

So - chown root:brian /usr/bin/python-suid    ??

 

Then I'd call "python3-suid MQTTsms2.py"   sort of thing.

 

Will this work in idle3 ?

Yes for the chown and the python-suid call .

 

Idle3 ? I don't know, it is depending if you start it using "python-suid".

If not, if if is installed as a service for example, you need to figure out with "ps -ef" what user is running the service, and which python it is using.

Then, adapt the method I've described accordingly ...

 

BTW, the copying of python to python-suid is only cosmetic here to avoid having all python applications running as sudo, but it can be apply directly to /usr/bin/python3.5 for example without the copying.

Share this post


Link to post
Share on other sites

Thank you Martin.

 

Since my brainwave of using an expander board on the i2c that is working perfectly I'll give that a try and then it's all working in a manner I'm comfortable with.

Share this post


Link to post
Share on other sites

Humble apologies to Martin and Tido. I ask for advice and don't take it. There is a reason, age, if I patch things and it works, sure as hell in a few weeks when I want to make a change I'll have forgotten or lost the links to the changes.

 

I have wired in the PCF8574, it works with no changes to the system. Crazy, when all those pins are sticking out of the Rock64, defeatist maybe but it is working, I understand what is going on and I can tidy things up now.

 

If Armbian ever fixes the GPIO I would pull out the 8574 and go direct. It's tidier.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
1 1