cumulative raingraph with gnuplot

Definitions of graphs you want to share with us

Moderator: Mattk

Post Reply
pinto
Junior Boarder
Junior Boarder
Posts: 23
Joined: Thu Apr 14, 2011 7:33 pm
Contact:

cumulative raingraph with gnuplot

Post by pinto » Tue May 17, 2011 9:15 pm

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
Last edited by pinto on Mon May 23, 2011 8:37 am, edited 1 time in total.

pinto
Junior Boarder
Junior Boarder
Posts: 23
Joined: Thu Apr 14, 2011 7:33 pm
Contact:

Re: cumulative raingraph with gnuplot(tester needed)

Post by pinto » Sun May 22, 2011 11:26 am

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 4106 times

pinto
Junior Boarder
Junior Boarder
Posts: 23
Joined: Thu Apr 14, 2011 7:33 pm
Contact:

Re: cumulative raingraph with gnuplot

Post by pinto » Mon May 23, 2011 8:39 am

And last 48 hours, midnight reset is working.
rain-L24.png
rain-L24.png (2.85 KiB) Viewed 4094 times

User avatar
Napajedlaci.cz
Junior Boarder
Junior Boarder
Posts: 38
Joined: Fri Jul 30, 2010 1:10 pm
Location: Czech republic, Zlin
Contact:

Re: cumulative raingraph with gnuplot

Post by Napajedlaci.cz » Mon Apr 16, 2012 5:49 pm

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?
Napajedlaci.cz is very good weather station in Czech republic neer town Zlin.

pinto
Junior Boarder
Junior Boarder
Posts: 23
Joined: Thu Apr 14, 2011 7:33 pm
Contact:

Re: cumulative raingraph with gnuplot

Post by pinto » Mon Apr 16, 2012 9:17 pm

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

Post Reply