Create web server

This commit is contained in:
2019-04-21 15:06:49 +08:00
parent 7ddc7e1c80
commit 5309dd1da1
3 changed files with 27 additions and 5 deletions

25
app.py Normal file
View File

@ -0,0 +1,25 @@
import os
from flask import Flask, request, abort
import unlocker
PORT = os.environ.get('PORT') or 5000
CODE = os.environ.get('CODE') or '8787'
UNLOCKER_PIN = os.environ.get('UNLOCKER_PIN') or 'XIO-P7'
app = Flask(__name__)
@app.route('/unlock')
def root():
code = request.args.get('code')
if (code == CODE):
unlocker.run(UNLOCKER_PIN)
return "OK"
else:
abort(404)
if __name__ == '__main__':
app.run(port=PORT)

View File

@ -1 +1,2 @@
CHIP-IO
flask

View File

@ -14,7 +14,3 @@ def run(pin: str):
print("[Door] Unlocked!")
GPIO.cleanup(pin)
if __name__ == '__main__':
run("XIO-P7")