sensor sampling mit socket
authorBernhard Tittelbach <xro@realraum.at>
Thu, 18 Mar 2010 21:19:26 +0000 (21:19 +0000)
committerBernhard Tittelbach <xro@realraum.at>
Thu, 18 Mar 2010 21:19:26 +0000 (21:19 +0000)
sensor_graph/rrdtool.sh
sensor_graph/sample_sensor3.lua [new file with mode: 0755]
sensor_graph/sensors.cgi

index 1efcac4..374686a 100644 (file)
@@ -1,4 +1,6 @@
-rrdtool create sensordata.rrd --step 30 DS:temp:GAUGE:1800:-20:60 DS:light:GAUGE:300:0:1023 DS:movement:ABSOLUTE:604800:0:U  RRA:LAST:0.5:2:2048
-rrdtool update sensordata.rrd -t temp N:26.0   
-rrdtool update sensordata.rrd -t light N:200 
-rrdtool update sensordata.rrd -t movement N:0 
+rrdtool create sensorlight.rrd --step 30 DS:light:GAUGE:300:0:1023 RRA:LAST:0.5:2:2048
+rrdtool create sensortemp.rrd --step 30 DS:temp:GAUGE:1800:-20:60 RRA:LAST:0.5:2:2048
+rrdtool create sensormovement.rrd --step 30 DS:movement:ABSOLUTE:604800:0:U  RRA:LAST:0.5:2:2048
+rrdtool update sensorlight.rrd -t temp N:26.0   
+rrdtool update sensortemp.rrd -t light N:200 
+rrdtool update sensormovement.rrd -t movement N:0 
diff --git a/sensor_graph/sample_sensor3.lua b/sensor_graph/sample_sensor3.lua
new file mode 100755 (executable)
index 0000000..9d73d57
--- /dev/null
@@ -0,0 +1,35 @@
+#!/usr/bin/lua
+require('os')
+require('string')
+require('io')
+--require('socket')
+
+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/sensortemp.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/sensorlight.rrd -t light N:%d", last_light))
+    print(string.format("p: %d",last_light))
+  end
+  if string.find(str,"movement") then
+    --last_movement=1
+    os.execute(string.format("rrdtool update /home/sensormovement.rrd -t movement N:%d", 1))
+  end
+end
+
+
+
+while 1 do
+   local line = io.read("*line")
+    if line then 
+      parse_value(line) 
+    else
+      break
+    end
+end
index b9305cd..5b52164 100755 (executable)
@@ -8,20 +8,20 @@
 <RRD::GRAPH ../light0.png
    --lazy --imginfo '<IMG SRC="/%s" WIDTH="%lu" HEIGHT="%lu" >'
    --title="Room Illumination"
-   DEF:cel=/home/sensordata.rrd:light:LAST
+   DEF:cel=/home/sensorlight.rrd:light:LAST
    LINE2:cel#00a000:"0 dark to 1023 bright">
 </P>
 <P>
 <RRD::GRAPH ../temp0.png
    --lazy --imginfo '<IMG SRC="/%s" WIDTH="%lu" HEIGHT="%lu" >'
    --title="Temperatures"
-   DEF:cel=/home/sensordata.rrd:temp:LAST
+   DEF:cel=/home/sensortemp.rrd:temp:LAST
    LINE2:cel#00a000:"D. Celsius">
 </P>
 <RRD::GRAPH ../movement.png
   --lazy --imginfo '<IMG SRC="/%s" WIDTH="%lu" HEIGHT="%lu" >'
   --title="Graph of Movement Sensor"
-  DEF:cel=/home/sensordata.rrd:movement:LAST
+  DEF:cel=/home/sensormovement.rrd:movement:LAST
   LINE2:cel#00a000:"1 Movement, 0 No Movement">
 </P>                                 
 </BODY>