bug fixes
parent
3de5bbd826
commit
39cf8d3408
16
src/app.py
16
src/app.py
|
|
@ -2,7 +2,7 @@
|
|||
HTTP API to trigger unlock through MQTT
|
||||
'''
|
||||
|
||||
from time import sleep
|
||||
import time
|
||||
from bottle import Bottle, get, request, run
|
||||
import paho.mqtt.client as mqtt
|
||||
|
||||
|
|
@ -15,6 +15,10 @@ mqttc.loop_start()
|
|||
|
||||
app = application = Bottle()
|
||||
|
||||
@app.route('/')
|
||||
def index():
|
||||
return "<div>Hello world</div>"
|
||||
|
||||
@app.route('/unlock')
|
||||
def unlock():
|
||||
deviceID = request.query.get('deviceID')
|
||||
|
|
@ -22,15 +26,19 @@ def unlock():
|
|||
delay = request.query.get('delay')
|
||||
|
||||
if apiKey == "c5S8De2TTPkDhkXREzSP":
|
||||
if delay > 0:
|
||||
sleep(delay)
|
||||
try:
|
||||
if int(delay) > 0:
|
||||
time.sleep(int(delay))
|
||||
except:
|
||||
pass
|
||||
result = mqttc.publish("devices/main-door/unlock/unlock/set", "true")
|
||||
result.wait_for_publish()
|
||||
return "<div>Unlocked!</div>"
|
||||
return "<div>" + str(delay) + " Unlocked!</div>"
|
||||
return "<div>Hello World</div>"
|
||||
|
||||
if __name__ == '__main__':
|
||||
run(
|
||||
app=app,
|
||||
host='localhost',
|
||||
port=8000)
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue