X-Git-Url: http://git.rot13.org/?a=blobdiff_plain;f=temp2.sh;h=32670fe86cd079f9c0bc783c0fd3468e8146e5f4;hb=3e30408e19a1d486982af96b0e2bd4bc5ec9a749;hp=3ffd76db8c248cd43478881337a964a778c21a77;hpb=8706ce2f99dfd5dc9dacd869ce596e35e577777b;p=vaillant-thermostat diff --git a/temp2.sh b/temp2.sh index 3ffd76d..32670fe 100755 --- a/temp2.sh +++ b/temp2.sh @@ -1,4 +1,4 @@ -#!/bin/sh -x +#!/bin/sh # sudo apt-get install jq # ln -s `pwd`/temp2.sh /var/www/html/temp2.sh @@ -12,37 +12,71 @@ INTERVAL=`echo $QUERY_STRING | grep -i 't=[0-9]*h' | sed 's/.*t=\([0-9]*h\).*/\1/'` test -z "$INTERVAL" && INTERVAL=48h +LINES=0 +echo $QUERY_STRING | grep -i 'lines=' >/dev/null && LINES=1 + +cat <<__SHELL__ | parallel + 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() - $INTERVAL 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() - $INTERVAL 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 \"value\" FROM \"mqtt_consumer\" WHERE time > now() - $INTERVAL AND \"topic\"='stat/boiler/DHT22/humidity'" | sed -e 's/^.*"values":\[\[//' -e 's/\],\[/\n/g' -e 's/,/ /g' -e 's/]].*$//' > /dev/shm/DHT22-humidity +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() - $INTERVAL AND \"topic\"='stat/boiler/d'" | sed -e 's/^.*"values":\[\[//' -e 's/\],\[/\n/g' -e 's/,/ /g' -e 's/]].*$//' > /dev/shm/boiler.d + #curl -G 'http://10.60.0.89:8086/query' --data-urlencode "db=telegraf" --data-urlencode "epoch=s" --data-urlencode "q=SELECT \"temperature_C\" FROM \"rtl_433\" WHERE time > now() - $INTERVAL 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-temperature -curl -G 'http://10.60.0.89:8086/query' --data-urlencode "db=telegraf" --data-urlencode "epoch=s" --data-urlencode "q=SELECT \"temperature_C\" FROM \"rtl_433\" WHERE time > now() - $INTERVAL AND \"topic\"='rpi2/rtl_433/influx' AND \"rid\" = '172'" | sed -e 's/^.*"values":\[\[//' -e 's/\],\[/\n/g' -e 's/,/ /g' -e 's/]].*$//' | tr -d '\\"' > /dev/shm/rtl_433-9-172-temperature -curl -G 'http://10.60.0.89:8086/query' --data-urlencode "db=telegraf" --data-urlencode "epoch=s" --data-urlencode "q=SELECT \"temperature_C\" FROM \"rtl_433\" WHERE time > now() - $INTERVAL AND \"topic\"='rpi2/rtl_433/influx' AND \"rid\" = '75'" | sed -e 's/^.*"values":\[\[//' -e 's/\],\[/\n/g' -e 's/,/ /g' -e 's/]].*$//' | tr -d '\\"' > /dev/shm/rtl_433-9-75-temperature -curl -G 'http://10.60.0.89:8086/query' --data-urlencode "db=telegraf" --data-urlencode "epoch=s" --data-urlencode "q=SELECT \"temperature_C\" FROM \"rtl_433\" WHERE time > now() - $INTERVAL AND \"topic\"='rpi2/rtl_433/influx' AND \"rid\" = '141'" | sed -e 's/^.*"values":\[\[//' -e 's/\],\[/\n/g' -e 's/,/ /g' -e 's/]].*$//' | tr -d '\\"' > /dev/shm/rtl_433-9-141-temperature +curl -G 'http://10.60.0.89:8086/query' --data-urlencode "db=telegraf" --data-urlencode "epoch=s" --data-urlencode "q=SELECT \"temperature_C\" FROM \"rtl_433\" WHERE time > now() - $INTERVAL AND \"topic\"='rpi2/rtl_433/influx' AND \"rid\" = '1111' or \"rid\" = '47'" | sed -e 's/^.*"values":\[\[//' -e 's/\],\[/\n/g' -e 's/,/ /g' -e 's/]].*$//' | tr -d '\\"' > /dev/shm/rtl_433-vani-temperature +curl -G 'http://10.60.0.89:8086/query' --data-urlencode "db=telegraf" --data-urlencode "epoch=s" --data-urlencode "q=SELECT \"temperature_C\" FROM \"rtl_433\" WHERE time > now() - $INTERVAL AND \"topic\"='rpi2/rtl_433/influx' AND \"rid\" = '75' or \"rid\" = '211'" | sed -e 's/^.*"values":\[\[//' -e 's/\],\[/\n/g' -e 's/,/ /g' -e 's/]].*$//' | tr -d '\\"' > /dev/shm/rtl_433-kupaona-temperature +curl -G 'http://10.60.0.89:8086/query' --data-urlencode "db=telegraf" --data-urlencode "epoch=s" --data-urlencode "q=SELECT \"temperature_C\" FROM \"rtl_433\" WHERE time > now() - $INTERVAL AND \"topic\"='rpi2/rtl_433/influx' AND \"rid\" = '143' or \"rid\" = '209'" | sed -e 's/^.*"values":\[\[//' -e 's/\],\[/\n/g' -e 's/,/ /g' -e 's/]].*$//' | tr -d '\\"' > /dev/shm/rtl_433-kuhinja-temperature +curl -G 'http://10.60.0.89:8086/query' --data-urlencode "db=telegraf" --data-urlencode "epoch=s" --data-urlencode "q=SELECT \"temperature_C\" FROM \"rtl_433\" WHERE time > now() - $INTERVAL AND \"topic\"='rpi2/rtl_433/influx' AND \"rid\" = '150' or \"rid\" = '16'" | sed -e 's/^.*"values":\[\[//' -e 's/\],\[/\n/g' -e 's/,/ /g' -e 's/]].*$//' | tr -d '\\"' > /dev/shm/rtl_433-soba-temperature curl -G 'http://10.60.0.89:8086/query' --data-urlencode "db=telegraf" --data-urlencode "epoch=s" --data-urlencode "q=SELECT mean(\"value\"),spread(\"value\") FROM \"mqtt_consumer\" WHERE time > now() - $INTERVAL AND \"topic\"='stat/boiler/DS18B20/temperature'" | jq '.results[0].series[0].values[0][1,2]' > /dev/shm/temperature.mean.spread curl -G 'http://10.60.0.89:8086/query' --data-urlencode "db=telegraf" --data-urlencode "epoch=s" --data-urlencode "q=SELECT mean(\"value\"),spread(\"value\") FROM \"mqtt_consumer\" WHERE time > now() - $INTERVAL AND \"topic\"='stat/boiler/DHT22/humidity'" | jq '.results[0].series[0].values[0][1,2]' > /dev/shm/humidity.mean.spread 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() - $INTERVAL 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 -#curl -G 'http://10.60.0.89:8086/query' --data-urlencode "db=telegraf" --data-urlencode "epoch=s" --data-urlencode "q=SELECT \"humidity\",\"channel\" FROM \"rtl_433\" WHERE time > now() - $INTERVAL AND \"topic\"='rpi2/rtl_433/influx' AND \"id\" = '9'" | sed -e 's/^.*"values":\[\[//' -e 's/\],\[/\n/g' -e 's/,/ /g' -e 's/]].*$//' | tr -d '\\"' > /dev/shm/rtl_433-9-humidity -curl -G 'http://10.60.0.89:8086/query' --data-urlencode "db=telegraf" --data-urlencode "epoch=s" --data-urlencode "q=SELECT \"humidity\",\"channel\" FROM \"rtl_433\" WHERE time > now() - $INTERVAL AND \"topic\"='rpi2/rtl_433/influx' AND \"rid\" = '172'" | sed -e 's/^.*"values":\[\[//' -e 's/\],\[/\n/g' -e 's/,/ /g' -e 's/]].*$//' | tr -d '\\"' > /dev/shm/rtl_433-9-172-humidity -curl -G 'http://10.60.0.89:8086/query' --data-urlencode "db=telegraf" --data-urlencode "epoch=s" --data-urlencode "q=SELECT \"humidity\",\"channel\" FROM \"rtl_433\" WHERE time > now() - $INTERVAL AND \"topic\"='rpi2/rtl_433/influx' AND \"rid\" = '75'" | sed -e 's/^.*"values":\[\[//' -e 's/\],\[/\n/g' -e 's/,/ /g' -e 's/]].*$//' | tr -d '\\"' > /dev/shm/rtl_433-9-75-humidity -curl -G 'http://10.60.0.89:8086/query' --data-urlencode "db=telegraf" --data-urlencode "epoch=s" --data-urlencode "q=SELECT \"humidity\",\"channel\" FROM \"rtl_433\" WHERE time > now() - $INTERVAL AND \"topic\"='rpi2/rtl_433/influx' AND \"rid\" = '141'" | sed -e 's/^.*"values":\[\[//' -e 's/\],\[/\n/g' -e 's/,/ /g' -e 's/]].*$//' | tr -d '\\"' > /dev/shm/rtl_433-9-141-humidity +curl -G 'http://10.60.0.89:8086/query' --data-urlencode "db=telegraf" --data-urlencode "epoch=s" --data-urlencode "q=SELECT \"humidity\",\"channel\" FROM \"rtl_433\" WHERE time > now() - $INTERVAL AND \"topic\"='rpi2/rtl_433/influx' AND \"rid\" = '1111' or \"rid\" = '47'" | sed -e 's/^.*"values":\[\[//' -e 's/\],\[/\n/g' -e 's/,/ /g' -e 's/]].*$//' | tr -d '\\"' > /dev/shm/rtl_433-vani-humidity +curl -G 'http://10.60.0.89:8086/query' --data-urlencode "db=telegraf" --data-urlencode "epoch=s" --data-urlencode "q=SELECT \"humidity\",\"channel\" FROM \"rtl_433\" WHERE time > now() - $INTERVAL AND \"topic\"='rpi2/rtl_433/influx' AND \"rid\" = '75' or \"rid\" = '211'" | sed -e 's/^.*"values":\[\[//' -e 's/\],\[/\n/g' -e 's/,/ /g' -e 's/]].*$//' | tr -d '\\"' > /dev/shm/rtl_433-kupaona-humidity +curl -G 'http://10.60.0.89:8086/query' --data-urlencode "db=telegraf" --data-urlencode "epoch=s" --data-urlencode "q=SELECT \"humidity\",\"channel\" FROM \"rtl_433\" WHERE time > now() - $INTERVAL AND \"topic\"='rpi2/rtl_433/influx' AND \"rid\" = '143' or \"rid\" = '209'" | sed -e 's/^.*"values":\[\[//' -e 's/\],\[/\n/g' -e 's/,/ /g' -e 's/]].*$//' | tr -d '\\"' > /dev/shm/rtl_433-kuhinja-humidity + +__SHELL__ +GRAY=`echo $QUERY_STRING | grep -i gray | wc -l` + +tz_secs=`date +%:z | cut -d: -f1 | sed -e 's/^+//' -e 's/$/ * 3600/' | bc` 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 +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` ; gray=$GRAY ; lines=$LINES ; interval=\"$INTERVAL\" ; tz_secs=$tz_secs" temp2.gnuplot -GRAY=`echo $QUERY_STRING | grep -i gray` -if [ ! -z "$GRAY" ] ; then +if [ "$GRAY" = 1 ] ; then convert /dev/shm/temp2.png -gravity center -extent 600x800 -colorspace Gray /dev/shm/temp2-gray.png GRAY="-gray" +else + GRAY="" fi set > /dev/shm/temp2.cgi.vars +lines_checked="" +test "$LINES" = 1 && lines_checked="checked" + +if echo $HTTP_USER_AGENT | grep Mozilla > /dev/null ; then + echo "Content-type: text/html\r\n\r\n" + cat << __HTML__ + +
+ + + + + + +
+ + +__HTML__ + exit 0 +fi + echo "Location: $REQUEST_SCHEME://$SERVER_NAME:$SERVER_PORT/temp2$GRAY.png" echo