From d4399fddbb4e0543b88a9c72c83562eae52768ef Mon Sep 17 00:00:00 2001 From: lucasbutzke Date: Tue, 1 Jul 2025 10:38:04 -0400 Subject: [PATCH 1/7] [RTOP-23] Simple Rest API with a few runtime commands --- webserver/restapi.py | 55 ++++++++++++++++++++++++++++++++++++++++++ webserver/webserver.py | 34 ++++++++++++++++++++++++++ 2 files changed, 89 insertions(+) create mode 100644 webserver/restapi.py diff --git a/webserver/restapi.py b/webserver/restapi.py new file mode 100644 index 0000000..3aa5985 --- /dev/null +++ b/webserver/restapi.py @@ -0,0 +1,55 @@ +# restblueprint.py +from flask import Blueprint, jsonify, request +from typing import Callable, Optional + +# Define the Blueprint +restapi_bp = Blueprint('restapi_blueprint', __name__) + +# Global variable to store the single callback for this blueprint +_handler_callback: Optional[Callable[[str, dict], dict]] = None + +def register_callback(callback: Callable[[str, dict], dict]): + """Registers the business logic callback function.""" + global _handler_callback + _handler_callback = callback + print("Callback registered successfully for rest_blueprint!") + +@restapi_bp.route("/", methods=["GET"]) +def restapi_start_plc(some_argument): + """ + Handles GET requests to /start_plc/. + Data is expected via query parameters. + """ + if _handler_callback is None: + return jsonify({"error": "No handler registered"}), 500 + + try: + # For GET requests, get data from query parameters + # Example: /start_plc/echo?key1=value1&key2=value2 + data = request.args.to_dict() # Converts query parameters to a dictionary + + result = _handler_callback(some_argument, data) + return jsonify(result), 200 + except Exception as e: + print(f"Error in restapi_start_plc: {e}") # Log the error + return jsonify({"error": str(e)}), 500 + +@restapi_bp.route("/", methods=["POST"]) +def restapi_start_plc_post(some_argument): + """ + Handles POST requests to /start_plc_post/. + Data is expected in the JSON body. + """ + if _handler_callback is None: + return jsonify({"error": "No handler registered"}), 500 + + try: + # For POST requests, get data from JSON body + # request.get_json(silent=True) avoids raising an error if no JSON + data = request.get_json(silent=True) or {} # Default to empty dict if no JSON + + result = _handler_callback(some_argument, data) + return jsonify(result), 200 + except Exception as e: + print(f"Error in restapi_start_plc_post: {e}") # Log the error + return jsonify({"error": str(e)}), 500 \ No newline at end of file diff --git a/webserver/webserver.py b/webserver/webserver.py index b3defec..9964bd9 100644 --- a/webserver/webserver.py +++ b/webserver/webserver.py @@ -17,6 +17,7 @@ import mimetypes import flask import flask_login +from restapi import restapi_bp, register_callback app = flask.Flask(__name__) app.secret_key = str(os.urandom(16)) @@ -25,6 +26,35 @@ login_manager.init_app(app) openplc_runtime = openplc.runtime() +def my_callback(argument: str, data: dict) -> dict: + """ + This is the central callback function that handles the logic + based on the 'argument' from the URL and 'data' from the request. + """ + print(f"[{__name__}] Received argument: {argument}, data: {data}") + + if argument == "start_plc": + openplc_runtime.start_runtime() + return {"status": "runtime started"} + + elif argument == "stop_plc": + openplc_runtime.stop_runtime() + return {"status": "runtime stop"} + + elif argument == "runtime_logs": + logs = openplc_runtime.logs() + return {"runtime_logs": logs} + + elif argument == "status": + # Example for GET request with query params + return {"current_status": "operational", "details": data} # 'data' will be query params here + + elif argument == "ping": + return {"status": "pong"} + else: + return {"error": "Unknown argument"} + + class User(flask_login.UserMixin): pass @@ -2494,6 +2524,10 @@ def main(): print("Starting the web interface...") if __name__ == '__main__': + # rest api register + app.register_blueprint(restapi_bp, url_prefix='/api') + register_callback(my_callback) + #Load information about current program on the openplc_runtime object file = open("active_program", "r") st_file = file.read() From 897c479c182cf74bedfb5ecd12389e3a8bf47cfb Mon Sep 17 00:00:00 2001 From: lucasbutzke Date: Wed, 2 Jul 2025 09:28:38 -0400 Subject: [PATCH 2/7] Fix .gitignore file --- .gitignore | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index e968fe6..33f669c 100644 --- a/.gitignore +++ b/.gitignore @@ -19,6 +19,22 @@ webserver/build obj/ utils/dnp3_src/CMakeFiles/ webserver/scripts/ethercat +utils/ + +# Build artifacts +install_log.txt +start_openplc.sh +webserver/core/*.c +webserver/core/*.cpp +webserver/core/*.h +webserver/core/*.o +webserver/core/VARIABLES.csv +webserver/core/glue_generator +webserver/core/openplc +webserver/iec2c +webserver/st_optimizer +utils/libmodbus_src/src/.libs/* +utils/libmodbus_src/tests/.libs/* # Runtime directories -.venv +.venv \ No newline at end of file From 908739464940f831c86b31822319218cbc95125c Mon Sep 17 00:00:00 2001 From: lucasbutzke Date: Wed, 2 Jul 2025 21:24:09 -0400 Subject: [PATCH 3/7] [RTOP-23] Created post callback --- webserver/restapi.py | 54 +++++++++++++++++++----------------------- webserver/webserver.py | 31 ++++++++++++++++++++---- 2 files changed, 51 insertions(+), 34 deletions(-) diff --git a/webserver/restapi.py b/webserver/restapi.py index 3aa5985..fa3d797 100644 --- a/webserver/restapi.py +++ b/webserver/restapi.py @@ -6,50 +6,46 @@ from typing import Callable, Optional restapi_bp = Blueprint('restapi_blueprint', __name__) # Global variable to store the single callback for this blueprint -_handler_callback: Optional[Callable[[str, dict], dict]] = None +_handler_callback_get: Optional[Callable[[str, dict], dict]] = None +_handler_callback_get: Optional[Callable[[str, dict], dict]] = None -def register_callback(callback: Callable[[str, dict], dict]): +def register_callback_get(callback: Callable[[str, dict], dict]): """Registers the business logic callback function.""" - global _handler_callback - _handler_callback = callback + global _handler_callback_get + _handler_callback_get = callback print("Callback registered successfully for rest_blueprint!") -@restapi_bp.route("/", methods=["GET"]) -def restapi_start_plc(some_argument): - """ - Handles GET requests to /start_plc/. - Data is expected via query parameters. - """ - if _handler_callback is None: +def register_callback_post(callback: Callable[[str, dict], dict]): + """Registers the business logic callback function.""" + global _handler_callback_post + _handler_callback_post = callback + print("Callback registered successfully for rest_blueprint!") + +@restapi_bp.route("/", methods=["GET"]) +def restapi_start_plc_get(command): + if _handler_callback_get is None: return jsonify({"error": "No handler registered"}), 500 try: - # For GET requests, get data from query parameters - # Example: /start_plc/echo?key1=value1&key2=value2 - data = request.args.to_dict() # Converts query parameters to a dictionary + data = request.args.to_dict() - result = _handler_callback(some_argument, data) + result = _handler_callback_get(command, data) return jsonify(result), 200 except Exception as e: - print(f"Error in restapi_start_plc: {e}") # Log the error + print(f"Error in restapi_start_plc: {e}") return jsonify({"error": str(e)}), 500 -@restapi_bp.route("/", methods=["POST"]) -def restapi_start_plc_post(some_argument): - """ - Handles POST requests to /start_plc_post/. - Data is expected in the JSON body. - """ - if _handler_callback is None: +@restapi_bp.route("/", methods=["POST"]) +def restapi_start_plc_post(command): + if _handler_callback_post is None: return jsonify({"error": "No handler registered"}), 500 try: - # For POST requests, get data from JSON body - # request.get_json(silent=True) avoids raising an error if no JSON - data = request.get_json(silent=True) or {} # Default to empty dict if no JSON + # TODO validate file and limit size + data = request.get_json(silent=True) or {} - result = _handler_callback(some_argument, data) + result = _handler_callback_post(command, data) return jsonify(result), 200 except Exception as e: - print(f"Error in restapi_start_plc_post: {e}") # Log the error - return jsonify({"error": str(e)}), 500 \ No newline at end of file + print(f"Error in restapi_start_plc_post: {e}") + return jsonify({"error": str(e)}), 500 diff --git a/webserver/webserver.py b/webserver/webserver.py index 9964bd9..65059e4 100644 --- a/webserver/webserver.py +++ b/webserver/webserver.py @@ -17,7 +17,7 @@ import mimetypes import flask import flask_login -from restapi import restapi_bp, register_callback +from restapi import restapi_bp, register_callback_get, register_callback_post app = flask.Flask(__name__) app.secret_key = str(os.urandom(16)) @@ -26,7 +26,7 @@ login_manager.init_app(app) openplc_runtime = openplc.runtime() -def my_callback(argument: str, data: dict) -> dict: +def restapi_callback_get(argument: str, data: dict) -> dict: """ This is the central callback function that handles the logic based on the 'argument' from the URL and 'data' from the request. @@ -45,15 +45,35 @@ def my_callback(argument: str, data: dict) -> dict: logs = openplc_runtime.logs() return {"runtime_logs": logs} + # TODO + elif argument == "compilation_status": + return {"compilation_logs": + openplc_runtime.compilation_status()} + + # TODO + elif argument == "compile": + if openplc_runtime.status == "Running" or openplc_runtime.status == "Compiling": + pass + elif argument == "status": - # Example for GET request with query params - return {"current_status": "operational", "details": data} # 'data' will be query params here + return {"current_status": "operational", + "details": data} elif argument == "ping": return {"status": "pong"} else: return {"error": "Unknown argument"} +# file upload POST handler +def restapi_callback_post(argument: str, data: dict) -> dict: + # TODO + if argument == "upload_file": + logs = openplc_runtime.logs() + return {"runtime_logs": logs} + + else: + return {"error": "Unknown argument"} + class User(flask_login.UserMixin): pass @@ -2526,7 +2546,8 @@ def main(): if __name__ == '__main__': # rest api register app.register_blueprint(restapi_bp, url_prefix='/api') - register_callback(my_callback) + register_callback_get(restapi_callback_get) + register_callback_post(restapi_callback_post) #Load information about current program on the openplc_runtime object file = open("active_program", "r") From efa2345fb372f0fd54b3958fd35d4cf8105c078f Mon Sep 17 00:00:00 2001 From: lucasbutzke Date: Thu, 3 Jul 2025 23:02:47 -0400 Subject: [PATCH 4/7] [RTOP-23] Fix POST callback --- webserver/restapi.py | 10 ++++---- webserver/webserver.py | 55 +++++++++++++++++++++++++++--------------- 2 files changed, 41 insertions(+), 24 deletions(-) diff --git a/webserver/restapi.py b/webserver/restapi.py index fa3d797..e4bd113 100644 --- a/webserver/restapi.py +++ b/webserver/restapi.py @@ -7,22 +7,22 @@ restapi_bp = Blueprint('restapi_blueprint', __name__) # Global variable to store the single callback for this blueprint _handler_callback_get: Optional[Callable[[str, dict], dict]] = None -_handler_callback_get: Optional[Callable[[str, dict], dict]] = None +_handler_callback_post: Optional[Callable[[str, dict], dict]] = None def register_callback_get(callback: Callable[[str, dict], dict]): """Registers the business logic callback function.""" global _handler_callback_get _handler_callback_get = callback - print("Callback registered successfully for rest_blueprint!") + print("GET Callback registered successfully for rest_blueprint!") def register_callback_post(callback: Callable[[str, dict], dict]): """Registers the business logic callback function.""" global _handler_callback_post _handler_callback_post = callback - print("Callback registered successfully for rest_blueprint!") + print("POST Callback registered successfully for rest_blueprint!") @restapi_bp.route("/", methods=["GET"]) -def restapi_start_plc_get(command): +def restapi_plc_get(command): if _handler_callback_get is None: return jsonify({"error": "No handler registered"}), 500 @@ -36,7 +36,7 @@ def restapi_start_plc_get(command): return jsonify({"error": str(e)}), 500 @restapi_bp.route("/", methods=["POST"]) -def restapi_start_plc_post(command): +def restapi_plc_post(command): if _handler_callback_post is None: return jsonify({"error": "No handler registered"}), 500 diff --git a/webserver/webserver.py b/webserver/webserver.py index 65059e4..5170bd0 100644 --- a/webserver/webserver.py +++ b/webserver/webserver.py @@ -14,6 +14,7 @@ import sys import ctypes import socket import mimetypes +import json import flask import flask_login @@ -31,33 +32,31 @@ def restapi_callback_get(argument: str, data: dict) -> dict: This is the central callback function that handles the logic based on the 'argument' from the URL and 'data' from the request. """ - print(f"[{__name__}] Received argument: {argument}, data: {data}") + # TODO logging debug level + print(f"GET | [{__name__}] Received argument: {argument}, data: {data}") - if argument == "start_plc": + if argument == "start-plc": openplc_runtime.start_runtime() return {"status": "runtime started"} - elif argument == "stop_plc": + elif argument == "stop-plc": openplc_runtime.stop_runtime() return {"status": "runtime stop"} - elif argument == "runtime_logs": + elif argument == "runtime-logs": logs = openplc_runtime.logs() - return {"runtime_logs": logs} + return {"runtime-logs": logs} - # TODO - elif argument == "compilation_status": - return {"compilation_logs": - openplc_runtime.compilation_status()} - - # TODO - elif argument == "compile": - if openplc_runtime.status == "Running" or openplc_runtime.status == "Compiling": - pass + elif argument == "compilation-status": + status = openplc_runtime.is_compiling + return {"CompilationStatus": status} + + elif argument == "compilation-logs": + logs = openplc_runtime.compilation_status() + return {"compilation-logs": logs} elif argument == "status": - return {"current_status": "operational", - "details": data} + return {"current_status": "operational", "details": data} elif argument == "ping": return {"status": "pong"} @@ -66,11 +65,29 @@ def restapi_callback_get(argument: str, data: dict) -> dict: # file upload POST handler def restapi_callback_post(argument: str, data: dict) -> dict: - # TODO + # TODO logging debug level + print(f"POST | [{__name__}] Received argument: {argument}, data: {data}") + if argument == "upload_file": - logs = openplc_runtime.logs() - return {"runtime_logs": logs} + try: + st_file = flask.request.files['file'] + # TODO save file + print(st_file.filename) + + return {"UploadFile": "Success"} + except: + return {"UploadFile": "Fail"} + elif argument == "compile-program": + if (openplc_runtime.status() == "Compiling"): + return {"RuntimeStatus": "Compiling"} + + # st_file = flask.request.args.get('file') + st_file = flask.request.files['file'] + openplc_runtime.compile_program(st_file) + + return {"RuntimeStatus": "Program Compiled"} + else: return {"error": "Unknown argument"} From 940a0b15dd64fbc8d41644fd62db6afd446199e2 Mon Sep 17 00:00:00 2001 From: lucasbutzke Date: Fri, 4 Jul 2025 14:18:33 -0400 Subject: [PATCH 5/7] [RTOP-23] Fix routes --- webserver/webserver.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/webserver/webserver.py b/webserver/webserver.py index 5170bd0..5f2ed06 100644 --- a/webserver/webserver.py +++ b/webserver/webserver.py @@ -14,7 +14,6 @@ import sys import ctypes import socket import mimetypes -import json import flask import flask_login @@ -49,7 +48,7 @@ def restapi_callback_get(argument: str, data: dict) -> dict: elif argument == "compilation-status": status = openplc_runtime.is_compiling - return {"CompilationStatus": status} + return {"compilation-status": status} elif argument == "compilation-logs": logs = openplc_runtime.compilation_status() @@ -73,6 +72,7 @@ def restapi_callback_post(argument: str, data: dict) -> dict: st_file = flask.request.files['file'] # TODO save file print(st_file.filename) + st_file.save("st_files/") return {"UploadFile": "Success"} except: @@ -919,6 +919,7 @@ def upload_program(): if (prog_file.filename == ''): return draw_blank_page() + "

Error

You need to select a file to be uploaded!

Use the back-arrow on your browser to return

" + # TODO colocar em outra funçao filename = str(random.randint(1,1000000)) + ".st" prog_file.save(os.path.join('st_files', filename)) From fa3c3cd88845365ea32aff074adf6bb485683ff3 Mon Sep 17 00:00:00 2001 From: lucasbutzke Date: Mon, 7 Jul 2025 17:43:14 -0400 Subject: [PATCH 6/7] [RTOP-23] File context in openplc.py and restapi minor fix --- webserver/active_program | 2 +- webserver/openplc.py | 33 ++++++++++++++---------------- webserver/scripts/openplc_driver | 2 +- webserver/scripts/openplc_platform | 2 +- webserver/st_files/Dockerfile | 31 ++++++++++++++++++++++++++++ webserver/webserver.py | 25 +++++++++++++--------- 6 files changed, 64 insertions(+), 31 deletions(-) create mode 100644 webserver/st_files/Dockerfile diff --git a/webserver/active_program b/webserver/active_program index 5621f10..9414382 100755 --- a/webserver/active_program +++ b/webserver/active_program @@ -1 +1 @@ -890590.st +Dockerfile diff --git a/webserver/openplc.py b/webserver/openplc.py index 6980c97..f1a22f7 100644 --- a/webserver/openplc.py +++ b/webserver/openplc.py @@ -114,9 +114,9 @@ class runtime: compilation_status_str = "" # Extract debug information from program - f = open('./st_files/' + st_file, "r") - combined_lines = f.read() - f.close() + with open('./st_files/' + st_file, "r") as f: + combined_lines = f.read() + combined_lines = combined_lines.split('\n') program_lines = [] c_debug_lines = [] @@ -132,9 +132,9 @@ class runtime: # Could not find debug info on program uploaded if os.path.isfile('./st_files/' + st_file + '.dbg'): # Debugger info exists on file - open it - f = open('./st_files/' + st_file + '.dbg', "r") - c_debug = f.read() - f.close() + with open('./st_files/' + st_file + '.dbg', "r") as f: + c_debug = f.read() + else: # No debug info... probably a program generated from the old editor. Use the blank debug info just to compile the program f = open('./core/debug.blank', "r") @@ -142,9 +142,8 @@ class runtime: f.close() # Write c_debug file - f = open('./core/debug.cpp', "w") - f.write(c_debug) - f.close() + with open('./core/debug.cpp', "w") as f: + f.write(c_debug) # Start compilation a = subprocess.Popen(['./scripts/compile_program.sh', str(st_file)], stdout=subprocess.PIPE, stderr=subprocess.STDOUT) @@ -155,17 +154,15 @@ class runtime: c_debug = '\n'.join(c_debug_lines) # Write c_debug file - f = open('./core/debug.cpp', "w") - f.write(c_debug) - f.close() + with open('./core/debug.cpp', "w") as f: + f.write(c_debug) #Write program and debug files - f = open('./st_files/' + st_file, "w") - f.write(program) - f.close() - f = open('./st_files/' + st_file + '.dbg', "w") - f.write(c_debug) - f.close() + with open('./st_files/' + st_file, "w") as f: + f.write(program) + + with open('./st_files/' + st_file + '.dbg', "w") as f: + f.write(c_debug) # Start compilation a = subprocess.Popen(['./scripts/compile_program.sh', str(st_file)], stdout=subprocess.PIPE, stderr=subprocess.STDOUT) diff --git a/webserver/scripts/openplc_driver b/webserver/scripts/openplc_driver index 61aaae3..055bd00 100755 --- a/webserver/scripts/openplc_driver +++ b/webserver/scripts/openplc_driver @@ -1 +1 @@ -rpi +blank_linux diff --git a/webserver/scripts/openplc_platform b/webserver/scripts/openplc_platform index 61aaae3..a08e1f3 100755 --- a/webserver/scripts/openplc_platform +++ b/webserver/scripts/openplc_platform @@ -1 +1 @@ -rpi +linux diff --git a/webserver/st_files/Dockerfile b/webserver/st_files/Dockerfile new file mode 100644 index 0000000..a6d8cb4 --- /dev/null +++ b/webserver/st_files/Dockerfile @@ -0,0 +1,31 @@ +FROM debian:bullseye-20240722 + +COPY . /workdir + +WORKDIR /workdir + +RUN mkdir /docker_persistent + +VOLUME /docker_persistent + +# setup docker +RUN ./install.sh docker \ + && touch /docker_persistent/mbconfig.cfg \ + && touch /docker_persistent/persistent.file \ + && mkdir /docker_persistent/st_files \ + && cp /workdir/webserver/openplc.db /docker_persistent/openplc.db \ + && mv /workdir/webserver/openplc.db /workdir/webserver/openplc_default.db \ + && cp /workdir/webserver/dnp3.cfg /docker_persistent/dnp3.cfg \ + && mv /workdir/webserver/dnp3.cfg /workdir/webserver/dnp3_default.cfg \ + && cp -r /workdir/webserver/st_files/ /docker_persistent/st_files/ \ + && mv /workdir/webserver/st_files /workdir/webserver/st_files_default \ + && cp /workdir/webserver/active_program /docker_persistent/active_program \ + && mv /workdir/webserver/active_program /workdir/webserver/active_program_default \ + && ln -s /docker_persistent/mbconfig.cfg /workdir/webserver/mbconfig.cfg \ + && ln -s /docker_persistent/persistent.file /workdir/webserver/persistent.file \ + && ln -s /docker_persistent/openplc.db /workdir/webserver/openplc.db \ + && ln -s /docker_persistent/dnp3.cfg /workdir/webserver/dnp3.cfg \ + && ln -s /docker_persistent/st_files /workdir/webserver/st_files \ + && ln -s /docker_persistent/active_program /workdir/webserver/active_program + +ENTRYPOINT ["./start_openplc.sh"] diff --git a/webserver/webserver.py b/webserver/webserver.py index 5f2ed06..c46ddcf 100644 --- a/webserver/webserver.py +++ b/webserver/webserver.py @@ -48,7 +48,7 @@ def restapi_callback_get(argument: str, data: dict) -> dict: elif argument == "compilation-status": status = openplc_runtime.is_compiling - return {"compilation-status": status} + return {"is-compiling": status} elif argument == "compilation-logs": logs = openplc_runtime.compilation_status() @@ -67,14 +67,14 @@ def restapi_callback_post(argument: str, data: dict) -> dict: # TODO logging debug level print(f"POST | [{__name__}] Received argument: {argument}, data: {data}") - if argument == "upload_file": + if argument == "upload-file": try: + # TODO validate filename, content and size st_file = flask.request.files['file'] - # TODO save file print(st_file.filename) - st_file.save("st_files/") - + st_file.save(f"st_files/{st_file.filename}") return {"UploadFile": "Success"} + except: return {"UploadFile": "Fail"} @@ -82,14 +82,19 @@ def restapi_callback_post(argument: str, data: dict) -> dict: if (openplc_runtime.status() == "Compiling"): return {"RuntimeStatus": "Compiling"} - # st_file = flask.request.args.get('file') - st_file = flask.request.files['file'] - openplc_runtime.compile_program(st_file) + try: + # TODO return compilation result and validate filename + # st_file = flask.request.args.get('file') + st_file = flask.request.files['file'] + # print(f"st_files/{st_file.filename}") + openplc_runtime.compile_program(f"{st_file.filename}") + return {"CompilationStatus": "Program Compiled"} - return {"RuntimeStatus": "Program Compiled"} + except Exception as e: + return {"CompilationStatus": e} else: - return {"error": "Unknown argument"} + return {"PostError": "Unknown argument"} class User(flask_login.UserMixin): From a8ddd94025c8dfcf34717e76826dbbfec0f46286 Mon Sep 17 00:00:00 2001 From: lucasbutzke Date: Thu, 10 Jul 2025 10:38:50 -0400 Subject: [PATCH 7/7] [RTOP-23] PR review fix --- .gitignore | 3 +++ webserver/restapi.py | 4 ++-- webserver/webserver.py | 2 +- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index 33f669c..8bf317a 100644 --- a/.gitignore +++ b/.gitignore @@ -33,8 +33,11 @@ webserver/core/glue_generator webserver/core/openplc webserver/iec2c webserver/st_optimizer +webserver/active_program utils/libmodbus_src/src/.libs/* utils/libmodbus_src/tests/.libs/* +webserver/scripts/openplc_driver +webserver/scripts/openplc_platform # Runtime directories .venv \ No newline at end of file diff --git a/webserver/restapi.py b/webserver/restapi.py index e4bd113..339d7f3 100644 --- a/webserver/restapi.py +++ b/webserver/restapi.py @@ -32,7 +32,7 @@ def restapi_plc_get(command): result = _handler_callback_get(command, data) return jsonify(result), 200 except Exception as e: - print(f"Error in restapi_start_plc: {e}") + print(f"Error in restapi_plc_get: {e}") return jsonify({"error": str(e)}), 500 @restapi_bp.route("/", methods=["POST"]) @@ -47,5 +47,5 @@ def restapi_plc_post(command): result = _handler_callback_post(command, data) return jsonify(result), 200 except Exception as e: - print(f"Error in restapi_start_plc_post: {e}") + print(f"Error in restapi_plc_post: {e}") return jsonify({"error": str(e)}), 500 diff --git a/webserver/webserver.py b/webserver/webserver.py index c46ddcf..cfeb1b7 100644 --- a/webserver/webserver.py +++ b/webserver/webserver.py @@ -924,7 +924,7 @@ def upload_program(): if (prog_file.filename == ''): return draw_blank_page() + "

Error

You need to select a file to be uploaded!

Use the back-arrow on your browser to return

" - # TODO colocar em outra funçao + # TODO realocate to another function filename = str(random.randint(1,1000000)) + ".st" prog_file.save(os.path.join('st_files', filename))