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")