-set terminal pngcairo color size 600,800
+if ( ! exists("mono") ) {
+ set terminal pngcairo color size 600,800
+} else {
+ set terminal pngcairo mono size 600,800
+}
set xdata time
set timefmt "%s"
set output '/dev/shm/temp2.png'
+unset border
+
set multiplot
set size 1, 0.5
plot "/dev/shm/DS18B20-temperature" using ($1+7200):($2 > min_t && $2 < max_t ? $2 : '') with dots title "DS18B20 deg. C" \
,"/dev/shm/DHT22-temperature" using ($1+7200):($2 > min_t && $2 < max_t ? $2 : '') with dots title "DHT22 deg. C" \
-,"/dev/shm/rtl_433-temperature" using ($1+7200):($2) with dots title "RTL433 deg. C" axes x1y2
+,"/dev/shm/rtl_433-temperature" using ($1+7200):($2) with dots title "RTL433 deg. C"
set origin 0.0, 0.0
max_h = h_mean + h_spread
plot "/dev/shm/DHT22-humidity" using ($1+7200):($2 > min_h && $2 < max_h ? $2 : '') with dots title "DHT22 % hum" \
-,"/dev/shm/rtl_433-humidity" using ($1+7200):($2) with dots title "RTL433 % hum" axis x1y2
+,"/dev/shm/rtl_433-humidity" using ($1+7200):($2) with dots title "RTL433 % hum"
unset multiplot
#!/bin/sh -x
# sudo apt-get install jq
+# ln -s `pwd`/temp2.sh /var/www/html/temp2.sh
+# ln -s /dev/shm/temp2.png /var/www/html/temp2.png
+# ln -s /dev/shm/temp2-gray.png /var/www/html/temp2-gray.png
#
-# install as cgi-script and invoke to get png
-
-#ssh rpi 'cat `ls -t /dev/shm/vaillant.* | head -1` | sed "s/ .*| */ /"' > /dev/shm/temp.tsv
-#tail -4320 `ls -t /dev/shm/vaillant.* | head -1` | sed "s/ .*| */ /" > /dev/shm/temp.tsv
+# install as cgi-script and invoke to get png use http://localhost/temp2.sh?gray for kindle grayscale output
curl -G 'http://10.60.0.89:8086/query' --data-urlencode "db=telegraf" --data-urlencode "epoch=s" --data-urlencode "q=SELECT \"value\" FROM \"mqtt_consumer\" WHERE time > now() - 48h AND \"topic\"='stat/boiler/DS18B20/temperature'" | sed -e 's/^.*"values":\[\[//' -e 's/\],\[/\n/g' -e 's/,/ /g' -e 's/]].*$//' > /dev/shm/DS18B20-temperature
curl -G 'http://10.60.0.89:8086/query' --data-urlencode "db=telegraf" --data-urlencode "epoch=s" --data-urlencode "q=SELECT \"value\" FROM \"mqtt_consumer\" WHERE time > now() - 48h AND \"topic\"='stat/boiler/DHT22/temperature'" | sed -e 's/^.*"values":\[\[//' -e 's/\],\[/\n/g' -e 's/,/ /g' -e 's/]].*$//' > /dev/shm/DHT22-temperature
curl -G 'http://10.60.0.89:8086/query' --data-urlencode "db=telegraf" --data-urlencode "epoch=s" --data-urlencode "q=SELECT \"humidity\" FROM \"rtl_433\" WHERE time > now() - 48h AND \"topic\"='rpi2/rtl_433/influx' AND \"id\" = '5'" | sed -e 's/^.*"values":\[\[//' -e 's/\],\[/\n/g' -e 's/,/ /g' -e 's/]].*$//' > /dev/shm/rtl_433-humidity
+
cd /home/pi/vaillant-thermostat/
gnuplot -e "t_mean=`head -1 /dev/shm/temperature.mean.spread`;t_spread=`tail -1 /dev/shm/temperature.mean.spread`;h_mean=`head -1 /dev/shm/humidity.mean.spread` ; h_spread=`tail -1 /dev/shm/humidity.mean.spread`" temp2.gnuplot
-convert /dev/shm/temp2.png -gravity center -extent 600x800 -colorspace Gray /dev/shm/temp2-gray.png
-# ln -s /dev/shm/temp2-gray.png /var/www/html/temp2.png
-echo "Location: $REQUEST_SCHEME://$SERVER_NAME:$SERVER_PORT/temp2.png"
+GRAY=`echo $QUERY_STRING | grep -i gray`
+if [ ! -z "$GRAY" ] ; then
+ convert /dev/shm/temp2.png -gravity center -extent 600x800 -colorspace Gray /dev/shm/temp2-gray.png
+ GRAY="-gray"
+fi
+
+set > /dev/shm/temp2.cgi.vars
+
+echo "Location: $REQUEST_SCHEME://$SERVER_NAME:$SERVER_PORT/temp2$GRAY.png"
echo
exit 0