X-Git-Url: https://git.realraum.at/?a=blobdiff_plain;f=sensor_graph%2Fsample_sensor.lua;fp=sensor_graph%2Fsample_sensor.lua;h=31cdfc3b2cbb49dfe2bbc57381cf0fff780d7e46;hb=3b1d42bd8a6816e8e0aa9345f62ecb3c1b1c864a;hp=8f5f19316c3081d0654d9f1e9b5350d588a9a857;hpb=6c2af2c9c5122b663be6c92d4804497e4a926377;p=svn42.git diff --git a/sensor_graph/sample_sensor.lua b/sensor_graph/sample_sensor.lua index 8f5f193..31cdfc3 100755 --- a/sensor_graph/sample_sensor.lua +++ b/sensor_graph/sample_sensor.lua @@ -1,55 +1,28 @@ #!/usr/bin/lua require('os') require('string') -require('socket') - -last_movement = 0 - -function save_values() - os.execute(string.format("rrdtool update /home/sensordata.rrd -t temp:light:movement N:%f:%d:%d", last_temp, last_light, last_movement)) - last_movement=0 -end - +require('io') function parse_value(str) last_temp = 0.0 last_light = 0 - if string.find(str,"Sensor T: Temp C:") then - last_temp = tonumber(string.sub(str,18)) - os.execute(string.format("rrdtool update /home/sensordata.rrd -t temp N:%f", last_temp)) - print(string.format("t: %f Grad Celsius",last_temp)) - end - if string.find(str,"Sensor P: Photo:") then - last_light = tonumber(string.sub(str,17)) - os.execute(string.format("rrdtool update /home/sensordata.rrd -t light N:%d", last_light)) - print(string.format("p: %d",last_light)) + if string.find(str,"temp0: Temp C:") then + last_temp = tonumber(string.sub(str,15)) + os.execute(string.format("rrdtool update /home/sensortemp.rrd -t temp N:%f", last_temp)) + --print(string.format("t: %f Grad Celsius",last_temp)) end - if string.find(str,"movement") then - --last_movement=1 - os.execute(string.format("rrdtool update /home/sensordata.rrd -t movement N:%d", 1)) + if string.find(str,"photo0: Photo:") then + last_light = tonumber(string.sub(str,15)) + os.execute(string.format("rrdtool update /home/sensorlight.rrd -t light N:%d", last_light)) + --print(string.format("p: %d",last_light)) end end - -local socket_factory = require("socket.unix"); -local socket = socket_factory() - - while 1 do - local client = socket.connect("/var/run/powersensordaemon/cmd.sock") - if client then - client:send("listen sensor\n") - --client:settimeout(30) - while 1 do - local line, err = client:receive() - if not err then - parse_value(line) - elseif err ~= "timeout" then - break - end + local line = io.read("*line") + if line then + parse_value(line) + else + break end - client:shutdown("both") - end - --wait 10 seconds - socket.select(nil, nil, 10) end