Page 1 of 1

cumulative raingraph with gnuplot

Posted: Tue May 17, 2011 9:15 pm
by pinto
Not exactly a graph definition, so feel free to move it.

Someone wants to test the folowing :?:
:!: Warning :!:
:!: Don't do it if you don't understand what exacly the scripts are doing :!:
Cumulative raingraph (sort of)
This is only tested with fake data, as we didn't get much rain, and no rain in the forecast for the next days.


create rainlogger.html with folowing contents:

Code: Select all

[actual_localdate] [day1_rain0_total_mm]
Drop it in /data/graphs/ of your meteohub system

Next run folowing shell-script every 5 minutes with cron:
Make it executable: chmod +x rainlogger.sh

Code: Select all

#!/bin/bash
hour=`date +%H`
minute=`date +%M`
mydate=`date +%Y%m%d%H%M%S`

if (( ($hour == 00) && ($minute < 10)  )); then

	echo "$mydate 0.00" >> /data/weather/rainlog-min5
else

wget -O /var/log/rain "http://127.0.0.1/meteohtml.cgi?file=rainlogger"
cat /data/weather/rainlog-min5 /var/log/rain > /var/log/temprain
mv /var/log/temprain /data/weather/rainlog-min5
 
fi
You are creating your own rainlog-min5 now
Next thing to do is creating the actual graph (you cannot use meteohub for it)
Last 24 hours example:rain-L24.sh

Code: Select all

#!/bin/bash
sleep 2
mydate=`date +%Y%m%d%H%M%S`
yesterday=`date --date='1 day ago' +%Y%m%d%H%M%S`
titledate=`date +%Y-%m-%d`
mytitle="Precipitation  ($titledate)"

/usr/local/bin/gnuplot << EOF
#
set terminal png 10 size 610,250 
set output "/data/uploads/rain-L24.png" 
set title "$mytitle" 
set grid 
set timefmt "%Y%m%d%H%M%S" 
set xdata time 
set xrange [ "$yesterday":"$mydate" ] 
set yrange [0:30] 
set format y "%0.0f mm" 
set xdata time 
set format x "%H:%M" 
plot '/data/weather/rainlog-min5' using 1:2 with steps lw 2 lt rgb "blue" title "rain" 
reset 
quit
EOF
Look at the line with "set output" and change it if you need, so you don't overwrite another graph.
If you use /data/uploads/ as the folder you write your graph,
meteohub takes care of the upload.

My crontab
I have these on the first lines

Code: Select all

#own scripts
*/5 * * * * /data/scripts/rainlogger.sh > /dev/null 2>&1
*/5 * * * * /data/scripts/rain-L24.sh > /dev/null 2>&1
#
As you can see, I created a folder /data/scripts to put my own scripts in.
I do it this way, because when I backup meteohub with rsync, I have a backup of them.

Jozef

Re: cumulative raingraph with gnuplot(tester needed)

Posted: Sun May 22, 2011 11:26 am
by pinto
We had some rain today, so far it's looking good, now only wait until the midnight reset.
rain-L24.png
rain-L24.png (2.74 KiB) Viewed 5472 times

Re: cumulative raingraph with gnuplot

Posted: Mon May 23, 2011 8:39 am
by pinto
And last 48 hours, midnight reset is working.
rain-L24.png
rain-L24.png (2.85 KiB) Viewed 5460 times

Re: cumulative raingraph with gnuplot

Posted: Mon Apr 16, 2012 5:49 pm
by Napajedlaci.cz
I have two questions:
First how the crontab to do? (where he edited, how)
Second as the graph created by upload via FTP to other graphs?

Re: cumulative raingraph with gnuplot

Posted: Mon Apr 16, 2012 9:17 pm
by pinto
Napajedlaci.cz wrote:I have two questions:
First how the crontab to do? (where he edited, how)
Second as the graph created by upload via FTP to other graphs?
:!: Are you sure you want to try this ?
You can brake your system and nobody can fix it for you.

Using cron is one of the basics in Linux, so I don't know it is a good idea to try this. It is possible you have to start from scratch if something is going wrong.
Don't say I did not warn you !!

Editing the crontab file:
crontab -e
and:
meteohub will upload the graph to the same location as your other graphs