diff --git a/main.py b/main.py index 52fe49b..ed8e6f1 100644 --- a/main.py +++ b/main.py @@ -1,18 +1,28 @@ from flask import request, Flask, render_template +# Flask server boilerplate app = Flask(__name__) app.debug=True -app.config['SECRET_KEY'] = 'Thisisasecret!' +app.config['SECRET_KEY'] = 'Thisisasecret!' # Feel free to change this TODO: Make this change itself each boot +# Values used to track the train's throttle and direction. throttle: float = 0.0 direction: int = 0 @app.route('/') def index(): + """ + Renders the webpage if you view the IP address and port + """ return render_template('index.html') @app.route("/data", methods=["POST"]) -def data(): +def data() -> str: + """ + Used by the webpage to set the throttle and/or travel direction + + :return: Always returns "Success" (200) + """ global throttle, direction print(request.json) @@ -26,14 +36,17 @@ def data(): return "Success" @app.route("/control", methods=["GET"]) -def control(): - print(request.data) +def control() -> dict[str, str]: + """ + Used by the train controller to determine what the throttle and direction currently are + :return: A dictionary containing the throttle and direction values, will be jsonified + """ return { "throttle": throttle, "direction": direction } - if __name__=="__main__": - app.run(host="10.0.2.148", port=2093) \ No newline at end of file + # Listen on all interfaces on port 2093 + app.run(host="0.0.0.0", port=2093) \ No newline at end of file