Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python
- import RPi.GPIO as GPIO
- import time
- import urllib
- import urllib2
- sensor = 17 # Biuro
- GPIO.setmode(GPIO.BCM)
- GPIO.setup(sensor, GPIO.IN, pull_up_down=GPIO.PUD_UP)
- previous_state = False
- current_state = False
- while True:
- time.sleep(0.1)
- previous_state = current_state
- current_state = GPIO.input(sensor)
- if current_state != previous_state:
- if current_state:
- httpresponse = urllib.urlopen ("http://192.168.0.10:8084/json.htm?type=command¶m=switchlight&idx=44&switchcmd=On")
- else:
- httpresponse = urllib.urlopen ("http://192.168.0.10:8084/json.htm?type=command¶m=switchlight&idx=44&switchcmd=Off")
- sensor1 = 18 # Kuchnia
- GPIO.setmode(GPIO.BCM)
- GPIO.setup(sensor1, GPIO.IN, pull_up_down=GPIO.PUD_UP)
- previous_state = False
- current_state = False
- while True:
- time.sleep(0.1)
- previous_state = current_state
- current_state = GPIO.input(sensor1)
- if current_state != previous_state:
- if current_state:
- httpresponse = urllib.urlopen ("http://192.168.0.10:8084/json.htm?type=command¶m=switchlight&idx=43&switchcmd=On")
- else:
- httpresponse = urllib.urlopen ("http://192.168.0.10:8084/json.htm?type=command¶m=switchlight&idx=43&switchcmd=Off")
- sensor2 = 22 # Salon balkon
- GPIO.setmode(GPIO.BCM)
- GPIO.setup(sensor2, GPIO.IN, pull_up_down=GPIO.PUD_UP)
- previous_state = False
- current_state = False
- while True:
- time.sleep(0.1)
- previous_state = current_state
- current_state = GPIO.input(sensor2)
- if current_state != previous_state:
- if current_state:
- httpresponse = urllib.urlopen ("http://192.168.0.10:8084/json.htm?type=command¶m=switchlight&idx=46&switchcmd=On")
- else:
- httpresponse = urllib.urlopen ("http://192.168.0.10:8084/json.htm?type=command¶m=switchlight&idx=46&switchcmd=Off")
- sensor3 = 23 # sypialnia
- GPIO.setmode(GPIO.BCM)
- GPIO.setup(sensor3, GPIO.IN, pull_up_down=GPIO.PUD_UP)
- previous_state = False
- current_state = False
- while True:
- time.sleep(0.1)
- previous_state = current_state
- current_state = GPIO.input(sensor3)
- if current_state != previous_state:
- if current_state:
- httpresponse = urllib.urlopen ("http://192.168.0.10:8084/json.htm?type=command¶m=switchlight&idx=41&switchcmd=On")
- else:
- httpresponse = urllib.urlopen ("http://192.168.0.10:8084/json.htm?type=command¶m=switchlight&idx=41&switchcmd=Off")
- sensor4 = 24 # pokoj kamili
- GPIO.setmode(GPIO.BCM)
- GPIO.setup(sensor4, GPIO.IN, pull_up_down=GPIO.PUD_UP)
- previous_state = False
- current_state = False
- while True:
- time.sleep(0.1)
- previous_state = current_state
- current_state = GPIO.input(sensor4)
- if current_state != previous_state:
- if current_state:
- httpresponse = urllib.urlopen ("http://192.168.0.10:8084/json.htm?type=command¶m=switchlight&idx=42&switchcmd=On")
- else:
- httpresponse = urllib.urlopen ("http://192.168.0.10:8084/json.htm?type=command¶m=switchlight&idx=42&switchcmd=Off")
- sensor5 = 27 # Salon okno
- GPIO.setmode(GPIO.BCM)
- GPIO.setup(sensor5, GPIO.IN, pull_up_down=GPIO.PUD_UP)
- previous_state = False
- current_state = False
- while True:
- time.sleep(0.1)
- previous_state = current_state
- current_state = GPIO.input(sensor5)
- if current_state != previous_state:
- if current_state:
- httpresponse = urllib.urlopen ("http://192.168.0.10:8084/json.htm?type=command¶m=switchlight&idx=45&switchcmd=On")
- else:
- httpresponse = urllib.urlopen ("http://192.168.0.10:8084/json.htm?type=command¶m=switchlight&idx=45&switchcmd=Off")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement