Comments (16)
There are timing issues with starting and then stopping straight away. Of course I never do that in my own usage so I forget. As a work around a time.sleep(1) before the stop() works for me.
How are you running the code?
From a Linux machine I guess as Windows would give a different error message.
Are you running the code on a Pi or on a box on the same network as the Pi?
Are you typing the code into a Python interpreter or are you running a script?
from pigpio.
Direct access (ssh) and running on the Pi from the script as: sudo python test.py
.
from pigpio.
You don't need the sudo (you only need to use sudo to start the pigpiod daemon).
I can't reproduce the error you get. I get
soft ~ $ cat test.py
import pigpio
pigpio.start()
pigpio.stop()
soft ~ $ python test.py
Traceback (most recent call last):
File "test.py", line 5, in <module>
pigpio.stop()
File "/usr/local/lib/python2.7/dist-packages/pigpio.py", line 1583, in stop
_notify.stop()
File "/usr/local/lib/python2.7/dist-packages/pigpio.py", line 351, in stop
if self.go:
AttributeError: '_callback_thread' object has no attribute 'go'
soft ~ $ grep VERSION /usr/local/include/pigpio.h
#define PIGPIO_VERSION 9
soft ~ $
from pigpio.
I've added sleep(1), but, as I feared, it changed nothing.
As I said in the original comment, the error comes only AFTER the interrupt.
Just as then, I have now let program "run" for few minutes, but it obviously hangs as it exits (with this error) only when I press Ctrl+C:
$ python test.py
^CTraceback (most recent call last):
File "test.py", line 5, in <module>
pigpio.start()
File "/usr/local/lib/python2.7/dist-packages/pigpio.py", line 1547, in start
_notify = _callback_thread()
File "/usr/local/lib/python2.7/dist-packages/pigpio.py", line 346, in __init__
self.handle = _pigpio_command(self.sock, _PI_CMD_NOIB, 0, 0)
File "/usr/local/lib/python2.7/dist-packages/pigpio.py", line 316, in _pigpio_command
x, y, z, res = struct.unpack('IIII', sock.recv(16))
KeyboardInterrupt
Again the same --> the error is in start() which never finishes (normally).
The script:
import sys
import pigpio
from time import sleep
pigpio.start()
sleep(1)
pigpio.stop()
sys.exit(0)
from pigpio.
All I can think of is that you are using a version of pigpio prior to that which supports in band socket notifications.
Did you make/make install to install the latest pigpio and python module or did you just extract the tar and do a sudo python setup.py install yourself?
Do a grep for the pigpio version in /usr/local/include.
from pigpio.
I followd this:
wget abyz.co.uk/rpi/pigpio/pigpio.tar
tar xvf pigpio.tar
cd PIGPIO
make
make install
all passed OK.
This is the (grep for) version:
usr/local/include $ grep version pigpio.h
This version is for pigpio version 9
gpioHardwareRevision Get hardware version.
Returns the pigpio version number if OK, otherwise PI_INIT_FAILED.
/* Used to print a readable version of the current waveform to stdout.
from pigpio.
I have now cloned the GitHub source.
This is the result of run make; make install:
$ make; make install
gcc -O3 -Wall -c -o pigpio.o pigpio.c
gcc -O3 -Wall -c -o command.o command.c
ar rcs libpigpio.a pigpio.o command.o
ranlib libpigpio.a
size libpigpio.a
text data bss dec hex filename
65804 148 368328 434280 6a068 pigpio.o (ex libpigpio.a)
3316 548 0 3864 f18 command.o (ex libpigpio.a)
gcc -O3 -Wall -c -o checklib.o checklib.c
gcc -o checklib checklib.c -L. -lpigpio -lpthread -lrt
gcc -O3 -Wall -c -o demolib.o demolib.c
gcc -o demolib demolib.c -L. -lpigpio -lpthread -lrt
gcc -O3 -Wall -c -o pig2vcd.o pig2vcd.c
gcc -o pig2vcd pig2vcd.c
gcc -O3 -Wall -c -o pigpiod.o pigpiod.c
gcc -o pigpiod pigpiod.c -L. -lpigpio -lpthread -lrt
gcc -o pigs pigs.c command.c
sudo install -m 0755 -d /usr/local/include
sudo install -m 0644 pigpio.h /usr/local/include
sudo install -m 0755 -d /usr/local/lib
sudo install -m 0644 libpigpio.a /usr/local/lib
sudo install -m 0755 -d /usr/local/bin
sudo install -m 0755 pig2vcd /usr/local/bin
sudo install -m 0755 pigpiod /usr/local/bin
sudo install -m 0755 pigs /usr/local/bin
sudo python setup.py install
running install
running build
running build_py
creating build
creating build/lib.linux-armv6l-2.7
copying pigpio.py -> build/lib.linux-armv6l-2.7
running install_lib
copying build/lib.linux-armv6l-2.7/pigpio.py -> /usr/local/lib/python2.7/dist-packages
byte-compiling /usr/local/lib/python2.7/dist-packages/pigpio.py to pigpio.pyc
running install_egg_info
Removing /usr/local/lib/python2.7/dist-packages/pigpio-1.0.egg-info
Writing /usr/local/lib/python2.7/dist-packages/pigpio-1.0.egg-info
Version:
$ grep version pigpio.h
This version is for pigpio version 9
Same problem (after kbd interrupt):
$ python test.py
^CTraceback (most recent call last):
File "test.py", line 5, in <module>
pigpio.start()
File "/usr/local/lib/python2.7/dist-packages/pigpio.py", line 1547, in start
_notify = _callback_thread()
File "/usr/local/lib/python2.7/dist-packages/pigpio.py", line 346, in __init__
self.handle = _pigpio_command(self.sock, _PI_CMD_NOIB, 0, 0)
File "/usr/local/lib/python2.7/dist-packages/pigpio.py", line 316, in _pigpio_command
x, y, z, res = struct.unpack('IIII', sock.recv(16))
KeyboardInterrupt
from pigpio.
Did you sudo pigpiod after building?
from pigpio.
yes
from pigpio.
I'm stumped.
I think you need to give full details of your setup and versions.
I've used the module on Windows (Vista, Python 3.3), laptop (Linux 3.11-2-amd64, Python 3.3, Python 2.7.6), Pi 1 (Raspbian Linux 3.10.25, Python 2.7.3, Python 3.2.3) Pi 2 (Debian Linux 3.10.25, Python 2.7.3, Python 3.2.3).
#########################################################################
Troubleshooting.
Does pigs br1, pigs br2 return hex numbers (confirms pigpiod is running).
Do the pigpio pipes exist? There should be /dev/piopio, /dev/pigout, /dev/pigerr
Does cat /dev/pigerr & report any errors?
Leave cat /dev/pigerr & running in the background and switch on pigpio debugs by sending a signal to the daemon.
sudo killall -USR2 pigpiod
sudo killall -USR2 pigpiod
sudo killall -USR2 pigpiod
sudo killall -USR2 pigpiod
Each -USR2 increases the debug level, -USR1 decreases the debug level.
Then do python test.py
You should see.
soft ~ $ cat /dev/pigerr &
[1] 3983
soft ~ $ sudo killall -USR2 pigpiod
soft ~ $ sudo killall -USR2 pigpiod
soft ~ $ sudo killall -USR2 pigpiod
2014-01-05 15:09:38 sigHandler: Debug level 3
soft ~ $ sudo killall -USR2 pigpiod
2014-01-05 15:09:40 sigHandler: Debug level 4
soft ~ $ python test.py
Traceback (most recent call last):
File "test.py", line 5, in <module>
pigpio.stop()
File "/usr/local/lib/python2.7/dist-packages/pigpio.py", line 1583, in stop
_notify.stop()
File "/usr/local/lib/python2.7/dist-packages/pigpio.py", line 351, in stop
if self.go:
AttributeError: '_callback_thread' object has no attribute 'go'
soft ~ $
2014-01-05 15:09:53 gpioNotifyOpenInBand:
2014-01-05 15:09:53 gpioNotifyClose: handle=0
from pigpio.
Same.
cat /dev/pigerr &
[1] 20228
pi@raspi ~ $ sudo killall -USR2 pigpiod
pi@raspi ~ $ sudo killall -USR2 pigpiod
pi@raspi ~ $ sudo killall -USR2 pigpiod
2014-01-14 10:15:33 sigHandler: Debug level 3
pi@raspi ~ $ sudo killall -USR2 pigpiod
2014-01-14 10:15:35 sigHandler: Debug level 4
pi@raspi ~ $ cd python
pi@raspi ~/python $ python test.py
^CTraceback (most recent call last):
File "test.py", line 5, in <module>
pigpio.start()
File "/usr/local/lib/python2.7/dist-packages/pigpio.py", line 1547, in start
_notify = _callback_thread()
File "/usr/local/lib/python2.7/dist-packages/pigpio.py", line 346, in __init__
self.handle = _pigpio_command(self.sock, _PI_CMD_NOIB, 0, 0)
File "/usr/local/lib/python2.7/dist-packages/pigpio.py", line 316, in _pigpio_command
x, y, z, res = struct.unpack('IIII', sock.recv(16))
KeyboardInterrupt
When I run the python script, there is no pigerr output until I press Ctrl+C.
from pigpio.
The only thing I can think of is that port 8888 is being used by another process and you are talking to that rather than pigpiod. However in that case I would have expected sudo pigpiod to have thrown up an error about port in use.
I just used netstat --listen to find ports being listened to on my local machine. I chose one at random and specified that as PIGPIO_PORT and started Python.
I get similar but not identical results (straight away though).
hard ~ $ export PIGPIO_PORT=6010
hard ~ $ python
Python 2.7.3 (default, Jan 13 2013, 11:20:46)
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import pigpio
>>> pigpio.start()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/dist-packages/pigpio.py", line 1558, in start
_notify = _callback_thread()
File "/usr/local/lib/python2.7/dist-packages/pigpio.py", line 347, in __init__
self.handle = _pigpio_command(self.sock, _PI_CMD_NOIB, 0, 0)
File "/usr/local/lib/python2.7/dist-packages/pigpio.py", line 316, in _pigpio_command
x, y, z, res = struct.unpack('IIII', sock.recv(16))
struct.error: unpack requires a string argument of length 16
>>>
I suggest the following.
netstat --listen | grep 8888
sudo killall pigpiod
sudo rm /var/run/pigpio.pid
netstat --listen | grep 8888
sudo pigpiod
netstat --listen | grep 8888
hard ~ $ netstat --listen|grep 8888
tcp 0 0 *:8888 *:* LISTEN
hard ~ $ sudo killall pigpiod
hard ~ $ sudo killall pigpiod
pigpiod: no process found
hard ~ $ sudo rm /var/run/pigpio.pid
rm: cannot remove `/var/run/pigpio.pid': No such file or directory
hard ~ $ netstat --listen|grep 8888
hard ~ $ sudo pigpiod
hard ~ $ cat /dev/pigerr &
[1] 3742
hard ~ $ netstat --listen|grep 8888
tcp 0 0 *:8888 *:* LISTEN
hard ~ $ pigs r 4
0
I'm afraid this is beyond my experience and am at a bit of a loss as to know how to proceed.
Have you got a funny firewall setting?
Could you try running the Python from a different networked machine?
from pigpio.
pi@raspi ~/python $ export PIGPIO_PORT=6010
pi@raspi ~/python $ sudo pigpiod
pi@raspi ~/python $ python test.py
********************************************************
Can't connect to pigpio on localhost(6010)
Did you start the pigpio daemon?
(sudo pigpiod)
Did you specify the correct Pi host/port in the environment
variables PIGPIO_ADDR/PIGPIO_PORT?
(e.g. export PIGPIO_ADDR=soft, export PIGPIO_PORT=8888)
Did you specify the correct Pi host/port in the
pigpio.start() function
(e.g. pigpio.start('soft', 8888))
********************************************************
Traceback (most recent call last):
File "test.py", line 5, in <module>
pigpio.start()
File "/usr/local/lib/python2.7/dist-packages/pigpio.py", line 1546, in start
_control.connect((_host, _port))
File "/usr/lib/python2.7/socket.py", line 224, in meth
return getattr(self._sock,name)(*args)
socket.error: [Errno 111] Connection refused
pi@raspi ~/python $
The 8888 port was reserved by RPi-Monitor. Since I wasn't using it, I removed it and pigpio is now working (at least the test.py script doesn't hang and exits as expected, can't test more as I'm not at home now).
Strange how the export PIGPIO_PORT did not fix the problem...
from pigpio.
The export was deliberately to a bad port (a port used by a different service) to try to get the same problem as you were seeing.
What is RPi-Monitor? If a lot of people use it I might have to search for another port to use by default.
pigpio by default uses 8888 but may be started with another port. However anything that uses pigpio must also be started with that port.
If you are happy this issue is resolved I will close it.
from pigpio.
RPi-Monitor: http://bit.ly/1cipgEh
You can close the case. Thanks.
from pigpio.
You might like to note the "Unofficial" use of port 8888 on, say, here at Wikipedia . It is a good central place that people might look at! 😀
Looking at the code of PiMonitor though - it does use the same default port of 8888 see ./rpimonitor/daemon.conf so - given that neither project has the explicit LANA "ownership" of it - it suggests a few extra words in the feedback to users that there may be something else (and perhaps quote "RPi-Monitor" as a specific case) that may also be trying to use the same Port might be helpful.
from pigpio.
Related Issues (20)
- C pigpio timer inaccuracy on raspbery pi 4 with raspian
- Pigpio BB Serial Read CPU Resource vs. RPI version HOT 4
- Is there a way to flush an open gpioSerialRead buffer? HOT 9
- event_callback with 0 bytes
- Issue with pigpio Initialization on Raspberry Pi 5 Model B HOT 1
- Understanding pigpiod command implementation HOT 9
- Glitch filter active while doing bbSerialRead? HOT 3
- SPI Slave - BSCX not consistently working RPi4B HOT 6
- i2c_open() returns the same handle for two devices on the same bus HOT 37
- Scheduling repetitive SPI writes HOT 3
- Isr doesn't work on raspberry os 12.5 HOT 3
- Continuous Wave Program Concept HOT 6
- SPI6 mode 3 HOT 1
- Leave CS low HOT 1
- Pigpio stuck on activating HOT 4
- Adding new functions to the library HOT 2
- Missed packets using RaspberryPi and nRF24L01. HOT 8
- Python 3.11.2 is installed but still getting "Depends: python:any (>= 2.7~) but it is not installable" HOT 2
- gpioSetISRFunc error -123 HOT 1
- setup.py does not work with python 3.12
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pigpio.