From 790491db2b7471d9e0bef58eaeb9a751b1d91902 Mon Sep 17 00:00:00 2001 From: Marco Locatelli Date: Fri, 26 Mar 2021 16:12:00 +0100 Subject: [PATCH] Fix setup + fix logger x display + input --- server/FlythisServer.py | 65 ++++++++++- server/templates/layout.html | 4 +- server/templates/logger.html | 95 ++++++++++------ server/templates/settings.html | 196 ++++++++++++++++----------------- 4 files changed, 224 insertions(+), 136 deletions(-) diff --git a/server/FlythisServer.py b/server/FlythisServer.py index cb4c0ba..3b429a5 100644 --- a/server/FlythisServer.py +++ b/server/FlythisServer.py @@ -30,6 +30,10 @@ redSrv0 = redis.Redis( port=REDIS_PORT, db=0) +def getRedisVal(redisKey): + return redSrv0.get(redisKey).decode('utf-8') + + flaskApp = Flask(__name__) @flaskApp.route("/") #funzione main: passa al template home il titolo @@ -55,7 +59,15 @@ def logger(): 'Ch4' : redSrv0.get('RTDATA:CH:4').decode('utf-8'), 'Ch5' : redSrv0.get('RTDATA:CH:5').decode('utf-8'), 'Ch6' : redSrv0.get('RTDATA:CH:6').decode('utf-8'), - 'Ch7' : redSrv0.get('RTDATA:CH:7').decode('utf-8') + 'Ch7' : redSrv0.get('RTDATA:CH:7').decode('utf-8'), + 'Out0' : getRedisVal('RTDATA:OUT:0'), + 'Out1' : getRedisVal('RTDATA:OUT:1'), + 'Out2' : getRedisVal('RTDATA:OUT:2'), + 'Out3' : getRedisVal('RTDATA:OUT:3'), + 'Out4' : getRedisVal('RTDATA:OUT:4'), + 'Out5' : getRedisVal('RTDATA:OUT:5'), + 'Out6' : getRedisVal('RTDATA:OUT:6'), + 'Out7' : getRedisVal('RTDATA:OUT:7') } #assegno il template html di riferimento return render_template('logger.html', **channelsData) @@ -65,7 +77,23 @@ def logger(): def setup(): channelsData = { 'title' : 'Settings', - 'Freq' : redSrv0.get('SETTINGS:LOG:FREQ').decode('utf-8') + 'Freq' : redSrv0.get('SETTINGS:LOG:FREQ').decode('utf-8'), + 'Ch0' : getRedisVal('RTDATA:CH:0'), + 'Ch1' : getRedisVal('RTDATA:CH:1'), + 'Ch2' : getRedisVal('RTDATA:CH:2'), + 'Ch3' : getRedisVal('RTDATA:CH:3'), + 'Ch4' : getRedisVal('RTDATA:CH:4'), + 'Ch5' : getRedisVal('RTDATA:CH:5'), + 'Ch6' : getRedisVal('RTDATA:CH:6'), + 'Ch7' : getRedisVal('RTDATA:CH:7'), + 'Out0' : getRedisVal('RTDATA:OUT:0'), + 'Out1' : getRedisVal('RTDATA:OUT:1'), + 'Out2' : getRedisVal('RTDATA:OUT:2'), + 'Out3' : getRedisVal('RTDATA:OUT:3'), + 'Out4' : getRedisVal('RTDATA:OUT:4'), + 'Out5' : getRedisVal('RTDATA:OUT:5'), + 'Out6' : getRedisVal('RTDATA:OUT:6'), + 'Out7' : getRedisVal('RTDATA:OUT:7') } #assegno il template html di riferimento return render_template('settings.html', **channelsData) @@ -96,6 +124,14 @@ def api_channels_all(): 'Ch5' : redSrv0.get('RTDATA:CH:5').decode('utf-8'), 'Ch6' : redSrv0.get('RTDATA:CH:6').decode('utf-8'), 'Ch7' : redSrv0.get('RTDATA:CH:7').decode('utf-8'), + 'Out0' : getRedisVal('RTDATA:OUT:0'), + 'Out1' : getRedisVal('RTDATA:OUT:1'), + 'Out2' : getRedisVal('RTDATA:OUT:2'), + 'Out3' : getRedisVal('RTDATA:OUT:3'), + 'Out4' : getRedisVal('RTDATA:OUT:4'), + 'Out5' : getRedisVal('RTDATA:OUT:5'), + 'Out6' : getRedisVal('RTDATA:OUT:6'), + 'Out7' : getRedisVal('RTDATA:OUT:7'), 'ChScaleMax' : redSrv0.get('SETTINGS:IN:MAX:'+str(numCh)).decode('utf-8'), 'ChScaleMin' : redSrv0.get('SETTINGS:IN:MIN:'+str(numCh)).decode('utf-8'), 'ChRealMax' : redSrv0.get('SETTINGS:OUT:MAX:'+str(numCh)).decode('utf-8'), @@ -104,6 +140,27 @@ def api_channels_all(): # restituisce in formato json i dati letti da redis return jsonify(channelsData) + +# definisco una NUOVA route a cui rispondere su chiamta in metodo GET x restituire dati aggiornati +@flaskApp.route("/api/v1/channels/current", methods=['GET']) +def api_channels_current(): + numCh = redSrv0.get('SETTINGS:SELECTED_CH').decode('utf-8') + #funzione api_channels_all: legge direttamente da redis, ritorna jsonify + result = { + 'numCh' : numCh, + 'timeSrv' : getRedisVal('RTDATA:TIME:SRV'), + 'timeLog' : getRedisVal('RTDATA:TIME:LOG'), + 'Freq' : getRedisVal('SETTINGS:LOG:FREQ'), + 'CurrIn' : getRedisVal('RTDATA:CH:'+str(numCh)), + 'CurrOut' : getRedisVal('RTDATA:OUT:'+str(numCh)), + 'MaxOut' : getRedisVal('SETTINGS:OUT:MAX:'+str(numCh)), + 'MinOut' : getRedisVal('SETTINGS:OUT:MIN:'+str(numCh)), + 'MaxIn' : getRedisVal('SETTINGS:IN:MAX:'+str(numCh)), + 'MinIn' : getRedisVal('SETTINGS:IN:MIN:'+str(numCh)) + } + # restituisce in formato json i dati letti da redis + return jsonify(result) + # Route di comando x LOG: start e stop @flaskApp.route("/api/v1/log/start", methods=['PUT']) def start_log(): @@ -161,9 +218,9 @@ def setFrequency(): @flaskApp.route("/api/v1/scaleout", methods=['POST']) def setScale(): indexCh = redSrv0.get('SETTINGS:SELECTED_CH').decode('utf-8') - scaleMin = request.form['ScaleMin'] + scaleMin = request.form['MinOut'] redSrv0.set('SETTINGS:OUT:MIN:'+ str(indexCh), scaleMin) - scaleMax = request.form['ScaleMax'] + scaleMax = request.form['MaxOut'] redSrv0.set('SETTINGS:OUT:MAX:'+ str(indexCh), scaleMax) # rimando in settings return redirect("/settings") diff --git a/server/templates/layout.html b/server/templates/layout.html index ea26f17..cf40d5f 100644 --- a/server/templates/layout.html +++ b/server/templates/layout.html @@ -13,7 +13,7 @@ - -->