From c28acc820c3a9f1dc343e8b5aba4e65d95060c71 Mon Sep 17 00:00:00 2001
From: Bernhard Tittelbach
Date: Thu, 18 Mar 2010 21:19:26 +0000
Subject: [PATCH] sensor sampling mit socket
---
sensor_graph/rrdtool.sh | 10 ++++++----
sensor_graph/sample_sensor3.lua | 35 +++++++++++++++++++++++++++++++++++
sensor_graph/sensors.cgi | 6 +++---
3 files changed, 44 insertions(+), 7 deletions(-)
create mode 100755 sensor_graph/sample_sensor3.lua
diff --git a/sensor_graph/rrdtool.sh b/sensor_graph/rrdtool.sh
index 1efcac4..374686a 100644
--- a/sensor_graph/rrdtool.sh
+++ b/sensor_graph/rrdtool.sh
@@ -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
index 0000000..9d73d57
--- /dev/null
+++ b/sensor_graph/sample_sensor3.lua
@@ -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
diff --git a/sensor_graph/sensors.cgi b/sensor_graph/sensors.cgi
index b9305cd..5b52164 100755
--- a/sensor_graph/sensors.cgi
+++ b/sensor_graph/sensors.cgi
@@ -8,20 +8,20 @@
'
--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">
'
--title="Temperatures"
- DEF:cel=/home/sensordata.rrd:temp:LAST
+ DEF:cel=/home/sensortemp.rrd:temp:LAST
LINE2:cel#00a000:"D. Celsius">
'
--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">