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)