Last active
March 31, 2018 17:24
-
-
Save nicolaiarocci/fd2b273d3a5612e6fdda4a54fc5c20bb to your computer and use it in GitHub Desktop.
questo server accetta una query tipo ?pin=P03&cmd=1 ed estrae i valori di pin e cmd che puoi testare per fare tutto quel che ti serve.
This file contains 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 characters
from flask import Flask, request | |
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment