dati originali e scalati in 2 array

This commit is contained in:
Marco Locatelli
2021-04-02 12:15:50 +02:00
parent 6a316d87da
commit 8cdc0938bd
5 changed files with 188 additions and 158 deletions
+1
View File
@@ -83,3 +83,4 @@
2021-04-01 15:20:07.442727 Caught error: name 'now' is not defined
2021-04-01 15:20:08.570454 Caught error: name 'now' is not defined
2021-04-01 15:21:11.244154 Caught error: name 'now' is not defined
2021-04-02 09:27:42.781175 Caught error: Connection closed by server.
+24 -62
View File
@@ -4,22 +4,9 @@ from flask import Flask, render_template, jsonify, request
from datetime import datetime
from flask.wrappers import Request
import redis
#import socket
import os
from werkzeug.utils import redirect
# RIVEDERE: fare un ciclo di 10 tentativi, pausa 3 sec, prima di uscire se non andasse, che così fatto come servizio si pianta
#create a socket object
#s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
#connect to the server on local computer
#s.connect(("8.8.8.8", 80))
#assegno a variabile indirizzo ip per usi futuri
#ipv4 = s.getsocketname()[0]
#s.close()
#volendo stampo a video IPv4
#print("Indirizzo Ipv4 assegnato: ",s.getsockname()[0])
#assegno ipv4 statico
ipv4 = '10.74.83.210'
@@ -54,22 +41,6 @@ def logger():
'timeLog' : getRedisVal('RTDATA:TIME:LOG'),
'LogFreq' : getRedisVal('SETTINGS:LOG:FREQ'),
'WriteFreq' : getRedisVal('SETTINGS:WRITE:FREQ'),
'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('logger.html', **channelsData)
@@ -81,22 +52,6 @@ def setup():
'title' : 'Settings',
'LogFreq' : getRedisVal('SETTINGS:LOG:FREQ'),
'WriteFreq' : getRedisVal('SETTINGS:WRITE:FREQ'),
'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)
@@ -115,28 +70,23 @@ def about():
def api_channels_all():
numCh = getRedisVal('SETTINGS:SELECTED_CH')
#funzione api_channels_all: legge direttamente da redis, ritorna jsonify
CH = [0,0,0,0,0,0,0,0]
OUT = [0,0,0,0,0,0,0,0]
for numCh in range(0,8,+1):
CH[numCh] = getRedisVal('RTDATA:CH:'+str(numCh))
OUT[numCh] = getRedisVal('RTDATA:OUT:'+str(numCh))
channelsData = {
'timeSrv' : getRedisVal('RTDATA:TIME:SRV'),
'timeLog' : getRedisVal('RTDATA:TIME:LOG'),
'LogFreq' : getRedisVal('SETTINGS:LOG:FREQ'),
'WriteFreq' : getRedisVal('SETTINGS:WRITE:FREQ'),
'Status' : getRedisVal('SETTINGS:LOG:STATUS'),
'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'),
'Channels': CH,
'Outs': OUT,
'ChA' : getRedisVal('SETTINGS:CHANNEL:A'),
'ChB' : getRedisVal('SETTINGS:CHANNEL:B'),
'ChScaleMax' : getRedisVal('SETTINGS:IN:MAX:'+str(numCh)),
'ChScaleMin' : getRedisVal('SETTINGS:IN:MIN:'+str(numCh)),
'ChRealMax' : getRedisVal('SETTINGS:OUT:MAX:'+str(numCh)),
@@ -214,8 +164,20 @@ def setupInMax():
redSrv0.set('SETTINGS:IN:MAX:'+ str(indCh), currChVal)
return redirect("/settings")
@flaskApp.route("/api/v1/setup/selectChannelA/<numChA>", methods=['PUT'])
def selectChannelA(numChA):
print(numChA)
redSrv0.set('SETTINGS:CHANNEL:A', numChA)
return "OK"
@flaskApp.route("/api/v1/setup/selectChannelB/<numChB>", methods=['PUT'])
def selectChannelB(numChB):
print(numChB)
redSrv0.set('SETTINGS:CHANNEL:B', numChB)
return "OK"
@flaskApp.route("/api/v1/setup/selectChannel/<numCh>", methods=['PUT'])
def selectChannel(numCh):
def setChannel(numCh):
print(numCh)
# request_data = request.get_json()
# # devo leggere il channel attualmente selezionato, x ora cablo a 0...
+2 -2
View File
@@ -19,11 +19,11 @@
<p>Analog and Digital reader and logger software</p>
</div>
<div class="row">
<p>Version 0.1.1</p>
<p>Version 0.2.1</p>
</div>
<div class="row">
<p>Last Patched:<br>
23 March 2021</p>
02/04/2021</p>
</div>
</div>
</div>
+36 -56
View File
@@ -13,11 +13,9 @@
$("#divNewFile").toggle();
};
function setGauges(chVal0,chVal1){
// Create knob elements, 300 x 300 px in size.
function setGaugeA(chVal0){
// Create knob elements
const knob0 = pureknob.createKnob(200, 200);
const knob1 = pureknob.createKnob(200, 200);
// Set properties knob0
knob0.setProperty('angleStart', -0.8 * Math.PI);
knob0.setProperty('angleEnd', 0.8 * Math.PI);
@@ -25,7 +23,17 @@
knob0.setProperty('trackWidth', 0.3);
knob0.setProperty('valMin', 0);
knob0.setProperty('valMax', 100);
// Set initial value0
knob0.setValue(chVal0);
// Create element node0
const node0 = knob0.node();
// Add it to the DOM.
$("#divChA").html(node0);
}
function setGaugeB(chVal1){
// Create knob elements
const knob1 = pureknob.createKnob(200, 200);
// Set properties knob1
knob1.setProperty('angleStart', -0.8 * Math.PI);
knob1.setProperty('angleEnd', 0.8 * Math.PI);
@@ -33,59 +41,33 @@
knob1.setProperty('trackWidth', 0.3);
knob1.setProperty('valMin', 0);
knob1.setProperty('valMax', 100);
// Set initial value0
knob0.setValue(chVal0);
// Create element node0
const node0 = knob0.node();
// Set initial value1
knob1.setValue(chVal1);
// Create element node1
const node1 = knob1.node();
// Add it to the DOM.
$("#divCh0").html(node0);
$("#divCh1").html(node1);
// $("#divCh0").val(node);
// $("#divCh0").val(node);
//$("#divCh0").append(node);
// const elem0 = document.getElementById('divCh0');
// elem0.appendChild(node);
// const elem1 = document.getElementById('divCh1');
// elem1.appendChild(node);
$("#divChB").html(node1);
}
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);
$("#Output0").html(result.Out0);
$("#Output1").html(result.Out1);
$("#Output2").html(result.Out2);
$("#Output3").html(result.Out3);
$("#Output4").html(result.Out4);
$("#Output5").html(result.Out5);
$("#Output6").html(result.Out6);
$("#Output7").html(result.Out7);
$("#SelChannelA").html(result.ChA);
$("#ChannelA").html(result.Channels[result.ChA]);
$("#OutputA").html(result.Outs[result.ChA]);
setGaugeA(result.Outs[result.ChA]);
$("#SelChannelB").html(result.ChB);
$("#ChannelB").html(result.Channels[result.ChB]);
$("#OutputB").html(result.Outs[result.ChB]);
setGaugeB(result.Outs[result.ChB]);
$("#LogFrequency").html(result.LogFreq);
$("#WriteFrequency").html(result.WriteFreq);
$("#LoggerTime").html(result.timeLog);
$("#ServerTime").html(result.timeSrv);
$("#ChanScaleMin").html(result.ChScaleMin);
$("#ChanScaleMax").html(result.ChScaleMax);
$("#ChanRealMin").html(result.ChRealMin);
$("#ChanRealMax").html(result.ChRealMax);
$("#LastSessionName").html(result.LastSessionName);
setGauges(result.Out0,result.Out1);
}});
timeout = setTimeout(dataRefresh, intTime);
@@ -110,31 +92,29 @@
};
</script>
<div class="container-fluid text-center">
<div class="container-fluid">
<div class="row mx-2 my-2">
<div class="card col-6">
<div class="card-header">
<i class="fas fa-table mr-1"></i>
<strong>Channel A</strong>
<div class="card text-center col-6">
<div class="card-header text-center">
<strong>Channel A: <span id="SelChannelA"></span></strong>
</div>
<div class="card-body">
<div id="divCh0"></div>
Original: <span id="Chan0"></span>
<div id="divChA"></div>
Original: <span id="ChannelA"></span>
<br>
<strong>Scaled: <span id="Output0"></span>
<strong>Scaled: <span id="OutputA"></span>
</strong>
</div>
</div>
<div class="card col-6">
<div class="card-header">
<i class="fas fa-table mr-1"></i>
<strong>Channel B</strong>
<div class="card text-center col-6">
<div class="card-header text-center">
<strong>Channel B: <span id="SelChannelB"></span></strong>
</div>
<div class="card-body">
<div id="divCh1"></div>
Original: <span id="Chan1"></span>
<div id="divChB"></div>
Original: <span id="ChannelB"></span>
<br>
<strong>Scaled: <span id="Output1"></span>
<strong>Scaled: <span id="OutputB"></span>
</strong>
</div>
</div>
+125 -38
View File
@@ -5,6 +5,8 @@
<script type="text/javascript">
var intTime=200;
refreshInput();
var timeout = setTimeout(dataRefresh, intTime);
var timeoutSetting = setTimeout(refreshSettings, intTime);
// carico la prima volta i dati
function refreshInput() {
@@ -25,21 +27,14 @@
}});
}
// 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);
// $("#LogFreq").html(result.logFreq);
// $("#WriteFreq").html(result.writeFreq);
$("#LoggerTime").html(result.timeLog);
$("#ServerTime").html(result.timeSrv);
// $("#MinOut").val(result.MinOut);
// $("#MaxOut").val(result.MaxOut);
$("#MinIn").html(result.MinIn);
$("#MaxIn").html(result.MaxIn);
}});
@@ -47,6 +42,32 @@
timeoutSetting = setTimeout(refreshSettings, intTime);
}
function dataRefresh() {
// scarico i dati aggioranti
$.ajax({url: "/api/v1/channels/all", success: function(result){
$("#SelChannelA").val(result.ChA);
$("#ChannelA").html(result.Channels[result.ChA]);
$("#OutputA").html(result.Outs[result.ChA]);
$("#SelChannelB").val(result.ChB);
$("#ChannelB").html(result.Channels[result.ChB]);
$("#OutputB").html(result.Outs[result.ChB]);
$("#LogFrequency").html(result.LogFreq);
$("#WriteFrequency").html(result.WriteFreq);
$("#LoggerTime").html(result.timeLog);
$("#ServerTime").html(result.timeSrv);
$("#ChanScaleMin").html(result.ChScaleMin);
$("#ChanScaleMax").html(result.ChScaleMax);
$("#ChanRealMin").html(result.ChRealMin);
$("#ChanRealMax").html(result.ChRealMax);
$("#LastSessionName").html(result.LastSessionName);
}});
timeout = setTimeout(dataRefresh, intTime);
};
function saveMin(){
$.ajax({
type: 'PUT'
@@ -69,52 +90,92 @@
})
};
// function resetSettings(){
// $.ajax({
// type: 'PUT'
// ,url: "/api/v1/setup/resetSettings"
// ,data: ""
// ,success: function(){
// alert('Settings Resetted');
// }
// })
// };
function setChannelA(ddlChannelA) {
var selectedText = ddlChannelA.options[ddlChannelA.selectedIndex].innerHTML;
var selectedValue = ddlChannelA.value;
$.ajax({
type: 'PUT'
,url: "/api/v1/setup/selectChannelA/" + ddlChannelA.value
,data: ""
});
};
function setChannelB(ddlChannelB) {
var selectedText = ddlChannelB.options[ddlChannelB.selectedIndex].innerHTML;
var selectedValue = ddlChannelB.value;
$.ajax({
type: 'PUT'
,url: "/api/v1/setup/selectChannelB/" + ddlChannelB.value
,data: ""
});
};
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 class="container-fluid py-2">
<div class="card mb-4">
<div class="card-header">
<i class="fas fa-table mr-1"></i>
<strong>Impostazioni Timer</strong>
<div class="container-fluid">
<div class="row mx-1 my-2">
<div class="card col-6">
<div class="row card-header">
<div class="col-6">
<strong>Channel A</strong>
</div>
<div class="col-6">
<div class="form-group">
<select class="form-control" id="SelChannelA" onchange="setChannelA(this)">
<option>0</option>
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
<option>5</option>
<option>6</option>
<option>7</option>
</select>
</div>
</div>
</div>
<div class="card-body text-center">
Original: <span id="ChannelA"></span>
<br>
<strong>Scaled: <span id="OutputA"></span>
</strong>
</div>
</div>
<div class="card-body row">
<form class="col-12" method="POST" action="/api/v1/frequency">
<div class="input-group my-2">
<span class="col-8 input-group-text">Periodo di campionamento (ms): &nbsp;</span>
<input type="number" class="col-4 form-control" id="LogFreq" name="LogFreq"></input>
<div class="card col-6">
<div class="row card-header">
<div class="col-6">
<strong>Channel B</strong>
</div>
<div class="input-group my-2">
<span class="col-8 input-group-text">Periodo di scrittura (ms): &nbsp;</span>
<input type="number" class="col-4 form-control" id="WriteFreq" name="WriteFreq"></input>
<br>
<input type="submit" value="SET" class="btn btn-success btn-block my-2"></input>
<div class="col-6">
<div class="form-group">
<select class="form-control" id="SelChannelB" onchange="setChannelB(this)">
<option>0</option>
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
<option>5</option>
<option>6</option>
<option>7</option>
</select>
</div>
</div>
</form>
</div>
<div class="card-body text-center">
Original: <span id="ChannelB"></span>
<br>
<strong>Scaled: <span id="OutputB"></span>
</strong>
</div>
</div>
</div>
<div class="card mb-4">
@@ -132,6 +193,12 @@
<select class="form-control" id="ddlChannels" onchange="setChannel(this)">
<option>0</option>
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
<option>5</option>
<option>6</option>
<option>7</option>
</select>
</div>
</div>
@@ -203,6 +270,26 @@
</div>
</h5>
</div>
<div class="card mb-4">
<div class="card-header">
<i class="fas fa-table mr-1"></i>
<strong>Impostazioni Timer</strong>
</div>
<div class="card-body row">
<form class="col-12" method="POST" action="/api/v1/frequency">
<div class="input-group my-2">
<span class="col-8 input-group-text">Periodo di campionamento (ms): &nbsp;</span>
<input type="number" class="col-4 form-control" id="LogFreq" name="LogFreq"></input>
</div>
<div class="input-group my-2">
<span class="col-8 input-group-text">Periodo di scrittura (ms): &nbsp;</span>
<input type="number" class="col-4 form-control" id="WriteFreq" name="WriteFreq"></input>
<br>
<input type="submit" value="SET" class="btn btn-success btn-block my-2"></input>
</div>
</form>
</div>
</div>
<div class="card my-2">
<div class="card-header">
<i class="fas fa-table mr-1"></i>