Sensor Graphs on slug.realraum.at/cgi-bin/sensors.cgi
authorBernhard Tittelbach <xro@realraum.at>
Sun, 7 Mar 2010 02:36:21 +0000 (02:36 +0000)
committerBernhard Tittelbach <xro@realraum.at>
Sun, 7 Mar 2010 02:36:21 +0000 (02:36 +0000)
sensor_graph/rrdtool.sh [new file with mode: 0644]
sensor_graph/sample_sensor.lua [new file with mode: 0644]
sensor_graph/sensors.cgi [new file with mode: 0755]

diff --git a/sensor_graph/rrdtool.sh b/sensor_graph/rrdtool.sh
new file mode 100644 (file)
index 0000000..f18ae9f
--- /dev/null
@@ -0,0 +1,5 @@
+rrdtool create sensordata.rrd --step 30 DS:temp:GAUGE:1800:-20:60 DS:light:GAUGE:300:0:1023 DS:movement:GAUGE:300:0:1  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 
+
diff --git a/sensor_graph/sample_sensor.lua b/sensor_graph/sample_sensor.lua
new file mode 100644 (file)
index 0000000..ad3550d
--- /dev/null
@@ -0,0 +1,59 @@
+require('os')
+require('string')
+
+last_temp = 0.0
+last_light = 0
+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
+
+
+function parse_value(str)
+  if string.find(str,"Temp C:") then
+    last_temp = tonumber(string.sub(str,8))
+    --print(string.format("t: %f Grad Celsius",last_temp))
+  end
+  if string.find(str,"Photo:") then
+    last_light = tonumber(string.sub(str,7))
+    --print(string.format("p: %d",last_light))
+  end
+  if string.find(str,"movement") then
+   last_movement=1
+   --print "something moved"
+  end
+
+end
+
+
+
+
+local socket = require("socket")
+local client = assert(socket.connect("127.0.0.1",2010))
+--socket.unix = require("socket.unix")
+--local socket = assert(socket.unix())
+--local client = assert(socket:connect("/var/run/power_sensor.socket"))
+client:settimeout(10)
+
+
+
+
+while 1 do
+  local line, err = client:receive()
+  if not err then 
+    parse_value(line) 
+  end
+  client:send("T")
+  line, err = client:receive()
+  if not err then 
+    parse_value(line)
+  end
+  client:send("P")
+  line, err = client:receive()
+  if not err then 
+    parse_value(line)
+  end
+  save_values()
+end
diff --git a/sensor_graph/sensors.cgi b/sensor_graph/sensors.cgi
new file mode 100755 (executable)
index 0000000..be5ef8d
--- /dev/null
@@ -0,0 +1,28 @@
+#!/usr/bin/rrdcgi
+<HTML>
+<HEAD><TITLE>RealRaum Sensor Data</TITLE></HEAD>
+<BODY>
+<H1>RealRaum Sensor Data</H1>
+<RRD::GOODFOR 30>
+<P>
+<RRD::GRAPH ../light0.png
+   --imginfo '<IMG SRC="/%s" WIDTH="%lu" HEIGHT="%lu" >'
+   --lazy --title="Room Illumination"
+   DEF:cel=/home/sensordata.rrd:light:LAST
+   LINE2:cel#00a000:"0 dark to 1024 bright">
+</P>
+<P>
+<RRD::GRAPH ../temp0.png
+   --imginfo '<IMG SRC="/%s" WIDTH="%lu" HEIGHT="%lu" >'
+   --lazy --title="Temperatures"
+   DEF:cel=/home/sensordata.rrd:temp:LAST
+   LINE2:cel#00a000:"D. Celsius">
+</P>
+<RRD::GRAPH ../movement.png
+  --imginfo '<IMG SRC="/%s" WIDTH="%lu" HEIGHT="%lu" >'
+  --lazy --title="Graph of Movement Sensor"
+  DEF:cel=/home/sensordata.rrd:movement:LAST
+  LINE2:cel#00a000:"1 Movement, 0 No Movement">
+</P>                                 
+</BODY>
+</HTML>