mirror of
https://github.com/DigitalDevices/octonet.git
synced 2023-10-10 13:36:52 +02:00
Temperature monitor
up to 4 sensors display if there is no sensor available fixed a race condition
This commit is contained in:
parent
6e39d759fe
commit
fb0aab674e
@ -71,6 +71,13 @@ for i = 0,4,1 do
|
||||
NumSensors = NumSensors + 1
|
||||
end
|
||||
end
|
||||
|
||||
local fh = io.open(LogFile,"w")
|
||||
if fh then
|
||||
fh:write(NumSensors..","..interval..","..fanstate.."\n")
|
||||
fh:close()
|
||||
end
|
||||
|
||||
if NumSensors == 0 then
|
||||
return
|
||||
end
|
||||
@ -116,7 +123,7 @@ while true do
|
||||
|
||||
TmpLogFile = os.tmpname()
|
||||
|
||||
local fh = io.open(TmpLogFile,"w")
|
||||
fh = io.open(TmpLogFile,"w")
|
||||
if fh then
|
||||
fh:write(NumSensors..","..interval..","..fanstate.."\n")
|
||||
|
||||
@ -135,4 +142,3 @@ while true do
|
||||
end
|
||||
collectgarbage()
|
||||
end
|
||||
|
||||
|
@ -13,9 +13,14 @@
|
||||
var xmlhttp = new XMLHttpRequest();
|
||||
var url = "/monitor.lua";
|
||||
|
||||
xmlhttp.onreadystatechange=function() {
|
||||
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
|
||||
myFunction(xmlhttp.responseText);
|
||||
xmlhttp.onreadystatechange=function()
|
||||
{
|
||||
if (xmlhttp.readyState == 4 )
|
||||
{
|
||||
if( xmlhttp.status == 200 )
|
||||
myFunction(xmlhttp.responseText);
|
||||
else if( xmlhttp.status == 204 )
|
||||
window.setTimeout(Reload,1000);
|
||||
}
|
||||
}
|
||||
|
||||
@ -27,31 +32,42 @@ function Reload()
|
||||
|
||||
function myFunction(response) {
|
||||
var Sensor = JSON.parse(response);
|
||||
var j;
|
||||
|
||||
if( Sensor.NumSensors > 0 )
|
||||
{
|
||||
var pts = document.getElementById("pts").points;
|
||||
var svgRoot = document.getElementById("svg");
|
||||
|
||||
var i;
|
||||
var v = Sensor.SensorData[0];
|
||||
var n = v.length;
|
||||
var i0 = 0;
|
||||
if( n > 120 )
|
||||
if( Sensor.NumSensors > 4 ) Sensor.NumSensors = 4;
|
||||
for( j = 0; j < Sensor.NumSensors; j += 1 )
|
||||
{
|
||||
i0 = n - 120;
|
||||
n = 120;
|
||||
}
|
||||
pts.clear();
|
||||
for(i = 0; i < n; i += 1)
|
||||
{
|
||||
var pt = svgRoot.createSVGPoint();
|
||||
pt.x = (i+1) * 20;
|
||||
pt.y = v[i+i0] * 10;
|
||||
pts.appendItem(pt);
|
||||
var id = "pts"+j
|
||||
var pts = document.getElementById(id).points;
|
||||
var svgRoot = document.getElementById("svg");
|
||||
|
||||
var i;
|
||||
var v = Sensor.SensorData[j];
|
||||
var n = v.length;
|
||||
var i0 = 0;
|
||||
if( n > 120 )
|
||||
{
|
||||
i0 = n - 120;
|
||||
n = 120;
|
||||
}
|
||||
pts.clear();
|
||||
for(i = 0; i < n; i += 1)
|
||||
{
|
||||
var pt = svgRoot.createSVGPoint();
|
||||
pt.x = (i+1) * 20;
|
||||
pt.y = v[i+i0] * 10;
|
||||
pts.appendItem(pt);
|
||||
}
|
||||
}
|
||||
window.setTimeout(Reload,10000);
|
||||
}
|
||||
else
|
||||
{
|
||||
document.getElementById("TGraph").style.display = "none";
|
||||
document.getElementById("NoSensor").style.display = "block";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -91,9 +107,13 @@ function OnLoad()
|
||||
</table>
|
||||
-->
|
||||
<h3 align="center">Frontend Temperature</h3>
|
||||
<div id="NoSensor" align="center" style="display: none">
|
||||
</p>
|
||||
No temperature sensors available
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
<div align="center">
|
||||
<div id="TGraph" align="center" style="display: block">
|
||||
<svg Id="svg" width="720px" height="330px">
|
||||
<desc>Temperature</desc>
|
||||
<g transform="scale(0.277)">
|
||||
@ -147,9 +167,18 @@ function OnLoad()
|
||||
</g>
|
||||
<svg x="100" y="100" width="2400" height="1000">
|
||||
<g transform="scale(1.0,-1.0) translate(0.0,-1000)">
|
||||
<polyline Id="pts"
|
||||
<polyline Id="pts0"
|
||||
points="0 0,"
|
||||
style="stroke:red; stroke-width: 3; fill : none;"/>
|
||||
style="stroke:#C00000; stroke-width: 3; fill : none;"/>
|
||||
<polyline Id="pts1"
|
||||
points="0 0,"
|
||||
style="stroke:#0000C0; stroke-width: 3; fill : none;"/>
|
||||
<polyline Id="pts2"
|
||||
points="0 0,"
|
||||
style="stroke:#00C000; stroke-width: 3; fill : none;"/>
|
||||
<polyline Id="pts3"
|
||||
points="0 0,"
|
||||
style="stroke:#C000C0; stroke-width: 3; fill : none;"/>
|
||||
</g>
|
||||
</svg>
|
||||
</g>
|
||||
|
@ -43,6 +43,7 @@ end
|
||||
|
||||
if method == "GET" then
|
||||
data = ""
|
||||
status = " 204"
|
||||
|
||||
local file = io.open("/tmp/Temperatur.log")
|
||||
if file then
|
||||
@ -84,10 +85,11 @@ if method == "GET" then
|
||||
end
|
||||
data = data .. "]\n"
|
||||
data = data .. "}\n"
|
||||
status = "200"
|
||||
end
|
||||
|
||||
|
||||
http_print(proto.." 200" )
|
||||
http_print(proto.." "..status )
|
||||
http_print("Pragma: no-cache")
|
||||
http_print("Content-Type: application/json; charset=UTF-8")
|
||||
http_print(string.format("Content-Length: %d",#data))
|
||||
|
Loading…
x
Reference in New Issue
Block a user