Skip to content
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

/dev/pigpio access issue some time after script start #2

Open
coff opened this issue Nov 15, 2018 · 5 comments
Open

/dev/pigpio access issue some time after script start #2

coff opened this issue Nov 15, 2018 · 5 comments

Comments

@coff
Copy link

coff commented Nov 15, 2018

I use pigpio library for SPI communication via berry-spi but also for controlling some servos via /dev/pigpio from the same script.

At first when I run the script everything works flawlessly until some time (sometimes it's a couple hours sometimes couple minutes) when it can't control the servo anymore while SPI communication still works. Servo locks itself in some position and I can't move it by hand so it seems some signal to it is still being sent but it's kinda deaf for signals of different lengths.

sample command sent to servo for is:
echo "s 22 1500" > /dev/pigpio

where 22 is the pin number, 1500 is an example signal length

strangely /dev/pigout output is (when servo stil works):

0
-29
0
-29
0
...

when it stops:

0
0
0
0
0

Sample debug printout after terminating the script:

#####################################################
pigpio version=64 internals=200
micros=5 allocMode=0 dmaInitCbs=46 DMARestarts=45
samples 0 maxSamples 0 maxEmit 0 emitFrags 0
cbTicks 29640512, cbCalls 93403624
pipe: good 0, short 0, would block 0
alertTicks 93403268, lateTicks 0, moreToDo 310
      135         0         0         0        13        10        14        19        17        13        10        14         9        15         9         6        18        10        17        10        17        30     19600    343445  31464968 701212926  31703668    344713     19883        33        12        10        16        13        21         9         6        10        10        12        14        12        19        16        13        13        11         0         0        46 
#####################################################
$ php -v
PHP 7.0.30-0+deb9u1 (cli) (built: Jun 14 2018 13:50:25) ( NTS )

$ apt list php7.0-berry-spi
Listing... Done
php7.0-berry-spi/unknown,now 0.4.1 armhf [installed]

php-cpp version is 2.1.1

@coff
Copy link
Author

coff commented Nov 15, 2018

I just realized I had SPI interface disabled on my RPi though... SPI still worked all fine despite that.

@marius-meissner
Copy link
Contributor

First of all, thank you for using berry-spi :)

Your issue sounds "mysterious" and at this point I'm not sure, if the problem is in the extension, Pigpio itself or maybe a hardware problem.

Do you use the regular or the bitbanging interface?
Have you maybe considered using the php-pigpio in combination with the Pigpio daemon?
Would be interesting if the same problem occurs there as well.

@coff
Copy link
Author

coff commented Nov 17, 2018

Thank you for a quick response,

In the following days I'll try with php-pigpio as you suggested and I'll provide feedback then.
I'm using regular interface.

Let me know if you need any additional details on that.

Best,
Krzysztof

@coff
Copy link
Author

coff commented Nov 17, 2018

I'm not sure if that's related but when I launched it with php-pigpio I got these warnings:

PHP Warning:  socket_set_nonblock(): supplied resource is not a valid Socket resource in /home/pi/hellfirepi/vendor/volantus/php-pigpio/src/Network/Socket.php on line 72
PHP Warning:  socket_read(): supplied resource is not a valid Socket resource in /home/pi/hellfirepi/vendor/volantus/php-pigpio/src/Network/Socket.php on line 73
PHP Warning:  socket_set_block(): supplied resource is not a valid Socket resource in /home/pi/hellfirepi/vendor/volantus/php-pigpio/src/Network/Socket.php on line 74
PHP Warning:  socket_write(): supplied resource is not a valid Socket resource in /home/pi/hellfirepi/vendor/volantus/php-pigpio/src/Network/Socket.php on line 38
PHP Warning:  socket_set_option(): supplied resource is not a valid Socket resource in /home/pi/hellfirepi/vendor/volantus/php-pigpio/src/Network/Socket.php on line 50
PHP Warning:  socket_read(): supplied resource is not a valid Socket resource in /home/pi/hellfirepi/vendor/volantus/php-pigpio/src/Network/Socket.php on line 52
PHP Warning:  socket_set_nonblock(): supplied resource is not a valid Socket resource in /home/pi/hellfirepi/vendor/volantus/php-pigpio/src/Network/Socket.php on line 54
PHP Warning:  socket_read(): supplied resource is not a valid Socket resource in /home/pi/hellfirepi/vendor/volantus/php-pigpio/src/Network/Socket.php on line 55
PHP Warning:  socket_set_block(): supplied resource is not a valid Socket resource in /home/pi/hellfirepi/vendor/volantus/php-pigpio/src/Network/Socket.php on line 58

... and then after more in-depth analysis I realized that in certain point of my script execution I do pcntl_fork() to make some work within a child process which dies afterwards so then SpiDevice::__destruct() is called.

But then... I thought... isn't it an exact reason why it didn't work properly with berry-spi? I mean... since the script works as a kind of pigpiod daemon and listens on 8888 port then if we fork a child out of it then perhaps some kind of gross things happen to it.

Next thing I try is to run it without forking on berry-spi and we see if it changes anything.

Best,
Krzysztof

@marius-meissner
Copy link
Contributor

marius-meissner commented Nov 17, 2018

Thanks for mentioning the forking, this could be the right lead.

php-pigpio:
As you already analyzed correctly, the risky part is the socket resource.
But the only risk might be invalid socket requests/responses due to parallel usage, so except the descturct problem, forking should be quite save here (from hardware perspective point of view.)
Regarding the desctruct problem I opened the issue Volantus/php-pigpio#3.

berry-spi

if we fork a child out of it then perhaps some kind of gross things happen to it.

I'm exactly the same opinion.
This could lead to many potential reference problems. Pigpio allows only running one instance at a time, so I assume that counts for forks as well (but I found no statement so far about this topic).

Next thing I try is to run it without forking on berry-spi and we see if it changes anything.

I am looking forward to the results :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants