-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfinal_v1_script.py
More file actions
48 lines (39 loc) · 1.22 KB
/
final_v1_script.py
File metadata and controls
48 lines (39 loc) · 1.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import RPi.GPIO as GPIO
import time
import requests
URL = ""
def send_lab_updates():
r = requests.get(url=URL)
return r.json()
led_pin = 22
button_pin = 4
lab_open = False
GPIO.setmode(GPIO.BCM)
GPIO.setup(led_pin,GPIO.OUT)
GPIO.setup(button_pin,GPIO.IN,pull_up_down=GPIO.PUD_UP)
GPIO.output(led_pin,GPIO.LOW)
# previous_state = GPIO.input(button_pin)
lab_msg_sent = False
while True:
button_state = GPIO.input(button_pin)
if button_state == GPIO.HIGH and lab_msg_sent == False:
data = send_lab_updates()
print("pehle wala called")
# data = data_.json()
time.sleep(5)
if data["slackResponse"]["message"]["text"] == "Bro lab is open":
GPIO.output(led_pin,GPIO.HIGH)
lab_msg_sent = True
# print("led is on")
elif lab_msg_sent == True and button_state == GPIO.LOW:
data = send_lab_updates()
print("doosre wala called")
# data = data_.json()
time.sleep(5)
if data["slackResponse"]["message"]["text"] == "Bro lab is closed":
GPIO.output(led_pin,GPIO.LOW)
lab_msg_sent = False
# GPIO.output(led_pin,GPIO.LOW)
# print("led is off")
time.sleep(0.1)
GPIO.cleanup()