X-Git-Url: https://vault307.fbx.one/gitweb/garage_door_sensor.git/blobdiff_plain/b6ac3df69b9a88ebbb8507f595d756139864076a..2f834b0f175c10abb28ec7ebaa8612e85b004377:/garageStatus.py diff --git a/garageStatus.py b/garageStatus.py index 6fe6ac7..265a49f 100755 --- a/garageStatus.py +++ b/garageStatus.py @@ -1,21 +1,57 @@ #!/usr/bin/python3 -import serial, time +import serial,time +from bs4 import BeautifulSoup ser=serial.Serial('/dev/ttyACM0',9600,timeout=.5) - -l='' #lightsensor -g='' #garagedoor sensor +global d +global l +d='' +l='' +global dstate +global lstate +dstate='' +lstate='' def readLine(): - global l - global g - data=str(ser.readline()) - l=data[2] - g=data[4] - return l - return g + global d + global l + data=str(ser.readline()) + d=data[4] + l=data[2] + return d,l + +def check(): + global d + global l + global dstate + global lstate + with open('/var/www/html/index.html') as fp: + soup=BeautifulSoup((fp),features='html.parser') + dstate=soup.find(id='dstate') + lstate=soup.find(id='lstate') + fp.close() + if int(l)==0: + lstate.string='OFF' + if int(l)==1: + lstate.string='ON' + if int(d)==1: + dstate=soup.find(id='dstate') + dstate.string='OPEN' + with open('/var/www/html/index.html','w') as writer: + writer.write(str(soup)) + fp.close() + writer.close() + return dstate + elif int(d)==0: + dstate.string='CLOSED' + with open('/var/www/html/index.html','w') as writer: + writer.write(str(soup)) + fp.close() + writer.close() + return dstate while True: - readLine() - print(l,g) - time.sleep(1) + readLine() + check() + print(d,dstate) + time.sleep(.5)