]> vault307.fbx.one Git - garage_door_sensor.git/blob - garageStatus.py
garageCheck runs on device to turn on/off LEDs (Myserver)
[garage_door_sensor.git] / garageStatus.py
1 #!/usr/bin/python3
2 import serial,time
3 from bs4 import BeautifulSoup
4
5 ser=serial.Serial('/dev/ttyACM0',9600,timeout=.5)
6 global d
7 global l
8 d=''
9 l=''
10 global dstate
11 global lstate
12 dstate=''
13 lstate=''
14
15 def readLine():
16 global d
17 global l
18 data=str(ser.readline())
19 d=data[4]
20 l=data[2]
21 return d,l
22
23 def check():
24 global d
25 global l
26 global dstate
27 global lstate
28 with open('/var/www/html/index.html') as fp:
29 soup=BeautifulSoup((fp),features='html.parser')
30 dstate=soup.find(id='dstate')
31 lstate=soup.find(id='lstate')
32 # fp.close()
33 if int(l)==0:
34 lstate.string='OFF'
35 if int(l)==1:
36 lstate.string='ON'
37 if int(d)==1:
38 dstate=soup.find(id='dstate')
39 dstate.string='OPEN'
40 with open('/var/www/html/index.html','w') as writer:
41 writer.write(str(soup))
42 fp.close()
43 writer.close()
44 return dstate
45 elif int(d)==0:
46 dstate.string='CLOSED'
47 with open('/var/www/html/index.html','w') as writer:
48 writer.write(str(soup))
49 fp.close()
50 writer.close()
51 return dstate
52
53 while True:
54 readLine()
55 check()
56 # print(d,l,dstate,lstate) #debug
57 time.sleep(.5)