From 462c2f6307421a4a47d0c3f86112bf4f02bc96f3 Mon Sep 17 00:00:00 2001 From: Nathaniel Wesley Filardo Date: Wed, 7 Jun 2017 12:34:19 -0400 Subject: [PATCH] Bunch of updates, including new lcdproc client --- bin/.gitignore | 1 + bin/lcdproc-monitor.expect | 88 ++++++++++++++++++++++++++++ bin/lcdproc-remind.expect | 55 +++++++++++++++++ bin/lcdproc.expect | 117 ------------------------------------- bin/lcdproclib.tcl | 36 ++++++++++++ bin/monitor-graph-cgi.sh | 45 ++++++++++---- bin/pkgIndex.tcl | 1 + bin/rrdtool-creates.sh | 16 ++--- data/.gitignore | 2 + misc/crontab | 1 + misc/index.html | 21 +++++++ remind | 12 ---- remind/.gitignore | 2 + remind/light.rem | 21 +++++++ runit/pi-sc-lcd-remind/run | 3 + runit/pi-sc-lcd/run | 3 +- 16 files changed, 274 insertions(+), 150 deletions(-) create mode 100644 bin/.gitignore create mode 100755 bin/lcdproc-monitor.expect create mode 100755 bin/lcdproc-remind.expect delete mode 100755 bin/lcdproc.expect create mode 100644 bin/lcdproclib.tcl create mode 100644 bin/pkgIndex.tcl create mode 100644 misc/crontab create mode 100644 misc/index.html delete mode 100644 remind create mode 100644 remind/.gitignore create mode 100644 remind/light.rem create mode 100755 runit/pi-sc-lcd-remind/run diff --git a/bin/.gitignore b/bin/.gitignore new file mode 100644 index 0000000..0d20b64 --- /dev/null +++ b/bin/.gitignore @@ -0,0 +1 @@ +*.pyc diff --git a/bin/lcdproc-monitor.expect b/bin/lcdproc-monitor.expect new file mode 100755 index 0000000..d55a6d2 --- /dev/null +++ b/bin/lcdproc-monitor.expect @@ -0,0 +1,88 @@ +#!/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" {} + } +} diff --git a/bin/lcdproc-remind.expect b/bin/lcdproc-remind.expect new file mode 100755 index 0000000..50a4eef --- /dev/null +++ b/bin/lcdproc-remind.expect @@ -0,0 +1,55 @@ +#!/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" {} + } +} diff --git a/bin/lcdproc.expect b/bin/lcdproc.expect deleted file mode 100755 index 28235e6..0000000 --- a/bin/lcdproc.expect +++ /dev/null @@ -1,117 +0,0 @@ -#!/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" {} - } -} diff --git a/bin/lcdproclib.tcl b/bin/lcdproclib.tcl new file mode 100644 index 0000000..fca0ca5 --- /dev/null +++ b/bin/lcdproclib.tcl @@ -0,0 +1,36 @@ +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 diff --git a/bin/monitor-graph-cgi.sh b/bin/monitor-graph-cgi.sh index fcb2fc6..af4997c 100755 --- a/bin/monitor-graph-cgi.sh +++ b/bin/monitor-graph-cgi.sh @@ -3,11 +3,17 @@ 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 @@ -17,22 +23,37 @@ COMMON_ARGS=( 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 < /run/snakecontrol/remind.out diff --git a/misc/index.html b/misc/index.html new file mode 100644 index 0000000..7dd3dfe --- /dev/null +++ b/misc/index.html @@ -0,0 +1,21 @@ + + + Melman Vivarium Graphs + + + + + + + + + + + + + + +
+