From 39cf8d340800433e962596fdf0f0f8a3309a2d74 Mon Sep 17 00:00:00 2001 From: Bryan Date: Mon, 15 Mar 2021 00:30:01 -0600 Subject: [PATCH] bug fixes --- src/app.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/app.py b/src/app.py index db6c08e..67b5e2b 100644 --- a/src/app.py +++ b/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 "
Hello world
" + @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 "
Unlocked!
" + return "
" + str(delay) + " Unlocked!
" return "
Hello World
" if __name__ == '__main__': run( + app=app, host='localhost', port=8000)