add delay functionality, cleanup

master
Bryan 2021-03-15 00:12:55 -06:00
parent d479829672
commit 3de5bbd826
1 changed files with 10 additions and 7 deletions

View File

@ -1,33 +1,36 @@
#!/usr/bin/python3
'''
A basic bottle app skeleton
HTTP API to trigger unlock through MQTT
'''
from time import sleep
from bottle import Bottle, get, request, run
import paho.mqtt.client as mqtt
mqttc = mqtt.Client(client_id="", clean_session=True, userdata=None, transport="tcp")
mqttc.username_pw_set("th", password="h82b7782")
mqttc.connect("localhost", port=1883)
mqttc.connect("172.16.1.70", port=1883)
mqttc.loop_start()
app = application = Bottle()
@get('/unlock')
@app.route('/unlock')
def unlock():
deviceID = request.query.get('deviceID')
apiKey = request.query.get('apiKey')
delay = request.query.get('delay')
if apiKey == "123":
if apiKey == "c5S8De2TTPkDhkXREzSP":
if delay > 0:
sleep(delay)
result = mqttc.publish("devices/main-door/unlock/unlock/set", "true")
result.wait_for_publish()
return "<div>Unlocked!</div>"
#?deviceID=${dID}&apiKey=${aK}&delay=${d}
return "<div>Hello World</div>"
if __name__ == '__main__':
run(
host='localhost',
port=8000)