Last active
March 31, 2018 17:24
-
-
Save nicolaiarocci/fd2b273d3a5612e6fdda4a54fc5c20bb to your computer and use it in GitHub Desktop.
Revisions
-
nicolaiarocci revised this gist
Mar 31, 2018 . 1 changed file with 34 additions and 4 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -2,12 +2,42 @@ app = Flask(__name__) def parse_request(): commands = {0:'L', 1:'H', 2:'U', 3:'K', 4:'W'} cmd = commands.get(request.args.get("cmd", type=int)) pin = request.args.get("pin") if pin: if len(pin) == 3 and pin[0] == 'P': pin = pin[1:3] challenge = int(pin) if challenge < 2 or challenge > 25: pin = '' else: pin = '' return pin, cmd def get_message(): message = '/' pin, cmd = parse_request() if pin and cmd: message = '/*CMD%s%s' % (pin, cmd) return message def send_message(msg): # qui metti il codice che spedisce alla porta seriale (te lo fai tu) pass @app.route("/") def main(): msg = get_message() send_message(msg) return "messaggio spedito alla seriale: %s" % msg if __name__ == "__main__": #app.run(host='0.0.0.0', debug = True) app.run(debug=True) # usa questo per provare su localhost:5000 -
nicolaiarocci created this gist
Mar 31, 2018 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,13 @@ from flask import Flask, request app = Flask(__name__) @app.route("/") def main(): pin = request.args.get("pin") cmd = request.args.get("cmd") return "pin: %(pin)s, cmd: %(cmd)s" % locals() if __name__ == "__main__": #app.run(host='0.0.0.0', debug=True) # usa questo per rendere server accessibile da fuori app.run(debug=True) # usa questo per provare su localhost:5000