color gray, /temp2.sh?gray for kindle grayscale version
authorDobrica Pavlinusic <dpavlin@rot13.org>
Sat, 5 Aug 2017 09:21:06 +0000 (11:21 +0200)
committerDobrica Pavlinusic <dpavlin@rot13.org>
Sat, 5 Aug 2017 09:21:06 +0000 (11:21 +0200)
temp2.gnuplot
temp2.sh

index 42c988d..764ad17 100644 (file)
@@ -1,4 +1,8 @@
-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"
@@ -9,6 +13,8 @@ set pointsize 0.2
 
 set output '/dev/shm/temp2.png'
 
+unset border
+
 set multiplot
 set size 1, 0.5
 
@@ -33,7 +39,7 @@ set y2tics
 
 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
 
@@ -42,6 +48,6 @@ min_h = h_mean - h_spread
 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
index b14ddf0..c8b2390 100755 (executable)
--- a/temp2.sh
+++ b/temp2.sh
@@ -1,11 +1,11 @@
 #!/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
@@ -18,12 +18,19 @@ curl -G 'http://10.60.0.89:8086/query' --data-urlencode "db=telegraf" --data-url
 
 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