Fix setup + fix logger x display + input
This commit is contained in:
+61
-4
@@ -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")
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
<script src="../static/js/bootstrap.bundle.min.js"></script>
|
||||
</head>
|
||||
<body class="sb-nav-fixed">
|
||||
<script>
|
||||
<!-- <script>
|
||||
var intTime=350;
|
||||
// fix visualizzazioni
|
||||
fixDisplay();
|
||||
@@ -47,7 +47,7 @@
|
||||
timeout = setTimeout(dataRefresh, intTime);
|
||||
}
|
||||
|
||||
</script>
|
||||
</script> -->
|
||||
<nav class="navbar navbar-expand-md bg-dark navbar-dark">
|
||||
<!-- Brand -->
|
||||
<a class="navbar-brand" href="/">ANALOGGER</a>
|
||||
|
||||
@@ -2,40 +2,73 @@
|
||||
|
||||
{% block content %}
|
||||
<main>
|
||||
<script>
|
||||
// Funzione startLog: fa chiamata per settare a 1 il LOG:STATUS
|
||||
function startLog(){
|
||||
$.ajax({
|
||||
type: 'PUT'
|
||||
,url: "/api/v1/log/start"
|
||||
,data: ""
|
||||
,success: function(){
|
||||
alert('Log Started');
|
||||
}
|
||||
})
|
||||
intTime= 200;
|
||||
};
|
||||
<script type="text/javascript">
|
||||
var intTime=350;
|
||||
// fix visualizzazioni
|
||||
fixDisplay();
|
||||
// avvio timer
|
||||
var timeout = setTimeout(dataRefresh, intTime);
|
||||
|
||||
// Funzione stopLog: fa chiamata per settare a 0 il LOG:STATUS
|
||||
function stopLog(){
|
||||
$.ajax({
|
||||
type: 'PUT'
|
||||
,url: "/api/v1/log/stop"
|
||||
,data: ""
|
||||
,success: function(){
|
||||
alert('Log Stopped');
|
||||
}
|
||||
})
|
||||
intTime = 5000;
|
||||
};
|
||||
function fixDisplay(){
|
||||
$("#divNewFile").toggle();
|
||||
}
|
||||
function dataRefresh() {
|
||||
// scarico i dati aggioranti
|
||||
$.ajax({url: "/api/v1/channels/all", success: function(result){
|
||||
// compilo i dati scaricati
|
||||
$("#Chan0").html(result.Ch0);
|
||||
$("#Chan1").html(result.Ch1);
|
||||
$("#Chan2").html(result.Ch2);
|
||||
$("#Chan3").html(result.Ch3);
|
||||
$("#Chan4").html(result.Ch4);
|
||||
$("#Chan5").html(result.Ch5);
|
||||
$("#Chan6").html(result.Ch6);
|
||||
$("#Chan7").html(result.Ch7);
|
||||
$("#LogFrequency").html(result.Freq);
|
||||
$("#LoggerTime").html(result.timeLog);
|
||||
$("#ServerTime").html(result.timeSrv);
|
||||
$("#ChanScaleMin1").html(result.ChScaleMin1);
|
||||
$("#ChanScaleMax1").html(result.ChScaleMax1);
|
||||
$("#ChanRealMin1").html(result.ChRealMin1);
|
||||
$("#ChanRealMax1").html(result.ChRealMax1);
|
||||
}});
|
||||
|
||||
// Funzione startNewRec: assegna nuovo nome con data e ora al file .csv di record
|
||||
function startNewRec(){
|
||||
var d = new Date();
|
||||
var name= d.toISOString().replace('T','_').replace('-','_').replace('-','_').replace(':','_').replace(':','_').replace('.','_').replace('Z','')+'.csv';
|
||||
//console.log(name);
|
||||
$('#NewSessionName').val(name);
|
||||
timeout = setTimeout(dataRefresh, intTime);
|
||||
};
|
||||
|
||||
// Funzione startLog: fa chiamata per settare a 1 il LOG:STATUS
|
||||
function startLog(){
|
||||
$.ajax({
|
||||
type: 'PUT'
|
||||
,url: "/api/v1/log/start"
|
||||
,data: ""
|
||||
,success: function(){
|
||||
alert('Log Started');
|
||||
}
|
||||
})
|
||||
intTime= 200;
|
||||
};
|
||||
|
||||
// Funzione stopLog: fa chiamata per settare a 0 il LOG:STATUS
|
||||
function stopLog(){
|
||||
$.ajax({
|
||||
type: 'PUT'
|
||||
,url: "/api/v1/log/stop"
|
||||
,data: ""
|
||||
,success: function(){
|
||||
alert('Log Stopped');
|
||||
}
|
||||
})
|
||||
intTime = 5000;
|
||||
};
|
||||
|
||||
// Funzione startNewRec: assegna nuovo nome con data e ora al file .csv di record
|
||||
function startNewRec(){
|
||||
var d = new Date();
|
||||
var name= d.toISOString().replace('T','_').replace('-','_').replace('-','_').replace(':','_').replace(':','_').replace('.','_').replace('Z','')+'.csv';
|
||||
//console.log(name);
|
||||
$('#NewSessionName').val(name);
|
||||
}
|
||||
</script>
|
||||
<div class="container-fluid py-2">
|
||||
<div class="card mb-4">
|
||||
|
||||
@@ -2,30 +2,87 @@
|
||||
|
||||
{% block content %}
|
||||
<main>
|
||||
<script>
|
||||
var intTime=1000;
|
||||
<script type="text/javascript">
|
||||
var intTime=200;
|
||||
refreshInput();
|
||||
|
||||
function saveMin(){
|
||||
$.ajax({
|
||||
type: 'PUT'
|
||||
,url: "/api/v1/setup/saveInMin"
|
||||
,data: ""
|
||||
,success: function(){
|
||||
alert('Min Set');
|
||||
}
|
||||
})
|
||||
};
|
||||
// carico la prima volta i dati
|
||||
function refreshInput() {
|
||||
// scarico i dati aggioranti
|
||||
$.ajax({url: "/api/v1/channels/current", success: function(result){
|
||||
// compilo i dati scaricati
|
||||
$("#CurrIn").html(result.CurrIn);
|
||||
$("#CurrOut").html(result.CurrOut);
|
||||
$("#LogFrequency").html(result.Freq);
|
||||
$("#LoggerTime").html(result.timeLog);
|
||||
$("#ServerTime").html(result.timeSrv);
|
||||
$("#ddlChannels").val(result.numCh);
|
||||
$("#MinOut").val(result.MinOut);
|
||||
$("#MaxOut").val(result.MaxOut);
|
||||
$("#MinIn").html(result.MinIn);
|
||||
$("#MaxIn").html(result.MaxIn);
|
||||
}});
|
||||
|
||||
function saveMax(){
|
||||
$.ajax({
|
||||
timeoutSetting = setTimeout(refreshSettings, intTime);
|
||||
}
|
||||
|
||||
// avvio timer
|
||||
var timeoutSetting = setTimeout(refreshSettings, intTime);
|
||||
|
||||
function refreshSettings() {
|
||||
// scarico i dati aggioranti
|
||||
$.ajax({url: "/api/v1/channels/current", success: function(result){
|
||||
// compilo i dati scaricati
|
||||
$("#CurrIn").html(result.CurrIn);
|
||||
$("#CurrOut").html(result.CurrOut);
|
||||
$("#LogFrequency").html(result.Freq);
|
||||
$("#LoggerTime").html(result.timeLog);
|
||||
$("#ServerTime").html(result.timeSrv);
|
||||
// $("#MinOut").val(result.MinOut);
|
||||
// $("#MaxOut").val(result.MaxOut);
|
||||
// $("#MinIn").html(result.MinIn);
|
||||
// $("#MaxIn").html(result.MaxIn);
|
||||
}});
|
||||
|
||||
timeoutSetting = setTimeout(refreshSettings, intTime);
|
||||
}
|
||||
|
||||
function saveMin(){
|
||||
$.ajax({
|
||||
type: 'PUT'
|
||||
,url: "/api/v1/setup/saveInMin"
|
||||
,data: ""
|
||||
,success: function(){
|
||||
alert('Min Set');
|
||||
}
|
||||
})
|
||||
};
|
||||
|
||||
function saveMax(){
|
||||
$.ajax({
|
||||
type: 'PUT'
|
||||
,url: "/api/v1/setup/saveInMax"
|
||||
,data: ""
|
||||
,success: function(){
|
||||
alert('Max Set');
|
||||
}
|
||||
})
|
||||
};
|
||||
|
||||
function setChannel(ddlChannels) {
|
||||
// fare vera funzione x salvare QUALE sia il canale attivo ins etup 8all'apertura va impostato 1...)
|
||||
var selectedText = ddlChannels.options[ddlChannels.selectedIndex].innerHTML;
|
||||
var selectedValue = ddlChannels.value;
|
||||
// alert("Selected Text: " + selectedText + " Value: " + selectedValue);
|
||||
$.ajax({
|
||||
type: 'PUT'
|
||||
,url: "/api/v1/setup/saveInMax"
|
||||
,url: "/api/v1/setup/selectChannel/" + ddlChannels.value
|
||||
,data: ""
|
||||
,success: function(){
|
||||
alert('Max Set');
|
||||
}
|
||||
})
|
||||
};
|
||||
// ,success: function(){
|
||||
// alert('Log Stopped');
|
||||
// }
|
||||
});
|
||||
};
|
||||
|
||||
</script>
|
||||
<div class="container-fluid py-2">
|
||||
@@ -65,22 +122,7 @@ function saveMax(){
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<script type="text/javascript">
|
||||
function setChannel(ddlChannels) {
|
||||
// fare vera funzione x salvare QUALE sia il canale attivo ins etup 8all'apertura va impostato 1...)
|
||||
var selectedText = ddlChannels.options[ddlChannels.selectedIndex].innerHTML;
|
||||
var selectedValue = ddlChannels.value;
|
||||
// alert("Selected Text: " + selectedText + " Value: " + selectedValue);
|
||||
$.ajax({
|
||||
type: 'PUT'
|
||||
,url: "/api/v1/setup/selectChannel/" + ddlChannels.value
|
||||
,data: ""
|
||||
// ,success: function(){
|
||||
// alert('Log Stopped');
|
||||
// }
|
||||
})
|
||||
}
|
||||
</script>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
<div class="card-body text-center">
|
||||
@@ -88,9 +130,9 @@ function saveMax(){
|
||||
<div class="col-3"></div>
|
||||
<div class="col-6">
|
||||
<div class="row">
|
||||
<div class="col-4"><span id="ChanRealMin1"></span></div>
|
||||
<div class="col-4"><span id="Chan0"></span></div>
|
||||
<div class="col-4"><span id="ChanRealMax1"></span></div>
|
||||
<div class="col-4"><span id="MinIn">000</span></div>
|
||||
<div class="col-4"><span id="CurrIn">000</span></div>
|
||||
<div class="col-4"><span id="MaxIn">000</span></div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-3"></div>
|
||||
@@ -107,69 +149,25 @@ function saveMax(){
|
||||
<div class="col-2"></div>
|
||||
</div>
|
||||
|
||||
<div class="row text-center mt-2">
|
||||
<div class="col-2">OUT</div>
|
||||
<form method="POST" action="/api/v1/scaleout">
|
||||
<div class="col-4">
|
||||
<input type="number" class="form-control" id="ScaleMin" name="ScaleMin"></input>
|
||||
<form method="POST" action="/api/v1/scaleout">
|
||||
<div class="row text-center mt-2">
|
||||
<div class="col-2">OUT</div>
|
||||
<div class="col-8">
|
||||
<div class="row">
|
||||
<div class="col-4">
|
||||
<input type="number" class="form-control" id="MinOut" name="MinOut"></input>
|
||||
</div>
|
||||
<div class="col-4"><span id="CurrOut">{{ Out0 }}</span></div>
|
||||
<div class="col-4">
|
||||
<input type="number" class="form-control" id="MaxOut" name="MaxOut"></input>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-4">Scaled OUT</div>
|
||||
<div class="col-4">
|
||||
<input type="number" class="form-control" id="ScaleMax" name="ScaleMax"></input>
|
||||
</div>
|
||||
<div class="input-group-append">
|
||||
<input type="submit" value="Invio" class="btn btn-success"></input>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<!-- <div class="row">
|
||||
<div class="col-2 input-group mb-3 input-group-text">
|
||||
<strong>Save OUT</strong>
|
||||
<div class="col-2">
|
||||
<input type="submit" value="Invio" class="btn btn-success"></input>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-5">
|
||||
<form method="POST" action="/api/v1/rmin1">
|
||||
<div class="input-group mb-3">
|
||||
<span class="input-group-text">Min: <span id="ChanRealMin1"></span></span>
|
||||
<div class="input-group-append">
|
||||
<input type="submit" value="SET MIN" class="btn btn-success"></input>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
<div class="col-5">
|
||||
<form method="POST" action="/api/v1/rmax1">
|
||||
<div class="input-group mb-3">
|
||||
<span class="input-group-text">Max: <span id="ChanRealMax1"></span></span>
|
||||
<div class="input-group-append">
|
||||
<input type="submit" value="SET MAX" class="btn btn-success"></input>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div> -->
|
||||
|
||||
<!-- <div class="row">
|
||||
<div class="col-2 input-group mb-3 input-group-text">
|
||||
<strong>Fattori di scala</strong>
|
||||
</div>
|
||||
<form method="POST" action="/api/v1/scaleout">
|
||||
<div class="input-group mb-3">
|
||||
<span class="input-group-text">Min: <span id="ChanScaleMin1"></span></span>
|
||||
<input type="number" class="form-control" id="ScaleMin1" name="ScaleMin1"></input>
|
||||
<div class="input-group-append">
|
||||
<input type="submit" value="SET" class="btn btn-success"></input>
|
||||
</div>
|
||||
</div>
|
||||
<div class="input-group mb-3">
|
||||
<span class="input-group-text">Max: <span id="ChanScaleMax1"></span></span>
|
||||
<input type="number" class="form-control" id="ScaleMax1" name="ScaleMax1"></input>
|
||||
<div class="input-group-append">
|
||||
<input type="submit" value="SET" class="btn btn-success"></input>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div> -->
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user