je le lance le script et quand je passe devant le capteur pir j ai le message d erreur suivant
Code : Tout sélectionner
Waiting for PIR to settle ...
Ready
Mouvement !
Traceback (most recent call last):
File "./pir2.py", line 31, in <module>
test = urllib.urlopen("http://192.168.1.40:8080/json.htm?type=command¶m= switchlight&idx=10&switchcmd=On&level=0")
File "/usr/lib/python2.7/urllib.py", line 86, in urlopen
return opener.open(url)
File "/usr/lib/python2.7/urllib.py", line 207, in open
return getattr(self, name)(url)
File "/usr/lib/python2.7/urllib.py", line 358, in open_http
return self.http_error(url, fp, errcode, errmsg, headers)
File "/usr/lib/python2.7/urllib.py", line 371, in http_error
result = method(url, fp, errcode, errmsg, headers)
File "/usr/lib/python2.7/urllib.py", line 682, in http_error_401
errcode, errmsg, headers)
File "/usr/lib/python2.7/urllib.py", line 380, in http_error_default
raise IOError, ('http error', errcode, errmsg, headers)
IOError: ('http error', 401, 'Unauthorized', <httplib.HTTPMessage instance at 0x cc9c10>)
Code : Tout sélectionner
usr/bin/python
import RPi.GPIO as GPIO
import time
import urllib
GPIO.setmode(GPIO.BCM)
GPIO_PIR = 25
print "PIR Module Test (CTRL-C pour quitter)"
GPIO.setup(GPIO_PIR,GPIO.IN)
Current_State = 0
Previous_State = 0
try:
print "Waiting for PIR to settle ..."
while GPIO.input(GPIO_PIR)==1:
Current_State = 0
print " Ready"
while True :
Current_State = GPIO.input(GPIO_PIR)
if Current_State==1 and Previous_State==0:
print " Mouvement !"
test = urllib.urlopen("http://192.168.1.69:8080/json.htm?type=command¶m=switchlight&idx=10&switchcmd=On&level=0")
time.sleep(80)
Previous_State=1
elif Current_State==0 and Previous_State==1:
print " Ready"
Previous_State=0
time.sleep(0.01)
except KeyboardInterrupt:
print " Quit"
GPIO.cleanup()