1
0
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:
mvoelkel 2015-09-24 16:20:44 +02:00
parent 6e39d759fe
commit fb0aab674e
3 changed files with 65 additions and 28 deletions

View File

@ -71,6 +71,13 @@ for i = 0,4,1 do
NumSensors = NumSensors + 1 NumSensors = NumSensors + 1
end end
end end
local fh = io.open(LogFile,"w")
if fh then
fh:write(NumSensors..","..interval..","..fanstate.."\n")
fh:close()
end
if NumSensors == 0 then if NumSensors == 0 then
return return
end end
@ -116,7 +123,7 @@ while true do
TmpLogFile = os.tmpname() TmpLogFile = os.tmpname()
local fh = io.open(TmpLogFile,"w") fh = io.open(TmpLogFile,"w")
if fh then if fh then
fh:write(NumSensors..","..interval..","..fanstate.."\n") fh:write(NumSensors..","..interval..","..fanstate.."\n")
@ -135,4 +142,3 @@ while true do
end end
collectgarbage() collectgarbage()
end end

View File

@ -13,9 +13,14 @@
var xmlhttp = new XMLHttpRequest(); var xmlhttp = new XMLHttpRequest();
var url = "/monitor.lua"; var url = "/monitor.lua";
xmlhttp.onreadystatechange=function() { xmlhttp.onreadystatechange=function()
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) { {
myFunction(xmlhttp.responseText); 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) { function myFunction(response) {
var Sensor = JSON.parse(response); var Sensor = JSON.parse(response);
var j;
if( Sensor.NumSensors > 0 ) if( Sensor.NumSensors > 0 )
{ {
var pts = document.getElementById("pts").points; if( Sensor.NumSensors > 4 ) Sensor.NumSensors = 4;
var svgRoot = document.getElementById("svg"); for( j = 0; j < Sensor.NumSensors; j += 1 )
var i;
var v = Sensor.SensorData[0];
var n = v.length;
var i0 = 0;
if( n > 120 )
{ {
i0 = n - 120; var id = "pts"+j
n = 120; var pts = document.getElementById(id).points;
} var svgRoot = document.getElementById("svg");
pts.clear();
for(i = 0; i < n; i += 1) var i;
{ var v = Sensor.SensorData[j];
var pt = svgRoot.createSVGPoint(); var n = v.length;
pt.x = (i+1) * 20; var i0 = 0;
pt.y = v[i+i0] * 10; if( n > 120 )
pts.appendItem(pt); {
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); window.setTimeout(Reload,10000);
} }
else
{
document.getElementById("TGraph").style.display = "none";
document.getElementById("NoSensor").style.display = "block";
}
} }
@ -91,9 +107,13 @@ function OnLoad()
</table> </table>
--> -->
<h3 align="center">Frontend Temperature</h3> <h3 align="center">Frontend Temperature</h3>
<div id="NoSensor" align="center" style="display: none">
</p>
No temperature sensors available
</div>
<div id="TGraph" align="center" style="display: block">
<div align="center">
<svg Id="svg" width="720px" height="330px"> <svg Id="svg" width="720px" height="330px">
<desc>Temperature</desc> <desc>Temperature</desc>
<g transform="scale(0.277)"> <g transform="scale(0.277)">
@ -147,9 +167,18 @@ function OnLoad()
</g> </g>
<svg x="100" y="100" width="2400" height="1000"> <svg x="100" y="100" width="2400" height="1000">
<g transform="scale(1.0,-1.0) translate(0.0,-1000)"> <g transform="scale(1.0,-1.0) translate(0.0,-1000)">
<polyline Id="pts" <polyline Id="pts0"
points="0 0," 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> </g>
</svg> </svg>
</g> </g>

View File

@ -43,6 +43,7 @@ end
if method == "GET" then if method == "GET" then
data = "" data = ""
status = " 204"
local file = io.open("/tmp/Temperatur.log") local file = io.open("/tmp/Temperatur.log")
if file then if file then
@ -84,10 +85,11 @@ if method == "GET" then
end end
data = data .. "]\n" data = data .. "]\n"
data = data .. "}\n" data = data .. "}\n"
status = "200"
end end
http_print(proto.." 200" ) http_print(proto.." "..status )
http_print("Pragma: no-cache") http_print("Pragma: no-cache")
http_print("Content-Type: application/json; charset=UTF-8") http_print("Content-Type: application/json; charset=UTF-8")
http_print(string.format("Content-Length: %d",#data)) http_print(string.format("Content-Length: %d",#data))