iw1
Posts: 47
Joined: Mon Oct 13, 2014 8:10 am

Access to pigpio daemon

Wed Nov 30, 2016 4:52 pm

Is this daemon only accessible to user pi?
A simple program controlling leds via a Pibrella board works fine for user pi but not for a new user. The error given was "...No connection to pigpiod daemon is missing ...". Even when the new user was made a member of the same groups that pi belongs to, except groups pi and sudo, the error persists. I want the new user to have only limited access to administrative activities but not limited functionality in Scratch. Any suggestions what I need to change to achieve this. Thanks.

User avatar
joan
Posts: 14848
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: Access to pigpio daemon

Wed Nov 30, 2016 5:15 pm

As far as the pigpio daemon is concerned the user (and groups) are irrelevant.

You could check that by entering the command pigs pigpv at the command line when logged in as the user.

How are you accessing the daemon? Is it via scratch?

iw1
Posts: 47
Joined: Mon Oct 13, 2014 8:10 am

Re: Access to pigpio daemon

Wed Nov 30, 2016 6:28 pm

You could check that by entering the command pigs pigpv at the command line when logged in as the user.
This gives 'socket connection failure' error whether logged on as pi or as the new user.
How are you accessing the daemon? Is it via scratch?
Yes. As but stated above, user pi has no problem in Scratch, the new user does, so strange that both users get the error with the pigs pigspv command.
The addition of the new user was done after upgrading to the new distribution.
I'll remake an sd card with the previous version of Raspian and see whether that recent upgrade is relevant or whether it's related to how Scratch accesses the daemon.
[Edit] I thought before changing back I'd try starting sudo pigpiod command with the current setup.
This then gives a socket number (with pigs pigpv) when logged on either as pi or as the new user.
However, subsequently trying to run my Scratch program works ok when logged as pi but, when logged as the new user, running the program produces a fatal (Smalltalk?) Error:primCreateDirectory: failed.

So, two things here:
1. Is the daemon usually first started when Scratch is run (or when when the pi boots)?
2. Why is Scratch crashing under the circumstances described. (One for Tim Rowledge, I think.)
Last edited by iw1 on Wed Nov 30, 2016 6:56 pm, edited 1 time in total.

User avatar
joan
Posts: 14848
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: Access to pigpio daemon

Wed Nov 30, 2016 6:39 pm

The socket error suggests the daemon isn't running.

Does the command sudo pigpiod as the new user work?

If it does try the pigs command again.

If it doesn't the problem may be that the user needs to have sudo permissions to start the daemon. That might also explain the scratch failure, as scratch will try to start the daemon and presumably will also fail if the user doesn't have sudo permissions.

iw1
Posts: 47
Joined: Mon Oct 13, 2014 8:10 am

Re: Access to pigpio daemon

Wed Nov 30, 2016 6:57 pm

Sorry your post arrived while I was doing my edit - see above.

User avatar
joan
Posts: 14848
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: Access to pigpio daemon

Wed Nov 30, 2016 7:12 pm

I don't use Scratch and would only be guessing the answers to 1) and 2). This does sound like a question for Tim.

iw1
Posts: 47
Joined: Mon Oct 13, 2014 8:10 am

Re: Access to pigpio daemon

Wed Nov 30, 2016 7:19 pm

Thanks for your help in pinning down the problem.
If it doesn't the problem may be that the user needs to have sudo permissions to start the daemon. That might also explain the scratch failure, as scratch will try to start the daemon and presumably will also fail if the user doesn't have sudo permissions.
By way of experiment I've added the new user to group 'pi' and group 'sudo'. When logged on as the new user, even with this new status, running Scratch does not start the pigpiod daemon and the Scratch error described in the first post is obtained. Then, if the daemon is run by 'sudo pigpiod' in a terminal window prior to running Scratch, running my Scratch program still generates a crash and the Smalltalk error.
It would seem that, at present, the user has to be 'pi' for pigpio to work in Scratch. As you say, a Scratch problem rather than a pigpio problem.

User avatar
joan
Posts: 14848
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: Access to pigpio daemon

Wed Nov 30, 2016 8:03 pm

iw1 wrote: ...
As you say, a Scratch problem rather than a pigpio problem.
I wouldn't go that far. You never know what errors might be triggered by an unexpected pattern of usage.

timrowledge
Posts: 1342
Joined: Mon Oct 29, 2012 8:12 pm
Location: Vancouver Island
Contact: Website

Re: Access to pigpio daemon

Fri Dec 02, 2016 7:26 pm

Well this is quite puzzling. I've never bothered to mess with users and groups so I can't offer any experience.
Scratch is started via a shell script (/usr/bin/scratch) which does all sorts of stuff including firing up pigpio (and in fact I recently discovered a bug in the line that is supposed to see if it was already running) before actually starting Squeak with the Scratch image and other parameters.
It seems to me that your new user account doesn't have all the permissions set properly and thus can't do the pigpio startup from the script. I have no idea how to do anything about that... Maybe make a script with only the pigpio startup line and see if that works? It might reveal something.

If the pigpio is not running, then the worst that should happen is Scratch whining at you if/when you try to start the gpio server and you just close the dialogue.

Now the primCreateDirectory failure is an indicator of some permissions error as well. I suspect that the system is trying to write an error log file and your new user doesn't have permissions to write to the relevant directory. Not sure which one that is and can't check right now since I'm away from the lab.

Who is a unix permissions expert? I think that's what we need here.
Making Smalltalk on ARM since 1986; making your Scratch better since 2012

User avatar
joan
Posts: 14848
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: Access to pigpio daemon

Fri Dec 02, 2016 8:27 pm

Assume it is a permissions problem.

Could you login as the new user and enter the following command

groups

Code: Select all

$ groups
pi adm dialout cdrom sudo audio video plugdev games users input netdev gpio i2c spi

iw1
Posts: 47
Joined: Mon Oct 13, 2014 8:10 am

Re: Access to pigpio daemon

Fri Dec 02, 2016 11:39 pm

Logged on as new user 'james' the output from groups is:
james adm dialout cdrom sudo audio video plugdev games users input netdev lpadmin gpio i2c spi pi

iw1
Posts: 47
Joined: Mon Oct 13, 2014 8:10 am

Re: Access to pigpio daemon

Sat Dec 03, 2016 12:45 am

I have repeated the whole process by creating another new user but this time have more carefully made the user a member of all the groups listed above before testing the Scratch program accessing the gpio pins.
groups gives:
robert adm dialout cdrom sudo audio video plugdev games users input netdev lpadmin gpio i2c spi pi

When logged on as this new user, just as before, Scratch doesn't start pigpiod and running the Scratch program trying to access the pins gives the error "...No connection to pigpiod daemon is missing ..." as first described above.
However this time, still logged on as the new user, if pigpiod is started in a terminal window with 'sudo pigpiod', subsequently running the Scratch program works without errors. I can't reproduce the fatal crash out of Scratch.

So this seems to be the question to be answered: why doesn't this user have permission to start pigpiod from within Scratch?
My eventual objective though is for the user not to belong to groups sudo and pi and the Scratch program still to work. Would starting the daemon when the computer boots rather than from within Scratch solve the problem?
Thanks for your help so far; let me know if there is anything else you would like me to try.

timrowledge
Posts: 1342
Joined: Mon Oct 29, 2012 8:12 pm
Location: Vancouver Island
Contact: Website

Re: Access to pigpio daemon

Sat Dec 03, 2016 1:16 am

iw1 wrote:When logged on as this new user, just as before, Scratch doesn't start pigpiod and running the Scratch program trying to access the pins gives the error "...No connection to pigpiod daemon is missing ..." as first described above.
However this time, still logged on as the new user, if pigpiod is started in a terminal window with 'sudo pigpiod', subsequently running the Scratch program works without errors. I can't reproduce the fatal crash out of Scratch.
Strictly speaking isn't Scratch that tries to start the daemon, but the surrounding shell script.

You might try

Code: Select all

sudo nano /usr/bin/scratch
and comment out the lines that run the actual squeak system and the ones that attempt to stop pigpiod after that exits. That's the last four lines, not counting a couple of blanks. Just stick # at the beginning.

Then (from a terminal of course) try
logging in as your new user
run the /usr/bin/scratch script
check if pigpiod is running

...and obviously any error messages would be interesting.

I suppose we should ask for the results of
ls /usr/bin/scra*
from both pi and your new user's logins. Just because for all I know permissions look different from different users.

Aside from that, I'm baffled. This is why I prefer RISC OS...
Making Smalltalk on ARM since 1986; making your Scratch better since 2012

User avatar
joan
Posts: 14848
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: Access to pigpio daemon

Sun Dec 04, 2016 12:36 pm

I have just set up a new user.

I stopped the pigpio daemon (sudo killall pigpiod) and then launched nuscratch (scratch).

Scratch launched and started the pigpio daemon.

I had to add the user to /etc/sudoers.

I assume you have done that because I got a sudo error message if I didn't.

iw1
Posts: 47
Joined: Mon Oct 13, 2014 8:10 am

Re: Access to pigpio daemon

Tue Dec 06, 2016 11:56 pm

Running Scratch from a terminal window requested a [sudo] password for the user; when this was provided my program worked as it should. Starting Scratch from the gui didn't request a sudo password and my program failed as described earlier. When the NOPASSWD option for the user was added to /etc/sudoers my Scratch program then worked from the desktop. Simply adding the user to group sudo (the way I had done it, with adduser) hadn't set the no-password option.
As far as the pigpio daemon is concerned the user (and groups) are irrelevant.
But it would seem from the things I have tried that pigpiod can only be used (started?) by members of group sudo; not what I was hoping for. Is there a reason why non-sudoers are excluded? Is there a way round this? If not it's probably best for me to stick to user pi.

User avatar
joan
Posts: 14848
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: Access to pigpio daemon

Wed Dec 07, 2016 4:33 am

Root privileges are needed to launch the daemon. There is no way around that.

The following one-off command will launch the daemon at boot thus getting around the problem of a non-root user trying to launch the daemon.

sudo systemctl enable pigpiod

iw1
Posts: 47
Joined: Mon Oct 13, 2014 8:10 am

Re: Access to pigpio daemon

Wed Dec 07, 2016 8:54 am

Thanks again for the help. I'll give that a try when I get chance. I've noticed that there are some lines in the /usr/bin/scratch file that relate to starting and conditionally stopping pigpiod as sudo so I suspect I won't get things right first time. More learning to do, but that's what this is all about. Again thanks.

User avatar
joan
Posts: 14848
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: Access to pigpio daemon

Wed Dec 07, 2016 9:04 am

iw1 wrote:Thanks again for the help. I'll give that a try when I get chance. I've noticed that there are some lines in the /usr/bin/scratch file that relate to starting and conditionally stopping pigpiod as sudo so I suspect I won't get things right first time. More learning to do, but that's what this is all about. Again thanks.
You shouldn't touch Scratch's configuration.

My understanding is that Scratch only starts/stops the daemon if it isn't already running.

iw1
Posts: 47
Joined: Mon Oct 13, 2014 8:10 am

Re: Access to pigpio daemon

Wed Dec 07, 2016 4:23 pm

Success!
...launch the daemon at boot...
That's all that was needed.
Thanks again.

Return to “Scratch”