foodoor ist oben!
This commit is contained in:
@ -1,10 +1,10 @@
|
||||
#! /usr/bin/python
|
||||
#!/usr/bin/env python2
|
||||
|
||||
import os
|
||||
import stat
|
||||
import time
|
||||
import pifacedigitalio
|
||||
import requests
|
||||
import urllib2
|
||||
import signal
|
||||
import sys
|
||||
import grp
|
||||
@ -14,9 +14,9 @@ from ConfigParser import SafeConfigParser
|
||||
parser = SafeConfigParser()
|
||||
parser.read('/etc/foodoord.conf')
|
||||
|
||||
doorapi = parser.get('doorstatus', 'status_url')
|
||||
consumerkey = parser.get('doorstatus', 'key')
|
||||
consumersecret = parser.get('doorstatus', 'secret')
|
||||
url = parser.get('door_firstlevel', 'status_url')
|
||||
old_api = parser.get('door_firstlevel_old', 'status_url')
|
||||
|
||||
|
||||
#Definitions for output
|
||||
LED_RED=6
|
||||
@ -40,15 +40,18 @@ if __name__ == "__main__":
|
||||
def doorbell(event):
|
||||
if (STATUS):
|
||||
pifacedigital.relays[RELAYS_UNLOCK].toggle()
|
||||
time.sleep(1.5)
|
||||
time.sleep(2)
|
||||
pifacedigital.relays[RELAYS_UNLOCK].toggle()
|
||||
#print 'got doorbell'
|
||||
|
||||
def close_button(event):
|
||||
global STATUS
|
||||
STATUS = False
|
||||
write_state("closed")
|
||||
|
||||
update_api(True)
|
||||
try:
|
||||
urllib2.urlopen(url+'&door=aerie&locked=1', timeout=2)
|
||||
urllib2.urlopen(old_api+'&status=closed', timeout=2)
|
||||
except:
|
||||
pass
|
||||
|
||||
set_led(RED)
|
||||
|
||||
@ -62,8 +65,11 @@ if __name__ == "__main__":
|
||||
listener.deactivate()
|
||||
os.remove("/var/run/foodoord.pipe")
|
||||
|
||||
write_state("closed")
|
||||
update_api(True)
|
||||
try:
|
||||
urllib2.urlopen(url+'&door=aerie&locked=1', timeout=2)
|
||||
urllib2.urlopen(old_api+'&status=closed', timeout=2)
|
||||
except:
|
||||
pass
|
||||
|
||||
set_led(RED)
|
||||
sys.exit(0)
|
||||
@ -83,28 +89,6 @@ if __name__ == "__main__":
|
||||
|
||||
pifacedigital = pifacedigitalio.PiFaceDigital()
|
||||
signal.signal(signal.SIGTERM, signal_handler)
|
||||
signal.signal(signal.SIGINT, signal_handler)
|
||||
|
||||
def write_state(state):
|
||||
try:
|
||||
handle = open("/tmp/door_state", "w")
|
||||
handle.write(state)
|
||||
handle.close()
|
||||
except:
|
||||
pass
|
||||
|
||||
def update_api(locked):
|
||||
#if locked:
|
||||
#
|
||||
# try:
|
||||
# os.system("/usr/bin/mosquitto_pub -h mqtt.chaospott.de -t foobar/aerie/licht -m 'zentral-aus'")
|
||||
# except:
|
||||
# pass
|
||||
try:
|
||||
os.system("/usr/bin/curl -XPOST --header 'Content-Type: application/json' --data '{ \"consumer_key\": \"" + consumerkey + "\", \"consumer_secret\": \"" + consumersecret + "\", \"aerie\": " + str(locked).lower() + " }' '" + doorapi + "' ")
|
||||
except:
|
||||
pass
|
||||
|
||||
|
||||
#Startsettings
|
||||
STATUS = False
|
||||
@ -128,16 +112,10 @@ if __name__ == "__main__":
|
||||
time.sleep(1)
|
||||
pifacedigital.relays[RELAYS_LOCK].toggle()
|
||||
STATUS = False
|
||||
|
||||
write_state("closed")
|
||||
|
||||
update_api(True)
|
||||
|
||||
try:
|
||||
r = requests.get(url+'&door=aerie&locked=1', timeout=2)
|
||||
#print (r.status_code)
|
||||
r = requests.get(old_api+'&status=closed', timeout=2)
|
||||
#print (r.status_code)
|
||||
urllib2.urlopen(url+'&door=aerie&locked=1', timeout=2)
|
||||
urllib2.urlopen(old_api+'&status=closed', timeout=2)
|
||||
except:
|
||||
pass
|
||||
|
||||
@ -145,23 +123,18 @@ if __name__ == "__main__":
|
||||
|
||||
elif (Pipe == "open"):
|
||||
pifacedigital.relays[RELAYS_UNLOCK].toggle()
|
||||
time.sleep(1.5)
|
||||
time.sleep(2)
|
||||
pifacedigital.relays[RELAYS_UNLOCK].toggle()
|
||||
|
||||
if (STATUS==False):
|
||||
|
||||
try:
|
||||
r = requests.get(url+"&door=aerie&locked=0", timeout=2)
|
||||
#print (r.status_code)
|
||||
r = requests.get(old_api+'&status=open', timeout=2)
|
||||
#print (r.status_code)
|
||||
urllib2.urlopen(url+'&door=aerie&locked=0', timeout=2)
|
||||
urllib2.urlopen(old_api+'&status=open', timeout=2)
|
||||
except:
|
||||
pass
|
||||
update_api(False)
|
||||
write_state("open")
|
||||
|
||||
STATUS = True
|
||||
|
||||
set_led(GREEN)
|
||||
time.sleep(0.1)
|
||||
|
||||
|
Reference in New Issue
Block a user