Skip to content

Instantly share code, notes, and snippets.

@nicolaiarocci
Last active March 31, 2018 17:24
Show Gist options
  • Save nicolaiarocci/fd2b273d3a5612e6fdda4a54fc5c20bb to your computer and use it in GitHub Desktop.
Save nicolaiarocci/fd2b273d3a5612e6fdda4a54fc5c20bb to your computer and use it in GitHub Desktop.

Revisions

  1. nicolaiarocci revised this gist Mar 31, 2018. 1 changed file with 34 additions and 4 deletions.
    38 changes: 34 additions & 4 deletions stefano.py
    Original 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():
    pin = request.args.get("pin")
    cmd = request.args.get("cmd")
    return "pin: %(pin)s, cmd: %(cmd)s" % locals()
    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) # usa questo per rendere server accessibile da fuori
    #app.run(host='0.0.0.0', debug = True)
    app.run(debug=True) # usa questo per provare su localhost:5000
  2. nicolaiarocci created this gist Mar 31, 2018.
    13 changes: 13 additions & 0 deletions stefano.py
    Original 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