3 # sudo apt-get install jq
4 # ln -s `pwd`/temp3.sh /var/www/html/temp3.sh
5 # ln -s /dev/shm/temp3.png /var/www/html/temp3.png
6 # ln -s /dev/shm/temp3-gray.png /var/www/html/temp3-gray.png
8 # install as cgi-script and invoke to get png use http://localhost/temp3.sh?gray for kindle grayscale output
10 # use as http://localhost/temp3.sh?t=6h to show last 6h instead of default 48h
12 INTERVAL=`echo $QUERY_STRING | grep -i 't=[0-9]*h' | sed 's/.*t=\([0-9]*h\).*/\1/'`
13 test -z "$INTERVAL" && INTERVAL=48h
16 echo $QUERY_STRING | grep -i 'lines=' >/dev/null && LINES=1
25 # echo "# $topic [$rids] -> $file"
26 cat <<__SHELL__ >> /dev/shm/curl
27 curl -G 'http://10.60.0.89:8086/query' --data-urlencode "db=telegraf" --data-urlencode "epoch=s" --data-urlencode "q=SELECT \"value\" FROM \"mqtt_stat\" WHERE time > now() - $INTERVAL AND \"topic\"='$topic' " | sed -e 's/^.*"values":\[\[//' -e 's/\],\[/\n/g' -e 's/,/ /g' -e 's/]].*$//' > /dev/shm/data.$file
34 rids=`echo $* | sed -e 's/\([0-9][0-9]*\)/ or id = '"'"'\1'"'"'/g' -e 's/^ or//'`
36 # echo "# $topic [$rids] -> $file"
37 cat <<__SHELL__ >> /dev/shm/curl
38 curl -G 'http://10.60.0.89:8086/query' --data-urlencode "db=telegraf" --data-urlencode "epoch=s" --data-urlencode "q=SELECT \"temperature_C\",\"humidity\" FROM \"mqtt_rtl_433\" WHERE time > now() - $INTERVAL and model='Prologue-TH' AND ( $rids )" | sed -e 's/^.*"values":\[\[//' -e 's/\],\[/\n/g' -e 's/,/ /g' -e 's/]].*$//' > /dev/shm/data.$file
48 cat <<__SHELL__ >> /dev/shm/curl
49 curl -G 'http://10.60.0.89:8086/query' --data-urlencode "db=telegraf" --data-urlencode "epoch=s" --data-urlencode "q=SELECT \"$t_col\",\"$h_col\" FROM \"mqtt_tele_sensor\" WHERE time > now() - $INTERVAL and topic='$topic'" | sed -e 's/^.*"values":\[\[//' -e 's/\],\[/\n/g' -e 's/,/ /g' -e 's/]].*$//' > /dev/shm/data.$file
53 influx_mqtt 'stat/boiler/DS18B20/temperature' 'DS18B20-t'
54 influx_mqtt 'stat/boiler/DHT22/temperature' 'DHT22-t'
55 influx_mqtt 'stat/boiler/DHT22/humidity' 'DHT22-h'
57 influx_tele 'tele/ir/SENSOR' 'AM2301_Temperature' 'AM2301_Humidity' 'ir-dht22-t-h'
58 influx_tele 'tele/dht11-ir-hdmi/SENSOR' 'DHT11_Temperature' 'DHT11_Humidity' 'stol-dht11-t-h'
60 influx_mqtt 'stat/boiler/d' 'boiler-d'
62 influx_rtl 'vani-t-h' 0 165
63 influx_rtl 'kutija-t-h' 104 228 241 # hlad
64 influx_rtl 'kupaona-t-h' 114 98
65 influx_rtl 'kuhinja-t-h' 199 27
66 influx_rtl 'soba-t-h' 59 252
68 cat /dev/shm/curl | parallel
70 echo "parallel over" >/dev/stderr
72 GRAY=`echo $QUERY_STRING | grep -i gray | wc -l`
74 tz_secs=`date +%:z | cut -d: -f1 | sed -e 's/^+//' -e 's/$/ * 3600/' | bc`
76 cd /home/pi/vaillant-thermostat/
77 gnuplot -e "gray=$GRAY ; lines=$LINES ; interval=\"$INTERVAL\" ; tz_secs=$tz_secs" temp3.gnuplot
79 if [ "$GRAY" = 1 ] ; then
80 convert /dev/shm/temp3.png -gravity center -extent 600x800 -colorspace Gray /dev/shm/temp3-gray.png
86 set > /dev/shm/temp3.cgi.vars
89 test "$LINES" = 1 && lines_checked="checked"
91 if echo $HTTP_USER_AGENT | grep Mozilla > /dev/null ; then
92 echo "Content-type: text/html\r\n\r\n"
95 <form method="get" action="/temp3.sh" style="position: fixed; top: 0; left: 0">
96 <input type=submit name="t" value="48h">
97 <input type=submit name="t" value="24h">
98 <input type=submit name="t" value="12h">
99 <input type=submit name="t" value="6h">
100 <input type=submit name="t" value="1h">
101 <input type=checkbox name="lines" $lines_checked> <!-- $LINES -->
103 <img src="/temp3.png">
109 echo "Location: $REQUEST_SCHEME://$SERVER_NAME:$SERVER_PORT/temp3$GRAY.png"