New statusapi implemented
This commit is contained in:
parent
f20e1158ed
commit
4f0f6b5f95
36
foodoord
36
foodoord
@ -15,6 +15,8 @@ parser = SafeConfigParser()
|
|||||||
parser.read('/etc/door.conf')
|
parser.read('/etc/door.conf')
|
||||||
|
|
||||||
url = parser.get('door_firstlevel', 'status_url')
|
url = parser.get('door_firstlevel', 'status_url')
|
||||||
|
old_api = parser.get('door_firstlevel_old', 'status_url')
|
||||||
|
|
||||||
|
|
||||||
#Definitions for output
|
#Definitions for output
|
||||||
LED_RED=6
|
LED_RED=6
|
||||||
@ -42,17 +44,34 @@ if __name__ == "__main__":
|
|||||||
pifacedigital.relays[RELAYS_UNLOCK].toggle()
|
pifacedigital.relays[RELAYS_UNLOCK].toggle()
|
||||||
#print 'got doorbell'
|
#print 'got doorbell'
|
||||||
|
|
||||||
|
def close_button(event):
|
||||||
|
global STATUS
|
||||||
|
STATUS = False
|
||||||
|
try:
|
||||||
|
urllib2.urlopen(url+'door=aerie&locked=1', timeout=2)
|
||||||
|
urllib2.urlopen(old_api+'&status=closed', timeout=2)
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
|
set_led(RED)
|
||||||
|
|
||||||
|
|
||||||
listener = pifacedigitalio.InputEventListener()
|
listener = pifacedigitalio.InputEventListener()
|
||||||
listener.register(0, pifacedigitalio.IODIR_RISING_EDGE, doorbell, settle_time=10)
|
listener.register(0, pifacedigitalio.IODIR_RISING_EDGE, doorbell, settle_time=10)
|
||||||
|
listener.register(1, pifacedigitalio.IODIR_RISING_EDGE, close_button, settle_time=5)
|
||||||
listener.activate()
|
listener.activate()
|
||||||
|
|
||||||
def signal_handler(signal, frame):
|
def signal_handler(signal, frame):
|
||||||
listener.deactivate()
|
listener.deactivate()
|
||||||
os.remove("/var/run/foodoord.pipe")
|
os.remove("/var/run/foodoord.pipe")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
urllib2.urlopen(url+'&status=closed', timeout=2)
|
urllib2.urlopen(url+'&door=aerie&locked=1', timeout=2)
|
||||||
|
urllib2.urlopen(old_api+'&status=closed', timeout=2)
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
set_led(RED)
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
|
||||||
def set_led(color):
|
def set_led(color):
|
||||||
@ -95,11 +114,8 @@ if __name__ == "__main__":
|
|||||||
STATUS = False
|
STATUS = False
|
||||||
|
|
||||||
try:
|
try:
|
||||||
urllib2.urlopen(url+'&status=closed', timeout=2)
|
urllib2.urlopen(url+'&door=aerie&locked=1', timeout=2)
|
||||||
except:
|
urllib2.urlopen(old_api+'&status=closed', timeout=2)
|
||||||
pass
|
|
||||||
try:
|
|
||||||
urllib2.urlopen("http://10.42.1.73/door/close", timeout=2)
|
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@ -113,12 +129,8 @@ if __name__ == "__main__":
|
|||||||
if (STATUS==False):
|
if (STATUS==False):
|
||||||
|
|
||||||
try:
|
try:
|
||||||
urllib2.urlopen(url+'&status=open', timeout=2)
|
urllib2.urlopen(url+'&door=aerie&locked=0', timeout=2)
|
||||||
except:
|
urllib2.urlopen(old_api+'&status=open', timeout=2)
|
||||||
pass
|
|
||||||
|
|
||||||
try:
|
|
||||||
urllib2.urlopen('http://10.42.1.73/door/open', timeout=2)
|
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user