New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Need for root access to use SPI #4
Comments
|
Hello David, Sorry for the delay in replying to your post. Nice to hear that you're putting wpi to good use. One limitation with the current implementation of the wpi is, as you've discovered, that Erlang has to be run as root (listed in the Caveats section of the readme). The WiringPi library has multiple "setup" functions, wiringPiSetup() for root and wiringPiSetupSys() for non-root, but wpi only supports wiringPiSetup() at the moment. The way it works today is that as soon as the wpi module is loaded, the NIF is loaded and wiringPiSetup() (which requires root) is called by the NIF. Hence, you'll get the "Must be root to call wiringPiSetup" error message (which is printed to the console by WiringPi). Perhaps there's another solution, but the one I know is to add support for wiringPiSetupSys(). Then the user of wpi would have to choose which setup to call. Two solutions spring to mind:
I'll have to think about that. Do you have any other ideas? Thanks and Regards, |
|
On 06/06/13 22:40, Klas Johansson wrote:
I bore you with tedious erlang output now, 04:57:38.281 [info] Application lager started on node 'rcouch@raspis.mol.gas.bog' without SUDO 08:40:18.732 [info] Application lager started on node 'rcouch@raspis.mol.gas.bog' the GPIO works ok without root after exporting pins but SPI no good. Yes I did see the caveat, thank you for that! It would be presumptuous for me to have any Ideas in the face of your knowledge on the subject, I would be happy for either (any) of your solutions. Then you will be able to boast the perfect combination with Gordon's great work. keep up the good work, be glad to cooperate with you, yours sincerely David Martin David Martin |
This is a backwards-incompatible change while preparing for wiringPi version 2 support. This commit still supports wiringPi version 1. Previously the setup function - wiringPiSetup() - was called when the NIF was loaded. The downside with that approach was that wpi had to be run as root, although the nice thing was that a user wouldn't have to worry about calling setup before accessing pins. After some consideration I've (despite breaking backwards compatibility) decided to remove the setup from the NIF loading and let the user choose the method. Hopefully fixes issue #4.
|
Hi David, I've made some changes that will hopefully improve the situation for you. See commit d29a866. Gone is the implicit setup done by the load function in the NIF; instead you'll have to call one of the wpi:setup/0, wpi:setup_gpio/0 or (like in your case) wpi:setup_sys/0. I haven't tested any SPI devices, only blinking a led on a pin so far. Please let me know how it works. Kind Regards, |
|
On 19/06/13 22:37, Klas Johansson wrote:
David Martin |
|
Hi David, Just out of curiosity, have you had the chance to try this one out yet? Kind Regards, |
|
Not yet Klas, I am looking at cubieboard2 with 96 gpio in a variety of forms. On 04/08/13 22:29, Klas Johansson wrote:
David Martin |
|
Hi, Ok, no worries, just curious. There are many boards in the same segment as raspberry pi to play with. :-) Commit d29a866 supports WiringPi version 1 (but with exposed setup functions) and commit 33d0356 (the latest) supports WiringPi version 2. So depending on which one you choose you can try the new setup functions either on version 1 or version 2. Regards, |
|
Let me know if you need any further assistance in this area. Regards, |
I have incorporated this excellent library in an Erlang/OTP Virtual Machine on Pi.
The application, which is for educational purposes, provides a rebar generated environment that incorporates rcouch web accessible nosql database with wpi driven access to GPIO and SPI (and the others available in your wrapper).
All is working very well thanks to you and Gordon for contributing this excellent work.
My only problem is that in order to use the SPI interface I have to run the whole system as root!. I have no problem with the GPIO but as soon as I try to use SPI as normal user I get the following;-
Must be root to call wiringPiSetup().
(Did you forget sudo?)
The code fragment in question is;-
io:format("load spi driver and change user to pi (I hope!!!)i
pn",[os:cmd("gpio load spi")]),
This all works perfectly as root.
I am trying to get to the bottom of this as it is regarded as insecure having the web accessible database run as root. I realise that this is an issue with the wiringpi library itself but I thought I would query here before troubling Gordon with something perhaps regarded as off the main topic and confused by NIF's and wrappers etc.
yours sincerely David Martin
The text was updated successfully, but these errors were encountered: