esp_routes_basic and server comm
This commit is contained in:
10
routes/esp_routes.py
Normal file
10
routes/esp_routes.py
Normal 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
10
routes/shared.py
Normal 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
|
||||
}
|
||||
@@ -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')
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -11,7 +11,6 @@
|
||||
<p><strong>Status:</strong> <span id="status"></span></p>
|
||||
<p><strong>Counter:</strong> <span id="counter"></span></p>
|
||||
|
||||
<script src="https://cdn.socket.io/4.6.1/socket.io.min.js"></script>
|
||||
<script>
|
||||
const socket = io();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user