]> vault307.fbx.one Git - garage_door_sensor.git/blob - garageCheck.py
garageCheck runs on device to turn on/off LEDs (Myserver)
[garage_door_sensor.git] / garageCheck.py
1 #!/usr/bin/python3
2 import RPi.GPIO as GPIO
3 import requests, time
4 from bs4 import BeautifulSoup
5
6 global soup
7 soup=''
8 #yellow=37
9 #green=36
10
11 GPIO.setmode(GPIO.BOARD)
12 GPIO.setup(37,GPIO.OUT)
13 GPIO.setup(36,GPIO.OUT)
14
15 #garage=requests.get('http://garage.local')
16
17 def readData():
18 global soup
19 garage=requests.get('http://garage.local')
20 soup=BeautifulSoup((garage.text),features='html.parser')
21 return soup
22
23 def check():
24 global soup
25 dstate=soup.find(id='dstate')
26 lstate=soup.find(id='lstate')
27 try:
28 if dstate.text=='CLOSED':
29 GPIO.output(36,False)
30 if dstate.text=='OPEN':
31 GPIO.output(36,True)
32 if lstate.text=='OFF':
33 GPIO.output(37,False)
34 if lstate.text=='ON':
35 GPIO.output(37,True)
36 except AttributeError:
37 print('oops')
38 pass
39
40 while True:
41 readData()
42 check()
43 time.sleep(1)