Page 1 of 1

Bash scrip

Posted: Tue 10 Jul 2018 11:26 pm
by dazza1223
Hi has any one made bash scrip to take snapshot off a ip cam and over lay in with data?

Re: Bash scrip

Posted: Tue 10 Jul 2018 11:56 pm
by ConligWX
yep :)

I run mine every minute I think with crontab. something like this:

camdataT.txt Template processed realtime.

Code: Select all

Temp: <#temp>°C - Press: <#press> hPa - Hum: <#hum>% - Wind: <#wspeed> mph(<#currentwdir>) - Rain: <#rfall> mm - UV Index: <#UV> - SolarRad: <#SolarRad> W/m² - CloudBase: <#cloudbase>.
then minute script

Code: Select all

#!/bin/sh
#
#set variable yday to be like 20100208
#
#tday=$(date -d today +%Y%m%d%H%M%S);
#stamp=$(date '+DATE: %d/%m/%y%nTIME:%H:%M:%S');
tday=$(date +%Y%m%d%H%M%S);
#stamp=$(date +%Y%m%d);
#
# get weather image
wget --auth-no-challenge --http-user=xxxxxx --http-password=xxxxxxxx "http://xxx.xxx.xx.xxx/cgi/jpg/image.cgi" -O "/share/weather/sky1.jpg";
# next 2 lines add weather info
testdata="$(/bin/cat /share/weather/camdata.txt)";
testdata1=`date +"%A %d-%b-%Y %R %Z"`;

# add layers and text to image
convert -fill RoyalBlue4 -draw "fill-opacity 0.4 rectangle 0 0 1280 25" \
-fill red -draw "fill-opacity 0.6 rectangle 0 26 1280 27" \
-fill RoyalBlue4 -draw "fill-opacity 0.7 rectangle 0 695 1280 720" \
-fill red -draw "fill-opacity 0.6 rectangle 0 693 1280 694" \
-fill white -pointsize 18 -font /share/script/arialbold.ttf -draw "text 10,20 'Conlig Weather Station:  $testdata1 - ICODOWNN2 - www.conligwx.org'" \
-fill yellow -pointsize 18 -draw "text 10,715 '$testdata'" /share/weather/sky1.jpg  /share/weather/skywebcam.jpg

# convert image.jpg to 150kb for WUnderground
convert /share/weather/skywebcam.jpg -define jpeg:extent=150kb /share/weather/image.jpg

# ftp webcam to wunderground
lftp -e 'put /share/weather/image.jpg; bye' -u xxxxxxxx,passwordxxxx webcam.wunderground.com -d
Image

Re: Bash scrip

Posted: Wed 11 Jul 2018 9:14 am
by dazza1223
o Simon thank you for that!!! i did have a Bash scrip but it keep crashing and makeing the imges go all funny? i will try and add yours..... but i will pont out this tho i do think it very nice that some ppl on here do share there hard work and give it to other and includeing you :D

Re: Bash scrip

Posted: Sun 26 Aug 2018 2:24 pm
by Big Daddy
Thanks for this post Simon. Inspired with the idea I did the same for my webcams. All generated on a PI (which also runs my CumuusMX) and managed to integrate a background image using Imagemagick so it blends in with the rest of my website.

http://midlifedad.me.uk/weather/webcam_north.php

Andy

Re: Bash scrip

Posted: Sun 26 Aug 2018 3:30 pm
by water01
Very nice, love the time lapse. Is all that running on the Pi?

Assume the template is home built?

Re: Bash scrip

Posted: Sun 26 Aug 2018 7:36 pm
by ConligWX
I do have a tinelapse script too if you guys want it

I am in Berlin for a few days but back home hopefully on Wednesday evening.

Re: Bash scrip

Posted: Sun 26 Aug 2018 10:50 pm
by dazza1223
yes plz mate thanks

Re: Bash scrip

Posted: Tue 28 Aug 2018 10:17 am
by Big Daddy
The Timelapse runs on an old Windows PC using some external software (IPTimelapse) as the PI wasnt able to handle creating 3 video images. It snaps frames using rtsp from my cameras every 10 seconds and then compiles the videos just after midnight each day. Its scheduled to captue between dawn and dusk using lat / long plus I add a bias before and after dusk to capture dark to light and vice versa.

The template started life as a WeatherByYou template "Weather Blues 2" (there is a section in the Sandaysoft forum) but as I learnt more I added more. I cant take all the credit for it, most of that goes to Jacques who developed the original template.

Andy

Re: Bash scrip

Posted: Tue 28 Aug 2018 2:16 pm
by water01
OK thanks wondered if the PI was capable of doing the time lapse as well as everything else!!

Re: Bash scrip

Posted: Tue 28 Aug 2018 2:21 pm
by dazza1223
i think it will be OK as i tried it with when i was running cumulus /SQL web server etc it a bit slow off making it but it dose the job and have u got the pi 3?

Re: Bash scrip

Posted: Thu 30 Aug 2018 1:11 pm
by ConligWX
ok had a look at the script which did work but have done some editing due to the fact uploading to WU for webcams should be no more than 2 minutes apart. 1 minute intervals will most likely be ignored.

so with that I suggest one crontab entry for uploading to WU, there by a separate script or command line entry.

every 2 minutes.

Code: Select all

# ftp webcam to wunderground
#
lftp -e 'put /share/htdocs/weather/image.jpg; bye' -u XXXXXXXX,xxxxxxxx webcam.wunderground.com
then 2 other scripts,

one to handle the image layers and create image and timed filenames:

Code: Select all

#!/bin/sh
#
# set variable yday to be like 20100208
#
# tday=$(date -d today +%Y%m%d%H%M%S);
# stamp=$(date '+DATE: %d/%m/%y%nTIME:%H:%M:%S');
tday=$(date +%Y%m%d%H%M%S);

# stamp=$(date +%Y%m%d);
#
# get weather image
wget --auth-no-challenge --http-user=xxxxx --http-password=xxxxxx "http://x.x.x.x/cgi/jpg/image.cgi" -O "/share/htdocs/weather/sky1.jpg";

# next 2 lines add weather info
#
testdata="$(/bin/cat /share/htdocs/weather/camdata.txt)";
testdata1=`date +"%A %d-%b-%Y %R %Z"`;

# convert -fill RoyalBlue4 -draw "fill-opacity 0.4 rectangle 0 0 1280 25" \
#
convert -fill RoyalBlue4 -draw "fill-opacity 0.4 rectangle 0 0 1280 25" \
-fill red -draw "fill-opacity 0.6 rectangle 0 26 1280 27" \
-fill RoyalBlue4 -draw "fill-opacity 0.7 rectangle 0 695 1280 720" \
-fill red -draw "fill-opacity 0.6 rectangle 0 693 1280 694" \
-fill white -pointsize 18 -font /share/db_backup/script/arialbold.ttf -draw "text 10,20 'Conlig Weather Station:  $testdata1 - INEWTOWN20 - www.conligwx.org'" \
-fill yellow -pointsize 18 -draw "text 10,715 '$testdata'" /share/htdocs/weather/sky1.jpg  /share/htdocs/weather/skywebcam.jpg

# convert image.jpg to 150kb for WUnderground
# 
convert /share/htdocs/weather/skywebcam.jpg -define jpeg:extent=150kb /share/htdocs/weather/image.jpg

# add timestamp to filename for image history and video timelapse.
cp /share/htdocs/weather/sky.jpg /share/htdocs/weather/image-history/video@"$tday".jpg;
the other to create a timelapse video from the image history (run once a day) atapprox 00:01

Code: Select all

#!/bin/sh
#maketimelapse movie
#
#set variable yday to be like 20100208
#
#yday=$(date +%Y%m%d %s -d $(( $(date +%s) - 86400 )));

yday=$(date -d "1 day ago" +%Y%m%d);
#
# make directory for yesterdays images
#
mkdir /share/htdocs/weather/image-history/"$yday";
# mkdir /volume1/Web/fishcam/image-history/"$yday";
#
# move yesterdays images to new directory sample image name is video@20100208000313.jpg
#
mv /share/htdocs/weather/image-history/video@"$yday"??????.jpg /share/htdocs/weather/image-history/"$yday"/;
# remove 0 byte files test script. find . -type f -size 0 | xargs ls -ld
cd /share/htdocs/weather/image-history/"$yday";
#find . -type f -size 0 | xargs rm;
# mv /volume1/Web/fishcam/image-history/video@"$yday"??????.jpg /volume1/Web/fishcam/image-history/"$yday"/;
# remove 0 byte files test script.
# cd /volume1/Web/fishcam/image-history/video@"$yday"??????.jpg /volume1/Web/fishcam/image-history/"$yday";
# /usr/bin/find . -type f -size 0 | xargs rm;
#
# create sequential files for ffmpeg to process apparently they have to be sequential for ffmpeg
#
x=1;
for i in $(ls -r -t /share/htdocs/weather/image-history/"$yday"/*jpg);
do counter=$(printf %04d $x);
ln -s "$i" /share/Public/tmp/img"$counter".jpg;
x=$(($x+1));
done;
#
#process with ffmpeg
#
# /volume1/.@plugins/AppCentral/upnp-server-v2/bin/ffmpeg -r 15 -f image2 -i /volume1/tmp/img%04d.jpg -qmax 9 /volume1/Web/weather/timelapse/"$yday".avi;
# /usr/local/bin/ffmpeg -r 15 -f image2 -i /volume1/tmp/img%04d.jpg -qmax 9 /volume1/Web/weather/timelapse/"$yday".avi;
ffmpeg -r 15 -f image2 -i /share/Public/tmp/img%04d.jpg -qmin 16 -qmax 26 /share/htdocs/weather/image-history/timelapse/"$yday".avi;
#
#tidy
#
rm /share/Public/tmp/img????.jpg;
#
# repeat final stages for fishcam..
#
# x=1;
# for i in $(ls -r -t /volume1/Web/fishcam/image-history/"$yday"/*jpg);
# do counter=$(printf %04d $x);
# ln "$i" /volume1/tmp/img"$counter".jpg;
# x=$(($x+1));
# done;
#
#process with ffmpeg
#
# /usr/local/bin/ffmpeg -r 15 -f image2 -i /volume1/tmp/img%04d.jpg -qmax 9 /volume1/Web/fishcam/timelapse/"$yday".avi;
# /volume1/Download/FFMPEG/ffmpeg -r 15 -f image2 -i /volume1/tmp/img%04d.jpg -qmax 9 /volume1/Web/fishcam/timelapse/"$yday".avi;
#
#tidy
#
# rm /volume1/tmp/img????.jpg;
#
#zip up yesterdays images to keep file count down
#

# /usr/builtin/bin/zip -rm0 /volume1/Web/fishcam/image-history/"$yday" /volume1/Web/fishcam/image-history/"$yday"
zip -rm9 /share/htdocs/weather/image-history/"$yday" /share/htdocs/weather/image-history/"$yday"
Please note I have not run the timelapse one for sometime and may differ from you own setups but it should give you an idea of how to create a timelapse video from your images you create from the previous day. I dont take credit for this, most of which was give to me by a friend (ho66es), and I had tweaked it to my setup and values I wanted for my layers.

Also inclusive is my CamdataT.txt template processed by CumulusMX to camdata.txt

Code: Select all

Temp: <#temp>°C - Press: <#press> hPa - Hum: <#hum>% - Wind: <#wspeed> mph(<#currentwdir>) - Rain: <#rfall> mm - UV Index: <#UV> - SolarRad: <#SolarRad> W/m² - CloudBase: <#cloudbase>.
hope this helps someone.

PLEASE NOTE THESE SCRIPTS ARE TOTALLY UNSUPPORTED

Re: Bash scrip

Posted: Tue 12 May 2020 1:01 pm
by Sadgit
old post but this is exactly what I was looking for, so thank you!

Re: Bash scrip

Posted: Thu 14 May 2020 10:04 pm
by ConligWX
Sadgit wrote: Tue 12 May 2020 1:01 pm old post but this is exactly what I was looking for, so thank you!
no problem!