works. todo: separate script that adds up movements
[svn42.git] / sensor_graph / sample_sensor3.lua
1 #!/usr/bin/lua
2 require('os')
3 require('string')
4 require('io')
5 --require('socket')
6
7 function parse_value(str)
8   last_temp = 0.0
9   last_light = 0
10   if string.find(str,"temp0: Temp C:") then
11     last_temp = tonumber(string.sub(str,15))
12     os.execute(string.format("rrdtool update /home/sensortemp.rrd -t temp N:%f", last_temp))
13     --print(string.format("t: %f Grad Celsius",last_temp))
14   end
15   if string.find(str,"photo0: Photo:") then
16     last_light = tonumber(string.sub(str,15))
17     os.execute(string.format("rrdtool update /home/sensorlight.rrd -t light N:%d", last_light))
18     --print(string.format("p: %d",last_light))
19   end
20   if string.find(str,"movement") then
21     --last_movement=1
22     os.execute(string.format("rrdtool update /home/sensormovement.rrd -t movement N:%d", 1))
23   end
24 end
25
26
27
28 while 1 do
29    local line = io.read("*line")
30     if line then 
31       parse_value(line) 
32     else
33       break
34     end
35 end