gestione valori scalatura

This commit is contained in:
Marco Locatelli
2021-03-25 13:04:04 +01:00
parent ea269a7e5d
commit f5cb01c06d
7 changed files with 210 additions and 139 deletions
+19 -7
View File
@@ -14,12 +14,24 @@ redSrv0 = redis.Redis(
port=REDIS_PORT,
db=0)
#se non c'è un valore in LOG:STATUS, lo assegno
if redSrv0.get('RTDATA:LOG:STATUS') is None:
redSrv0.set('RTDATA:LOG:STATUS',1)
#se non c'è un valore nei campi di redis, gli do 1
if redSrv0.get('SETTINGS:LOG:STATUS') is None:
redSrv0.set('SETTINGS:LOG:STATUS',1)
if redSrv0.get('SETTINGS:CH:SCALE:MIN1') is None:
redSrv0.set('SETTINGS:CH:SCALE:MIN1',1)
if redSrv0.get('SETTINGS:CH:SCALE:MAX1') is None:
redSrv0.set('SETTINGS:CH:SCALE:MAX1',1)
if redSrv0.get('SETTINGS:CH:REAL:MIN1') is None:
redSrv0.set('SETTINGS:CH:REAL:MIN1',1)
if redSrv0.get('SETTINGS:CH:REAL:MAX1') is None:
redSrv0.set('SETTINGS:CH:REAL:MAX1',1)
#intervallo in millisecondi fra un campionamento e il successivo
redSampleFreq = 'RTDATA:LOG:FREQ'
redSampleFreq = 'SETTINGS:LOG:FREQ'
startingFreq = 1000
redSrv0.set(redSampleFreq,startingFreq)
@@ -45,7 +57,7 @@ try:
#funzione salva time+data di log e otto valori su redis
def redisSave(CHvalue):
redLastLog = 'RTDATA:CH:RECTIME'
redLastLog = 'RTDATA:TIME:LOG'
lastLog = datetime.datetime.now()
redSrv0.set(redLastLog,str(lastLog))
for CHcount in range(0,8,+1):
@@ -55,12 +67,12 @@ try:
#ciclo principale, salva time attuale e se LOG:STATUS è 1 fa il ciclo principale
while(1):
redTime = 'RTDATA:CH:SRVTIME'
redTime = 'RTDATA:TIME:SRV'
now = datetime.datetime.now()
redSrv0.set(redTime,str(now))
#print(logStatus)
# solo se su redis LOG è 1 eseguo il ciclo principale
logStatus = redSrv0.get('RTDATA:LOG:STATUS').decode('utf-8')
logStatus = redSrv0.get('SETTINGS:LOG:STATUS').decode('utf-8')
if logStatus == "1" :
CHvalue = CH.ADS1256_GetAll()
#videoPrint(CHvalue)
+37 -46
View File
@@ -1,7 +1,6 @@
#!/usr/bin/python
from flask import Flask, render_template, jsonify, request
#from flask_bootstrap import Bootstrap
import datetime
from flask.wrappers import Request
import redis
@@ -31,21 +30,10 @@ redSrv0 = redis.Redis(
flaskApp = Flask(__name__)
@flaskApp.route("/")
#funzione main: passa al template html i primi dati che dovranno popolarlo. legge direttamente da redis. edit: passa anche indirizzo ip del server
#funzione main: passa al template home il titolo
def main():
channelsData = {
'title' : 'Home',
'timeSrv' : redSrv0.get('RTDATA:CH:SRVTIME').decode('utf-8')
# 'timeLog' : redSrv0.get('RTDATA:CH:RECTIME').decode('utf-8'),
# 'Freq' : redSrv0.get('RTDATA:LOG:FREQ').decode('utf-8'),
# 'Ch0' : redSrv0.get('RTDATA:CH:0').decode('utf-8'),
# 'Ch1' : redSrv0.get('RTDATA:CH:1').decode('utf-8'),
# 'Ch2' : redSrv0.get('RTDATA:CH:2').decode('utf-8'),
# 'Ch3' : redSrv0.get('RTDATA:CH:3').decode('utf-8'),
# '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')
'title' : 'Home'
}
#assegno il template html di riferimento
return render_template('home.html', **channelsData)
@@ -55,9 +43,9 @@ def main():
def logger():
channelsData = {
'title' : 'Logger',
'timeSrv' : redSrv0.get('RTDATA:CH:SRVTIME').decode('utf-8'),
'timeLog' : redSrv0.get('RTDATA:CH:RECTIME').decode('utf-8'),
'Freq' : redSrv0.get('RTDATA:LOG:FREQ').decode('utf-8'),
'timeSrv' : redSrv0.get('RTDATA:TIME:SRV').decode('utf-8'),
'timeLog' : redSrv0.get('RTDATA:TIME:LOG').decode('utf-8'),
'Freq' : redSrv0.get('SETTINGS:LOG:FREQ').decode('utf-8'),
'Ch0' : redSrv0.get('RTDATA:CH:0').decode('utf-8'),
'Ch1' : redSrv0.get('RTDATA:CH:1').decode('utf-8'),
'Ch2' : redSrv0.get('RTDATA:CH:2').decode('utf-8'),
@@ -75,28 +63,16 @@ def logger():
def setup():
channelsData = {
'title' : 'Settings',
'timeSrv' : redSrv0.get('RTDATA:CH:SRVTIME').decode('utf-8'),
'timeLog' : redSrv0.get('RTDATA:CH:RECTIME').decode('utf-8'),
'Freq' : redSrv0.get('RTDATA:LOG:FREQ').decode('utf-8'),
'Ch0' : redSrv0.get('RTDATA:CH:0').decode('utf-8'),
'Ch1' : redSrv0.get('RTDATA:CH:1').decode('utf-8'),
'Ch2' : redSrv0.get('RTDATA:CH:2').decode('utf-8'),
'Ch3' : redSrv0.get('RTDATA:CH:3').decode('utf-8'),
'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')
'Freq' : redSrv0.get('SETTINGS:LOG:FREQ').decode('utf-8')
}
#assegno il template html di riferimento
return render_template('settings.html', **channelsData)
@flaskApp.route("/about")
#funzione setup, route a pagina /setup
#funzione about, route a pagina /about
def about():
channelsData = {
'title' : 'About',
'timeSrv' : redSrv0.get('RTDATA:CH:SRVTIME').decode('utf-8')
'title' : 'About'
}
#assegno il template html di riferimento
return render_template('about.html', **channelsData)
@@ -106,10 +82,9 @@ def about():
def api_channels_all():
#funzione api_channels_all: legge direttamente da redis, ritorna jsonify
channelsData = {
'title' : 'Home',
'timeSrv' : redSrv0.get('RTDATA:CH:SRVTIME').decode('utf-8'),
'timeLog' : redSrv0.get('RTDATA:CH:RECTIME').decode('utf-8'),
'Freq' : redSrv0.get('RTDATA:LOG:FREQ').decode('utf-8'),
'timeSrv' : redSrv0.get('RTDATA:TIME:SRV').decode('utf-8'),
'timeLog' : redSrv0.get('RTDATA:TIME:LOG').decode('utf-8'),
'Freq' : redSrv0.get('SETTINGS:LOG:FREQ').decode('utf-8'),
'Ch0' : redSrv0.get('RTDATA:CH:0').decode('utf-8'),
'Ch1' : redSrv0.get('RTDATA:CH:1').decode('utf-8'),
'Ch2' : redSrv0.get('RTDATA:CH:2').decode('utf-8'),
@@ -117,7 +92,11 @@ def api_channels_all():
'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'),
'ChScaleMax1' : redSrv0.get('SETTINGS:CH:SCALE:MAX1').decode('utf-8'),
'ChScaleMin1' : redSrv0.get('SETTINGS:CH:SCALE:MIN1').decode('utf-8'),
'ChRealMax1' : redSrv0.get('SETTINGS:CH:REAL:MAX1').decode('utf-8'),
'ChRealMin1' : redSrv0.get('SETTINGS:CH:REAL:MIN1').decode('utf-8')
}
# restituisce in formato json i dati letti da redis
return jsonify(channelsData)
@@ -126,13 +105,13 @@ def api_channels_all():
@flaskApp.route("/api/v1/log/start", methods=['PUT'])
def start_log():
#funzione start_log: scrive su redis LOG:STATUS -> 1
redSrv0.set('RTDATA:LOG:STATUS', 1)
redSrv0.set('SETTINGS:LOG:STATUS', 1)
return "OK"
@flaskApp.route("/api/v1/log/stop", methods=['PUT'])
def stop_log():
#funzione stop_log: scrive su redis LOG:STATUS -> 0
redSrv0.set('RTDATA:LOG:STATUS', 0)
redSrv0.set('SETTINGS:LOG:STATUS', 0)
return "OK"
@flaskApp.route("/api/v1/sessions", methods=['POST'])
@@ -147,23 +126,35 @@ def sessionCreate():
def setFrequency():
#funzione set frequenza scrive su redis LOG:FREQ prendendolo dall'input in pagina html con nome LogFreq
newFrequency = request.form['LogFreq']
redSrv0.set('RTDATA:LOG:FREQ', newFrequency)
redSrv0.set('SETTINGS:LOG:FREQ', newFrequency)
# rimando in settings
return redirect("/settings")
@flaskApp.route("/api/v1/smin1", methods=['POST'])
def setScaleMin1():
scaleMin1 = request.form['ScaleMin1']
redSrv0.set('SETTINGS:CH:SCALE:MIN1', scaleMin1)
# rimando in settings
return redirect("/settings")
@flaskApp.route("/api/v1/smax1", methods=['POST'])
def setScaleMax1():
scaleMax1 = request.form['ScaleMax1']
redSrv0.set('SETTINGS:CH:SCALE:MAX1', scaleMax1)
# rimando in settings
return redirect("/settings")
@flaskApp.route("/api/v1/rmin1", methods=['POST'])
def setRealMin1():
#funzione set frequenza scrive su redis LOG:FREQ prendendolo dall'input in pagina html con nome LogFreq
realMin1 = request.form['MinReal1']
redSrv0.set('RTDATA:SET:RMIN1', realMin1)
realMin1 = redSrv0.get('RTDATA:CH:0')
redSrv0.set('SETTINGS:CH:REAL:MIN1', realMin1)
# rimando in settings
return redirect("/settings")
@flaskApp.route("/api/v1/rmax1", methods=['POST'])
def setRealMax1():
#funzione set frequenza scrive su redis LOG:FREQ prendendolo dall'input in pagina html con nome LogFreq
realMax1 = request.form['MaxReal1']
redSrv0.set('RTDATA:SET:RMAX1', realMax1)
realMax1 = redSrv0.get('RTDATA:CH:0')
redSrv0.set('SETTINGS:CH:REAL:MAX1', realMax1)
# rimando in settings
return redirect("/settings")
+22
View File
@@ -2,6 +2,28 @@
{% block content %}
<main>
<script>
var intTime=1000;
// fix visualizzazioni
fixDisplay();
// avvio timer
var timeout = setTimeout(dataRefresh, intTime);
function fixDisplay(){
$("#divNewFile").toggle();
}
function dataRefresh() {
// scarico data e ora
$.ajax({url: "/api/v1/channels/all", success: function(result){
// compilo i dati scaricati
$("#ServerTime").html(result.timeSrv);
}});
timeout = setTimeout(dataRefresh, intTime);
}
</script>
<div class="container-fluid py-2">
<div class="card mb-4">
<div class="card-header">
+20
View File
@@ -2,6 +2,26 @@
{% block content %}
<main>
<script>
var intTime=1000;
// fix visualizzazioni
fixDisplay();
// avvio timer
var timeout = setTimeout(dataRefresh, intTime);
function fixDisplay(){
$("#divNewFile").toggle();
} function dataRefresh() {
// scarico i dati aggioranti
$.ajax({url: "/api/v1/channels/all", success: function(result){
// compilo i dati scaricati
$("#ServerTime").html(result.timeSrv);
}});
timeout = setTimeout(dataRefresh, intTime);
}
</script>
<div class="container-fluid py-2">
<div class="row">
<div class="col-12">
+24 -64
View File
@@ -14,72 +14,32 @@
<script src="../static/js/bootstrap.bundle.min.js"></script>
</head>
<body class="sb-nav-fixed">
<script>
<script>
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);
}});
// var intTime=250;
// // fix visualizzazioni
// fixDisplay();
// // avvio timer
// var timeout = setTimeout(dataRefresh, intTime);
// function fixDisplay(){
// $("#divNewFile").toggle();
// //console.log("div hidden");
// }
// 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);
// $("#ServerTime").html(result.timeSrv);
// $("#LoggerTime").html(result.timeLog);
// //console.log(result);
// }});
// timeout = setTimeout(dataRefresh, intTime);
// }
function startLog(){
$.ajax({
type: 'PUT'
,url: "/api/v1/log/start"
,data: ""
,success: function(){
alert('Log Started');
}
})
intTime= 250;
};
function stopLog(){
$.ajax({
type: 'PUT'
,url: "/api/v1/log/stop"
,data: ""
,success: function(){
alert('Log Stopped');
}
})
intTime = 2500;
};
// 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);
}
</script>
</script>
<nav class="navbar navbar-expand-md bg-dark navbar-dark">
<!-- Brand -->
<a class="navbar-brand" href="/">ANALOGGER</a>
+39 -3
View File
@@ -11,9 +11,8 @@
function fixDisplay(){
$("#divNewFile").toggle();
//console.log("div hidden");
}
function dataRefresh() {
function dataRefresh() {
// scarico i dati aggioranti
$.ajax({url: "/api/v1/channels/all", success: function(result){
// compilo i dati scaricati
@@ -27,10 +26,47 @@
$("#Chan7").html(result.Ch7);
$("#LogFrequency").html(result.Freq);
$("#LoggerTime").html(result.timeLog);
//console.log(result);
$("#ServerTime").html(result.timeSrv);
$("#ChanScaleMin1").html(result.ChScaleMin1);
$("#ChanScaleMax1").html(result.ChScaleMax1);
$("#ChanRealMin1").html(result.ChRealMin1);
$("#ChanRealMax1").html(result.ChRealMax1);
}});
timeout = setTimeout(dataRefresh, intTime);
}
function startLog(){
$.ajax({
type: 'PUT'
,url: "/api/v1/log/start"
,data: ""
,success: function(){
alert('Log Started');
}
})
intTime= 200;
};
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">
+49 -19
View File
@@ -2,6 +2,42 @@
{% block content %}
<main>
<script>
var intTime=1000;
// fix visualizzazioni
fixDisplay();
// avvio timer
var timeout = setTimeout(dataRefresh, intTime);
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);
}});
timeout = setTimeout(dataRefresh, intTime);
}
</script>
<div class="container-fluid py-2">
<div class="card mb-4">
<div class="card-header">
@@ -11,7 +47,7 @@
<div class="row" id="setFrequency">
<form class="col-12" method="POST" action="/api/v1/frequency">
<div class="input-group">
<span class="input-group-text">Periodo di campionamento (ms)</span>
<span class="input-group-text">Periodo di campionamento (ms): &nbsp; <span id="LogFrequency"></span></span>
<input type="number" class="form-control" id="LogFreq" name="LogFreq"></input>
<div class="input-group-append">
<input type="submit" value="SET" class="btn btn-success"></input>
@@ -27,17 +63,15 @@
</div>
<div class="card-body">
<div class="row">
<div class="col-2 alert alert-info text-center">
Valori Reali
<div class="col-2 input-group mb-3 input-group-text">
<strong>Valori reali (current:&nbsp;<span id="Chan0"></span> ) </strong>
</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>
<button type="button" style="text-align: right;" class="btn btn-primary" onclick="">Get current</button>
<input type="float" class="form-control" id="MinReal1" name="MinReal1"></input>
<span class="input-group-text">Min: &nbsp; <span id="ChanRealMin1"></span></span>
<div class="input-group-append">
<input type="submit" value="SET" class="btn btn-success"></input>
<input type="submit" value="SET MIN" class="btn btn-success"></input>
</div>
</div>
</form>
@@ -45,26 +79,23 @@
<div class="col-5">
<form method="POST" action="/api/v1/rmax1">
<div class="input-group mb-3">
<span class="input-group-text">Max</span>
<button type="button" style="text-align: right;" class="btn btn-primary" onclick="">Get current</button>
<input type="float" class="form-control" id="MaxReal1" name="MaxReal1"></input>
<span class="input-group-text">Max: &nbsp; <span id="ChanRealMax1"></span></span>
<div class="input-group-append">
<input type="submit" value="SET" class="btn btn-success"></input>
<input type="submit" value="SET MAX" class="btn btn-success"></input>
</div>
</div>
</form>
</div>
</div>
<div class="row">
<div class="col-2 alert alert-info text-center">
Valori Scalati
<div class="col-2 input-group mb-3 input-group-text">
<strong>Fattori di scala</strong>
</div>
<div class="col-5">
<form method="POST" action="/api/v1/smin1">
<div class="input-group mb-3">
<span class="input-group-text">Min</span>
<button type="button" style="text-align: right;" class="btn btn-primary" onclick="">Get current</button>
<input type="number" class="form-control" id="MinScaled1" name="MinScaled1"></input>
<span class="input-group-text">Min: &nbsp; <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>
@@ -74,9 +105,8 @@
<div class="col-5">
<form method="POST" action="/api/v1/smax1">
<div class="input-group mb-3">
<span class="input-group-text">Max</span>
<button type="button" style="text-align: right;" class="btn btn-primary" onclick="">Get current</button>
<input type="number" class="form-control" id="MaxScaled1" name="MaxScaled1"></input>
<span class="input-group-text">Max: &nbsp; <span id="ChanScaleMax1"></span></span>
<input type="number" class="form-control" id="caleMax1" name="ScaleMax1"></input>
<div class="input-group-append">
<input type="submit" value="SET" class="btn btn-success"></input>
</div>