From f8cf64532518123ac95818678e8911fbc6a7975b Mon Sep 17 00:00:00 2001 From: derlole <122916573+derlole@users.noreply.github.com> Date: Thu, 17 Apr 2025 12:33:11 +0000 Subject: [PATCH] esp_routes_basic and server comm --- routes/esp_routes.py | 10 ++++++++++ routes/shared.py | 10 ++++++++++ routes/unsecure_routes.py | 21 ++++++++------------- server.py | 6 ++++-- templates/test.html | 1 - 5 files changed, 32 insertions(+), 16 deletions(-) create mode 100644 routes/esp_routes.py create mode 100644 routes/shared.py diff --git a/routes/esp_routes.py b/routes/esp_routes.py new file mode 100644 index 0000000..ffda1f7 --- /dev/null +++ b/routes/esp_routes.py @@ -0,0 +1,10 @@ +from flask import Blueprint, render_template, request, jsonify +import routes.shared as shared +esp = Blueprint('eps', __name__, url_prefix='/unsecure/esp') + + +@esp.route('/') +def fetch_command(): + pCd = shared.pending_command + shared.reset_command() + return jsonify(pCd) \ No newline at end of file diff --git a/routes/shared.py b/routes/shared.py new file mode 100644 index 0000000..42df8a0 --- /dev/null +++ b/routes/shared.py @@ -0,0 +1,10 @@ +pending_command = {'command': None, 'command-URL': None, 'command-expected': None, 'command-expected-URL': None} + +def reset_command(): + global pending_command + pending_command = { + 'command': None, + 'command-URL': None, + 'command-expected': None, + 'command-expected-URL': None + } \ No newline at end of file diff --git a/routes/unsecure_routes.py b/routes/unsecure_routes.py index 2a9c990..012a658 100644 --- a/routes/unsecure_routes.py +++ b/routes/unsecure_routes.py @@ -1,8 +1,8 @@ from flask import Blueprint, render_template, request, jsonify - +import routes.shared as shared unsecure = Blueprint('unsecure', __name__, url_prefix='/unsecure') -pending_command = None + @unsecure.route('/') def index(): @@ -10,21 +10,16 @@ def index(): @unsecure.route('/send') def send_command(): - global pending_command + pCd = shared.pending_command befehl = request.args.get('befehl') if befehl: - pending_command = befehl - return f"Befehl '{befehl}' gespeichert." + pCd['command'] = befehl + pCd['command-URL'] = '/unsecure/esp/someURI' + pCd.update({'extra': 'test'}) + print(pCd) + return f"Befehl '{pCd}' gespeichert." return "Kein Befehl angegeben.", 400 -@unsecure.route('/fetch') -def fetch_command(): - global pending_command - if pending_command: - cmd = pending_command - pending_command = None - return jsonify({'befehl': cmd}) - return jsonify({'befehl': None}) @unsecure.route('/test') def test(): return render_template('test.html') diff --git a/server.py b/server.py index 605b07b..0c700f1 100644 --- a/server.py +++ b/server.py @@ -37,6 +37,7 @@ from flask import Flask from flask_socketio import SocketIO from routes.unsecure_routes import unsecure +from routes.esp_routes import esp @@ -47,6 +48,7 @@ socketio = SocketIO(app, cors_allowed_origins="*", async_mode='threading') # Blueprint registrieren app.register_blueprint(unsecure) +app.register_blueprint(esp) # Simuliere regelmäßige Daten-Updates import threading @@ -55,7 +57,7 @@ import time def send_data(): counter = 0 while True: - print(f"Sending data: {counter}") + #print(f"Sending data: {counter}") data = { 'test': 'Live-Daten', 'status': 'OK', @@ -71,4 +73,4 @@ thread.daemon = True thread.start() if __name__ == '__main__': - socketio.run(app, host='0.0.0.0', port=5000) + socketio.run(app, host='0.0.0.0', port=3060) diff --git a/templates/test.html b/templates/test.html index c91825a..143fe3c 100644 --- a/templates/test.html +++ b/templates/test.html @@ -11,7 +11,6 @@
Status:
Counter:
-