From 5309dd1da12b3bb5101ffda6aa039913202e8e7e Mon Sep 17 00:00:00 2001 From: Pin Lin Date: Sun, 21 Apr 2019 15:06:49 +0800 Subject: [PATCH] Create web server --- app.py | 25 +++++++++++++++++++++++++ requirements.txt | 3 ++- unlocker.py | 4 ---- 3 files changed, 27 insertions(+), 5 deletions(-) create mode 100644 app.py diff --git a/app.py b/app.py new file mode 100644 index 0000000..218444e --- /dev/null +++ b/app.py @@ -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) diff --git a/requirements.txt b/requirements.txt index 0e98393..f877c76 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1 +1,2 @@ -CHIP-IO \ No newline at end of file +CHIP-IO +flask \ No newline at end of file diff --git a/unlocker.py b/unlocker.py index 4f776f8..016fbc2 100644 --- a/unlocker.py +++ b/unlocker.py @@ -14,7 +14,3 @@ def run(pin: str): print("[Door] Unlocked!") GPIO.cleanup(pin) - - -if __name__ == '__main__': - run("XIO-P7")