Advertisement
Martinnpl

kontaktron

Jan 23rd, 2020
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.62 KB | None | 0 0
  1. #!/usr/bin/python
  2.  
  3. import RPi.GPIO as GPIO
  4. import time
  5. import urllib
  6. import urllib2
  7.  
  8. sensor = 17 # Biuro
  9.  
  10. GPIO.setmode(GPIO.BCM)
  11. GPIO.setup(sensor, GPIO.IN, pull_up_down=GPIO.PUD_UP)
  12.  
  13. previous_state = False
  14. current_state = False
  15.  
  16. while True:
  17. time.sleep(0.1)
  18. previous_state = current_state
  19. current_state = GPIO.input(sensor)
  20. if current_state != previous_state:
  21. if current_state:
  22. httpresponse = urllib.urlopen ("http://192.168.0.10:8084/json.htm?type=command&param=switchlight&idx=44&switchcmd=On")
  23. else:
  24. httpresponse = urllib.urlopen ("http://192.168.0.10:8084/json.htm?type=command&param=switchlight&idx=44&switchcmd=Off")
  25.  
  26. sensor1 = 18 # Kuchnia
  27.  
  28. GPIO.setmode(GPIO.BCM)
  29. GPIO.setup(sensor1, GPIO.IN, pull_up_down=GPIO.PUD_UP)
  30.  
  31. previous_state = False
  32. current_state = False
  33.  
  34. while True:
  35. time.sleep(0.1)
  36. previous_state = current_state
  37. current_state = GPIO.input(sensor1)
  38. if current_state != previous_state:
  39. if current_state:
  40. httpresponse = urllib.urlopen ("http://192.168.0.10:8084/json.htm?type=command&param=switchlight&idx=43&switchcmd=On")
  41. else:
  42. httpresponse = urllib.urlopen ("http://192.168.0.10:8084/json.htm?type=command&param=switchlight&idx=43&switchcmd=Off")
  43.  
  44. sensor2 = 22 # Salon balkon
  45.  
  46. GPIO.setmode(GPIO.BCM)
  47. GPIO.setup(sensor2, GPIO.IN, pull_up_down=GPIO.PUD_UP)
  48.  
  49. previous_state = False
  50. current_state = False
  51.  
  52. while True:
  53. time.sleep(0.1)
  54. previous_state = current_state
  55. current_state = GPIO.input(sensor2)
  56. if current_state != previous_state:
  57. if current_state:
  58. httpresponse = urllib.urlopen ("http://192.168.0.10:8084/json.htm?type=command&param=switchlight&idx=46&switchcmd=On")
  59. else:
  60. httpresponse = urllib.urlopen ("http://192.168.0.10:8084/json.htm?type=command&param=switchlight&idx=46&switchcmd=Off")
  61.  
  62. sensor3 = 23 # sypialnia
  63.  
  64. GPIO.setmode(GPIO.BCM)
  65. GPIO.setup(sensor3, GPIO.IN, pull_up_down=GPIO.PUD_UP)
  66.  
  67. previous_state = False
  68. current_state = False
  69.  
  70. while True:
  71. time.sleep(0.1)
  72. previous_state = current_state
  73. current_state = GPIO.input(sensor3)
  74. if current_state != previous_state:
  75. if current_state:
  76. httpresponse = urllib.urlopen ("http://192.168.0.10:8084/json.htm?type=command&param=switchlight&idx=41&switchcmd=On")
  77. else:
  78. httpresponse = urllib.urlopen ("http://192.168.0.10:8084/json.htm?type=command&param=switchlight&idx=41&switchcmd=Off")
  79.  
  80. sensor4 = 24 # pokoj kamili
  81.  
  82. GPIO.setmode(GPIO.BCM)
  83. GPIO.setup(sensor4, GPIO.IN, pull_up_down=GPIO.PUD_UP)
  84.  
  85. previous_state = False
  86. current_state = False
  87.  
  88. while True:
  89. time.sleep(0.1)
  90. previous_state = current_state
  91. current_state = GPIO.input(sensor4)
  92. if current_state != previous_state:
  93. if current_state:
  94. httpresponse = urllib.urlopen ("http://192.168.0.10:8084/json.htm?type=command&param=switchlight&idx=42&switchcmd=On")
  95. else:
  96. httpresponse = urllib.urlopen ("http://192.168.0.10:8084/json.htm?type=command&param=switchlight&idx=42&switchcmd=Off")
  97.  
  98. sensor5 = 27 # Salon okno
  99.  
  100. GPIO.setmode(GPIO.BCM)
  101. GPIO.setup(sensor5, GPIO.IN, pull_up_down=GPIO.PUD_UP)
  102.  
  103. previous_state = False
  104. current_state = False
  105.  
  106. while True:
  107. time.sleep(0.1)
  108. previous_state = current_state
  109. current_state = GPIO.input(sensor5)
  110. if current_state != previous_state:
  111. if current_state:
  112. httpresponse = urllib.urlopen ("http://192.168.0.10:8084/json.htm?type=command&param=switchlight&idx=45&switchcmd=On")
  113. else:
  114. httpresponse = urllib.urlopen ("http://192.168.0.10:8084/json.htm?type=command&param=switchlight&idx=45&switchcmd=Off")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement