bug fixes

master
Bryan 2021-03-15 00:30:01 -06:00
parent 3de5bbd826
commit 39cf8d3408
1 changed files with 12 additions and 4 deletions

View File

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