esp_routes_basic and server comm

This commit is contained in:
derlole
2025-04-17 12:33:11 +00:00
parent 58f9d3b451
commit f8cf645325
5 changed files with 32 additions and 16 deletions

10
routes/esp_routes.py Normal file
View File

@@ -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)

10
routes/shared.py Normal file
View File

@@ -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
}

View File

@@ -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')