--- /dev/null
+#!/usr/bin/expect
+
+package require lcdproclib
+
+spawn tail --retry --follow=name /run/snakecontrol/monitor.log/current
+set logsid ${spawn_id}
+
+set sid [::lcdproclib::spawnlcd "localhost" "13666"]
+::lcdproclib::cmd ${sid} "client_set -name viv"
+
+::lcdproclib::cmd ${sid} "screen_add 1"
+::lcdproclib::cmd ${sid} "screen_set 1 -name Vivarium"
+::lcdproclib::cmd ${sid} "screen_set 1 -priority hidden"
+::lcdproclib::cmd ${sid} "screen_set 1 -cursor off"
+
+::lcdproclib::cmd ${sid} "widget_add 1 ti title"
+::lcdproclib::cmd ${sid} "widget_set 1 ti Vivarium"
+
+::lcdproclib::cmd ${sid} "widget_add 1 i_up icon"
+::lcdproclib::cmd ${sid} "widget_set 1 i_up 1 2 ARROW_UP"
+::lcdproclib::cmd ${sid} "widget_add 1 i_th string"
+::lcdproclib::cmd ${sid} "widget_set 1 i_th 2 2 T"
+::lcdproclib::cmd ${sid} "widget_add 1 v_ut string"
+::lcdproclib::cmd ${sid} "widget_add 1 i_uh string"
+::lcdproclib::cmd ${sid} "widget_set 1 i_uh 8 2 H"
+::lcdproclib::cmd ${sid} "widget_add 1 v_uh string"
+
+::lcdproclib::cmd ${sid} "widget_add 1 i_l icon"
+::lcdproclib::cmd ${sid} "widget_set 1 i_l 1 3 ARROW_LEFT"
+
+::lcdproclib::cmd ${sid} "widget_add 1 i_r icon"
+::lcdproclib::cmd ${sid} "widget_set 1 i_r 1 4 ARROW_RIGHT"
+
+::lcdproclib::cmd ${sid} "widget_add 1 i_lh icon"
+::lcdproclib::cmd ${sid} "widget_set 1 i_lh 2 3 ARROW_DOWN"
+::lcdproclib::cmd ${sid} "widget_add 1 v_lh string"
+
+::lcdproclib::cmd ${sid} "widget_add 1 i_rh icon"
+::lcdproclib::cmd ${sid} "widget_set 1 i_rh 2 4 ARROW_DOWN"
+::lcdproclib::cmd ${sid} "widget_add 1 v_rh string"
+
+::lcdproclib::cmd ${sid} "widget_add 1 i_lt icon"
+::lcdproclib::cmd ${sid} "widget_set 1 i_lt 9 3 ARROW_UP"
+::lcdproclib::cmd ${sid} "widget_add 1 v_lt string"
+
+::lcdproclib::cmd ${sid} "widget_add 1 i_rt icon"
+::lcdproclib::cmd ${sid} "widget_set 1 i_rt 9 4 ARROW_UP"
+::lcdproclib::cmd ${sid} "widget_add 1 v_rt string"
+
+::lcdproclib::cmd ${sid} "widget_add 1 v_ldmxl string"
+::lcdproclib::cmd ${sid} "widget_set 1 v_ldmxl 17 3 @"
+::lcdproclib::cmd ${sid} "widget_add 1 v_ldmx string"
+
+::lcdproclib::cmd ${sid} "widget_add 1 v_rdmxl string"
+::lcdproclib::cmd ${sid} "widget_set 1 v_rdmxl 17 4 @"
+::lcdproclib::cmd ${sid} "widget_add 1 v_rdmx string"
+
+::lcdproclib::cmd ${sid} "screen_set 1 -priority info"
+
+proc drawtemp { scr wid x y } {
+ global sid
+ global expect_out
+ set t [expr round(${expect_out(1,string)}*10.0)/10.0]
+ ::lcdproclib::cmd ${sid} "widget_set ${scr} ${wid} ${x} ${y} ${t}"
+}
+
+set datapfx "^\[^ \]* DATA: "
+set datare "(\[^ \r\n]*)"
+
+while { true } {
+ expect {
+ -i ${logsid} -re "${datapfx}hide-near.* temp=${datare}.*\n" { drawtemp 1 "v_lh" 4 3 }
+ -i ${logsid} -re "${datapfx}hide-far.* temp=${datare}.*\n" { drawtemp 1 "v_rh" 4 4 }
+ -i ${logsid} -re "${datapfx}tank-near.* temp=${datare}.*\n" { drawtemp 1 "v_lt" 11 3 }
+ -i ${logsid} -re "${datapfx}tank-far.* temp=${datare}.*\n" { drawtemp 1 "v_rt" 11 4 }
+ -i ${logsid} -re "${datapfx}tank-top.* temp=${datare}.*\n" { drawtemp 1 "v_ut" 3 2 }
+ -i ${logsid} -re "${datapfx}tank-top.* humid=${datare}.*\n" { drawtemp 1 "v_uh" 9 2 }
+ -i ${logsid} -re "${datapfx}dmx-near.* dmx=${datare}.*\n" {
+ ::lcdproclib::cmd ${sid} "widget_set 1 v_ldmx 18 3 ${expect_out(1,string)}"
+ }
+ -i ${logsid} -re "${datapfx}dmx-mid.* dmx=${datare}.*\n" {
+ ::lcdproclib::cmd ${sid} "widget_set 1 v_rdmx 18 4 ${expect_out(1,string)}"
+ }
+ -i ${logsid} -re "\n" {}
+ -i ${sid} -re "^listen .*\n" {}
+ -i ${sid} -re "^ignore .*\n" {}
+ }
+}
--- /dev/null
+#!/usr/bin/expect
+
+package require lcdproclib
+
+set lcdsid [::lcdproclib::spawnlcd "localhost" "13666"]
+::lcdproclib::cmd ${lcdsid} "client_set -name remind"
+
+::lcdproclib::cmd ${lcdsid} "screen_add 1"
+::lcdproclib::cmd ${lcdsid} "screen_set 1 -name Reminders"
+::lcdproclib::cmd ${lcdsid} "screen_set 1 -priority hidden"
+::lcdproclib::cmd ${lcdsid} "screen_set 1 -cursor off"
+
+::lcdproclib::cmd ${lcdsid} "widget_add 1 ti title"
+::lcdproclib::cmd ${lcdsid} "widget_set 1 ti Reminders"
+
+::lcdproclib::cmd ${lcdsid} "widget_add 1 v1 string"
+
+::lcdproclib::cmd ${lcdsid} "screen_set 1 -priority info"
+
+
+proc reload {lcdsid filename} {
+ try {
+ set fp [open ${filename} r]
+ } trap {POSIX ENOENT} {} {
+ puts "ENOENT"
+ sleep 1
+ return
+ }
+
+ ::lcdproclib::cmd ${lcdsid} "widget_set 1 ti {[gets $fp]}"
+ ::lcdproclib::cmd ${lcdsid} "widget_set 1 v1 1 2 {[gets $fp]}"
+
+ close ${fp}
+}
+
+proc spawninotify {filename} {
+ spawn inotifywait -m -e CLOSE_WRITE,DELETE_SELF ${filename}
+ return ${spawn_id}
+}
+
+set filename "/run/snakecontrol/remind.out"
+
+set waitsid [spawninotify ${filename}]
+
+while { true } {
+ expect {
+ -i ${waitsid} -re "(CLOSE|DELETE)" {
+ close ${waitsid}
+ set waitsid [spawninotify ${filename}]
+ }
+ -i ${waitsid} "Watches established." { reload ${lcdsid} ${filename} }
+ -i ${lcdsid} -re "^listen .*\n" {}
+ -i ${lcdsid} -re "^ignore .*\n" {}
+ }
+}
+++ /dev/null
-#!/usr/bin/expect
-
-proc lcdcmd {sid cmd} {
- send -i ${sid} "${cmd}\n"
- while { true } {
- expect {
- -i ${sid} -re "^[lindex [split "${cmd}"] 0]\[^\n\]*\r\n" {
- while { true } {
- expect {
- -i ${sid} -re "^success\[^\n\]*\n" { return }
- -i ${sid} -re "^\r\n" { }
- -i ${sid} -re "^listen .*\n" {}
- -i ${sid} -re "^ignore .*\n" {}
- timeout { error "LCD protocol failure while waiting for success?" }
- }
- }
- }
- -i ${sid} -re "^listen .*\n" {}
- -i ${sid} -re "^ignore .*\n" {}
- timeout { error "LCD protocol failure while waiting for echo?" }
- }
- }
-}
-
-proc spawnlcd {host port} {
- spawn socat STDIO "TCP:${host}:${port}"
- send -i ${spawn_id} "hello\n"
- expect {
- -i ${spawn_id} -re "^hello\r\nconnect .*\r\n" { return ${spawn_id} }
- timeout { error "LCD protocol failure while sending hello?" }
- }
-}
-
-spawn tail --retry --follow=name /run/snakecontrol/monitor.log/current
-set logsid ${spawn_id}
-
-set sid [spawnlcd "localhost" "13666"]
-lcdcmd ${sid} "client_set -name test"
-
-lcdcmd ${sid} "screen_add 1"
-lcdcmd ${sid} "screen_set 1 -name Vivarium"
-lcdcmd ${sid} "screen_set 1 -priority hidden"
-lcdcmd ${sid} "screen_set 1 -cursor off"
-
-lcdcmd ${sid} "widget_add 1 ti title"
-lcdcmd ${sid} "widget_set 1 ti Vivarium"
-
-lcdcmd ${sid} "widget_add 1 i_up icon"
-lcdcmd ${sid} "widget_set 1 i_up 1 2 ARROW_UP"
-lcdcmd ${sid} "widget_add 1 i_th string"
-lcdcmd ${sid} "widget_set 1 i_th 2 2 T"
-lcdcmd ${sid} "widget_add 1 v_ut string"
-lcdcmd ${sid} "widget_add 1 i_uh string"
-lcdcmd ${sid} "widget_set 1 i_uh 8 2 H"
-lcdcmd ${sid} "widget_add 1 v_uh string"
-
-lcdcmd ${sid} "widget_add 1 i_l icon"
-lcdcmd ${sid} "widget_set 1 i_l 1 3 ARROW_LEFT"
-
-lcdcmd ${sid} "widget_add 1 i_r icon"
-lcdcmd ${sid} "widget_set 1 i_r 1 4 ARROW_RIGHT"
-
-lcdcmd ${sid} "widget_add 1 i_lh icon"
-lcdcmd ${sid} "widget_set 1 i_lh 2 3 ARROW_DOWN"
-lcdcmd ${sid} "widget_add 1 v_lh string"
-
-lcdcmd ${sid} "widget_add 1 i_rh icon"
-lcdcmd ${sid} "widget_set 1 i_rh 2 4 ARROW_DOWN"
-lcdcmd ${sid} "widget_add 1 v_rh string"
-
-lcdcmd ${sid} "widget_add 1 i_lt icon"
-lcdcmd ${sid} "widget_set 1 i_lt 9 3 ARROW_UP"
-lcdcmd ${sid} "widget_add 1 v_lt string"
-
-lcdcmd ${sid} "widget_add 1 i_rt icon"
-lcdcmd ${sid} "widget_set 1 i_rt 9 4 ARROW_UP"
-lcdcmd ${sid} "widget_add 1 v_rt string"
-
-lcdcmd ${sid} "widget_add 1 v_ldmxl string"
-lcdcmd ${sid} "widget_set 1 v_ldmxl 17 3 @"
-lcdcmd ${sid} "widget_add 1 v_ldmx string"
-
-lcdcmd ${sid} "widget_add 1 v_rdmxl string"
-lcdcmd ${sid} "widget_set 1 v_rdmxl 17 4 @"
-lcdcmd ${sid} "widget_add 1 v_rdmx string"
-
-lcdcmd ${sid} "screen_set 1 -priority info"
-
-proc drawtemp { scr wid x y } {
- global sid
- global expect_out
- set t [expr round(${expect_out(1,string)}*10.0)/10.0]
- lcdcmd ${sid} "widget_set ${scr} ${wid} ${x} ${y} ${t}"
-}
-
-set datapfx "^\[^ \]* DATA: "
-set datare "(\[^ \r\n]*)"
-
-while { true } {
- expect {
- -i ${logsid} -re "${datapfx}hide-near.* temp=${datare}.*\n" { drawtemp 1 "v_lh" 4 3 }
- -i ${logsid} -re "${datapfx}hide-far.* temp=${datare}.*\n" { drawtemp 1 "v_rh" 4 4 }
- -i ${logsid} -re "${datapfx}tank-near.* temp=${datare}.*\n" { drawtemp 1 "v_lt" 11 3 }
- -i ${logsid} -re "${datapfx}tank-far.* temp=${datare}.*\n" { drawtemp 1 "v_rt" 11 4 }
- -i ${logsid} -re "${datapfx}tank-top.* temp=${datare}.*\n" { drawtemp 1 "v_ut" 3 2 }
- -i ${logsid} -re "${datapfx}tank-top.* humid=${datare}.*\n" { drawtemp 1 "v_uh" 9 2 }
- -i ${logsid} -re "${datapfx}dmx-near.* dmx=${datare}.*\n" {
- lcdcmd ${sid} "widget_set 1 v_ldmx 18 3 ${expect_out(1,string)}"
- }
- -i ${logsid} -re "${datapfx}dmx-mid.* dmx=${datare}.*\n" {
- lcdcmd ${sid} "widget_set 1 v_rdmx 18 4 ${expect_out(1,string)}"
- }
- -i ${logsid} -re "\n" {}
- -i ${sid} -re "^listen .*\n" {}
- -i ${sid} -re "^ignore .*\n" {}
- }
-}
--- /dev/null
+namespace eval ::lcdproclib {
+ variable version 0.0.1
+}
+
+proc ::lcdproclib::cmd {sid cmd} {
+ send -i ${sid} "${cmd}\n"
+ while { true } {
+ expect {
+ -i ${sid} -re "^[lindex [split "${cmd}"] 0]\[^\n\]*\r\n" {
+ while { true } {
+ expect {
+ -i ${sid} -re "^success\[^\n\]*\n" { return }
+ -i ${sid} -re "^\r\n" { }
+ -i ${sid} -re "^listen .*\n" {}
+ -i ${sid} -re "^ignore .*\n" {}
+ timeout { error "LCD protocol failure while waiting for success?" }
+ }
+ }
+ }
+ -i ${sid} -re "^listen .*\n" {}
+ -i ${sid} -re "^ignore .*\n" {}
+ timeout { error "LCD protocol failure while waiting for echo?" }
+ }
+ }
+}
+
+proc ::lcdproclib::spawnlcd {host port} {
+ spawn socat STDIO "TCP:${host}:${port}"
+ send -i ${spawn_id} "hello\n"
+ expect {
+ -i ${spawn_id} -re "^hello\r\nconnect .*\r\n" { return ${spawn_id} }
+ timeout { error "LCD protocol failure while sending hello?" }
+ }
+}
+
+package provide lcdproclib $::lcdproclib::version
DMX_SCALE=5
DMX_SHIFT=20
+TEMP_SCALE_UPPER=32
+TEMP_SCALE_LOWER=19
+
COMMON_ARGS=(
--end now
--width=960 --height=480
--lazy
- --step=60 -v "degrees C" --upper-limit 32 --lower-limit 19 --rigid
+)
+
+TEMP_ARGS=(
+ --step=60 -v "degrees C" --upper-limit ${TEMP_SCALE_UPPER} --lower-limit ${TEMP_SCALE_LOWER} --rigid
--right-axis-label "DMX"
--right-axis ${DMX_SCALE}:-${DMX_SHIFT}
DEF:tempH=/home/pi/sc/data/heater-temp.rrd:temp:AVERAGE
DEF:tempTN=/home/pi/sc/data/tank-near-temp.rrd:temp:AVERAGE
DEF:tempTF=/home/pi/sc/data/tank-far-temp.rrd:temp:AVERAGE
CDEF:scaled_dmxHN=dmxHN,${DMX_SHIFT},+,${DMX_SCALE},/
- LINE:scaled_dmxHN\#000000:"dmx near"
+ LINE:scaled_dmxHN\#000000:"dmx left"
LINE2:tempH\#FF0000:"heater"
- LINE2:tempHN\#808000:"hide near"
- LINE2:tempHF\#FF8000:"hide far"
- LINE2:tempTN\#00FF00:"tank near"
- LINE2:tempTF\#00FFFF:"tank far"
+ LINE2:tempHN\#808000:"hide left"
+ LINE2:tempHF\#FF8000:"hide right"
+ LINE2:tempTN\#00FF00:"tank left"
+ LINE2:tempTF\#00FFFF:"tank right"
HRULE:30#800000
- HRULE:25#8000FF
- HRULE:21#0000FF
+)
+
+HUMID_SCALE=$(( 100.0/(TEMP_SCALE_UPPER-TEMP_SCALE_LOWER) ))
+HUMID_SHIFT=$(( TEMP_SCALE_LOWER * HUMID_SCALE ))
+
+TOP_ARGS=(
+ --step=60 -v "degrees C" --upper-limit ${TEMP_SCALE_UPPER} --lower-limit ${TEMP_SCALE_LOWER} --rigid
+ --right-axis-label "Humidity"
+ --right-axis ${HUMID_SCALE}:-${HUMID_SHIFT}
+ DEF:temp=/home/pi/sc/data/tank-top-temp.rrd:temp:AVERAGE
+ DEF:humid=/home/pi/sc/data/tank-top-humid.rrd:humid:AVERAGE
+ CDEF:scaled_humid=humid,${HUMID_SHIFT},+,${HUMID_SCALE},/
+ LINE2:scaled_humid\#0000FF:"humidity"
+ LINE2:temp\#FF0000:"temp"
)
case "$QUERY_STRING" in
- 4h) OUTFILE="4h.png"; PARAMS=(--start now-4h --title "Melman Vivarium Sensor Data 4h" ) ;;
- 24h) OUTFILE="24h.png"; PARAMS=(--start now-24h --title "Melman Vivarium Sensor Data 24h") ;;
- 7d) OUTFILE="7d.png"; PARAMS=(--start now-7d --title "Melman Vivarium Sensor Data 7d" ) ;;
- 30d) OUTFILE="30d.png"; PARAMS=(--start now-30d --title "Melman Vivarium Sensor Data 30d") ;;
+ t-4h) OUTFILE="4h.png"; PARAMS=(--start now-4h --title "Melman Vivarium Sensor Data 4h" ${TEMP_ARGS[@]}) ;;
+ t-24h) OUTFILE="24h.png"; PARAMS=(--start now-24h --title "Melman Vivarium Sensor Data 24h" ${TEMP_ARGS[@]}) ;;
+ t-7d) OUTFILE="7d.png"; PARAMS=(--start now-7d --title "Melman Vivarium Sensor Data 7d" ${TEMP_ARGS[@]}) ;;
+ t-30d) OUTFILE="30d.png"; PARAMS=(--start now-30d --title "Melman Vivarium Sensor Data 30d" ${TEMP_ARGS[@]}) ;;
+ top-4h) OUTFILE="top-4h.png"; PARAMS=(--start now-4h --title "Melman Vivarium Top Sensor Data 4h" ${TOP_ARGS[@]}) ;;
+ top-24h) OUTFILE="top-24h.png"; PARAMS=(--start now-24h --title "Melman Vivarium Top Sensor Data 24h" ${TOP_ARGS[@]}) ;;
+ top-7d) OUTFILE="top-7d.png"; PARAMS=(--start now-7d --title "Melman Vivarium Top Sensor Data 7d" ${TOP_ARGS[@]}) ;;
*)
cat <<HERE
Content-Type: text/html
--- /dev/null
+package ifneeded lcdproclib 0.0.1 [list source [file join $dir lcdproclib.tcl]]
--no-overwrite \
--step 60 \
DS:humid:GAUGE:900:-5:105 \
- RRA:AVERAGE:0.5:6:525600 \
- RRA:AVERAGE:0.25:360:87600 \
- RRA:MIN:0.025:360:87600 \
- RRA:MAX:0.025:360:87600
+ RRA:AVERAGE:0.5:1:525600 \
+ RRA:AVERAGE:0.25:60:87600 \
+ RRA:MIN:0.025:60:87600 \
+ RRA:MAX:0.025:60:87600
rrdtool create /home/pi/sc/data/tank-top-press.rrd \
--no-overwrite \
--step 60 \
DS:press:GAUGE:900:-1000:120000 \
- RRA:AVERAGE:0.5:6:525600 \
- RRA:AVERAGE:0.25:360:87600 \
- RRA:MIN:0.025:360:87600 \
- RRA:MAX:0.025:360:87600
+ RRA:AVERAGE:0.5:1:525600 \
+ RRA:AVERAGE:0.25:60:87600 \
+ RRA:MIN:0.025:60:87600 \
+ RRA:MAX:0.025:60:87600
--- /dev/null
+* */4 * * * remind -r /home/pi/sc/data/care.rem | grep -v '^$' > /run/snakecontrol/remind.out
--- /dev/null
+<HTML>
+ <HEAD>
+ <TITLE>Melman Vivarium Graphs</TITLE>
+ <META http-equiv="refresh" content="300">
+ </HEAD><BODY>
+ <TABLE>
+ <TR>
+ <TD><IMG src="cgi-bin/graph.cgi?t-4h" width="1057" height="553"/></TD>
+ <TD><IMG src="cgi-bin/graph.cgi?t-24h" width="1057" height="553"/></TD>
+ <TD><IMG src="cgi-bin/graph.cgi?t-7d" width="1057" height="553"/></TD>
+ <TD><IMG src="cgi-bin/graph.cgi?t-30d" width="1057" height="553"/></TD>
+ </TR>
+ <TR>
+ <TD><IMG src="cgi-bin/graph.cgi?top-4h" width="1057" height="553"/></TD>
+ <TD><IMG src="cgi-bin/graph.cgi?top-24h" width="1057" height="553"/></TD>
+ <TD><IMG src="cgi-bin/graph.cgi?top-7d" width="1057" height="553"/></TD>
+ </TR>
+ </TABLE>
+ <IFRAME src="cgi-bin/log.cgi" width="2116"/>
+ </BODY>
+</HTML>
+++ /dev/null
-SET $LongDeg 76
-SET $LongMin 36
-SET $LongSec 33
-SET $LatDeg 39
-SET $LatMin 17
-SET $LatSec 33
-
-REM AT [sunrise()] MSG Lights on...
-REM AT [sunrise()] RUN /home/pi/sc/bin/rpb.expect 1 on > /dev/null
-
-REM AT [sunset()] MSG Lights off...
-REM AT [sunset()] RUN /home/pi/sc/bin/rpb.expect 1 off > /dev/null
--- /dev/null
+.*.swp
+care.rem
--- /dev/null
+SET $LongDeg 76
+SET $LongMin 36
+SET $LongSec 33
+SET $LatDeg 39
+SET $LatMin 17
+SET $LatSec 33
+
+REM AT [sunrise()] MSG Lights on...
+REM AT [sunrise()] RUN /home/pi/sc/bin/rpb.expect 1 on > /dev/null
+
+REM AT [sunset()] MSG Lights off...
+REM AT [sunset()] RUN /home/pi/sc/bin/rpb.expect 1 off > /dev/null
+
+REM AT [sunrise() - 45] MSG Aerator on
+REM AT [sunrise() - 45] RUN /home/pi/sc/bin/rpb.expect 4 on > /dev/null
+REM AT [sunrise() + 45] MSG Aerator off
+REM AT [sunrise() + 45] RUN /home/pi/sc/bin/rpb.expect 4 off > /dev/null
+REM AT [sunset() - 45] MSG Aerator on
+REM AT [sunset() - 45] RUN /home/pi/sc/bin/rpb.expect 4 on > /dev/null
+REM AT [sunset() + 45] MSG Aerator off
+REM AT [sunset() + 45] RUN /home/pi/sc/bin/rpb.expect 4 off > /dev/null
--- /dev/null
+#!/bin/sh
+export TCLLIBPATH="$TCLLIBPATH /home/pi/sc/bin"
+exec chpst -u pi:pi expect /home/pi/sc/bin/lcdproc-remind.expect >/dev/null
#!/bin/sh
-exec chpst -u pi:pi expect /home/pi/sc/bin/lcdproc.expect >/dev/null
+export TCLLIBPATH="$TCLLIBPATH /home/pi/sc/bin"
+exec chpst -u pi:pi expect /home/pi/sc/bin/lcdproc-monitor.expect >/dev/null