Hi!
For the
HP10, Ecowitt offers an upload service for webcam images and time lapse videos at Ecowitt.net.
However, these pictures as well as the time-lapse videos are difficult to integrate into your own web pages and the holding time of the videos @Ecowitt.net is unfortunately only 7 days.
In addition, I personally miss the essential weather data of the weather station:
[ You are not allowed to view attachments ]
Fortunately, the HP10 offers an easy-to-use interface to generate your own images and videos. I had already written this in my
review of the HP10.
And that too, completely locally and without the aid of any cloud services!
All that is required for this solution is a 24/7 Linux system (possibly also under Windows with WSL - untested).
Since the script generates local files, the possibilities for further processing and integration into existing web pages are almost unlimited.
So I use the single images and the time-lapse videos (after a few minor changes in the original PWSDashboard files) on my
PWSDashboard page.
I can give more information about the necessary changes in the PWSDashboard files here.
However, the pictures and videos can be integrated everywhere in this way, because the names are always the same and the files are overwritten when they are transferred to the target server.
If you already use FOSHKplugin, you can adopt this script without major changes. However, a few more tools may have to be installed.
Required are ffmpeg, curl, bc and possibly recode - these are to be installed with the respective package manager.
For Debian-like distributions this is done with
sudo apt-get install ffmpeg curl bc recode
The weather data to be embedded is taken from FOSHKplugin via http/GET and embedded in the individual images.
Users who have not yet used FOSHKplugin - but instead use a "more modern" console with http query option - can still embed the current weather data in the webcam images. I have already written more about this nice feature
here.
For processing the JSON responses of the console, another package has to be installed: jq (sudo apt-get install jq).
Basically, this script works with ANY other camera that can output a current image via a software trigger. However, depending on the camera model and possibilities, further adjustments are necessary.
The actual procedure is always:
- fetch the current image from the camera and save it as YYMMDDHHMM-capture.jpg
- if necessary, fetch weather data; integrate as overlay via ffmpeg and save as new image YYMMDDHHMM-snapshot.jpg
- Copy the last file as capture.jpg or snapshot.jpg and transfer it via FTP to the target server
- at midnight, create a time-lapse video as YYMMDD-snapshot.mp4 (or YYMMDD-capture.mp4) from all locally available YYMMDDHHMM*.jpg files using ffmpeg
- copy YYMMDD-snapshot.mp4 (or YYMMDD-capture.mp4) to snapshot.mp4 (or capture.mp4) and transfer to the target server via FTP
- when called with parameter -timelapse, create a tlpartial.mp4 from the existing YYMMDDHHMM*.jpg possible up to this point and transfer it to the target server
It is advisable to start this script via cron every n minutes - this will then fetch a new image from the camera every n minutes, store it locally and transfer it to the server as a single image.
In addition, there is the possibility of partial time-lapse videos. These can also be started at set times via cron. The script has to be started with the additional parameter -timelapse.
In my case, an image is generated for the webcam every minute and uploaded to the web server. In addition, a time-lapse video is generated at regular intervals from the images available up to that time:
*/1 * * engel /home/engel/getHP10/getHP10dm.sh
0 10,12,14,16,18 * * * engel /home/engel/getHP10/getHP10dm.sh -timelapse
About the configuration:
The main changes are made in the front part of the script between the two "##################################################################" lines.
NAM defines the name, which is displayed somewhat larger at the bottom left of the screen. CAM defines the IP address of the HP10 camera.
For the query of the current weather data (here via FOSHKplugin), the source of the data is defined with ADR.
If you only want pictures or time-lapse videos during daylight - as is the case with Ecowitt.net - use daymode=true. In this case, only pictures between sunrise (minus offset in seconds) and sunset (plus offset in seconds) are triggered.
To calculate sunrise and sunset
¹, the geographic coordinates must be specified with lat/lon. The offset can be used to specify how many seconds before sunrise or after sunset the pictures are to be fetched from the camera.
If you want to do without the weather data in the picture and video, simply set EMB to false in the script. This means that the weather data is not displayed in the image.
TIM defines the format for displaying the time in the image (lower right).
To make the values of the weather station easier to read in the picture, they are displayed in a block with a slightly different background. BLK can be used to determine whether this block should have a dark (black) or light (white) background or no background (none) at all.
JPGDIR AND TLVDIR define the local directories for pictures and videos. These directories are created as needed - according to the rights of the user context. The names specified in this configuration block (captname, snapname, partname and tlvname) specify the output name of the respective file on the remote server.
Of course, it is also important to specify the correct server name and credentials for access via ftp so that the upload to the target server works.
Important:
So far, no images have been deleted - so the storage requirement grows daily! At least you have the possibility to create a new time-lapse video afterwards.
For productive operation, however, a solution for automatically deleting the pictures (and videos if necessary) should be built in!
Depending on the selected resolution of the individual images and the frequency of the image recording, quite a few MByte per day can accumulate - in this case approx. 120KByte per minute per individual image and with currently approx. 10 hours between sunrise and sunset, 70MByte per day for the individual images as well as approx. double the amount for the time-lapse videos.
If you have any questions, problems or suggestions for improvement, please reply here in the thread.
¹The calculation of sunrise and sunset within a bash script is based on a solution found in the
Web.
A few words about the picture quality:
The camera is currently placed indoors behind a window with a fly screen. I hope to find a solution for mounting and power supply outside soon. Then the pictures should look a bit better - here it is only meant to demonstrate the possibilities. Sorry!
Regards, Oliver
#!/bin/bash
# Script for gathering the current snapshot of a local HP10 camera with
# integration of current real time data via FOSHKplugin
# creates a capture.jpg & snapshot.jpg (& YYMMDDHHMMSS-snapshot.jpg)
# sunrise/sunset based on https://www.anginf.de/?p=138
#
# needs: ffmpeg, curl, bc, foshkplugin & recode or jq & http-aware station
# put the script in an interval of your choice in the crontab
# 2do: lightning
# Phantasoft, Oliver Engel 02.02.2023, 30.09.2023
# v0.1d better ffmpeg compatibility; don't try to send files without specified FTPLOC
PRG=getHP10dm
VER=0.1d
##################################################################
# name the cam (bottom left)
NAM="Hohen Neuendorf, Brandenburg" # you may specify any name here
# set the camera ip
CAM=192.168.15.182 # ip address of the HP10 camera
# ip address of FOSHKplugin host to gather weather data from
ADR="http://192.168.15.236:8080" # for embedded values
# daymode: only capture from sunrise-offset till sunset+offset
daymode=true # do not grab snapshots at night
offset=3600 # before/after offset 3600 = +/-1h
lat="52.6695" # latitude
lon="13.2665" # longitude
# embedd some weather station values
EMB=true # use false to skip
# time format (bottom right)
now=`date +%s` # current local time
TIM=`date -d @${now} '+%d.%m.%Y %H:%M:%S'|sed 's/:/\\\:/g'` # TIM=`date -d @${now} '+%Y/%m/%d %H:%M:%S'|sed 's/:/\\\:/g'`
# define block style
BLK="black" # choose block style: none, black, grey, white
# local output destination dir
JPGDIR="/home/engel/getHP10/jpg/" # define a local output path here
captname=capture.jpg # name for raw input file
snapname=snapshot.jpg # name for file with embedded weather data
# enable time lapse video
TLV=true # uncomment to enable time lapse video
TLVDIR="/home/engel/getHP10/mp4/" # define a local output path here
partname=tlpartial.mp4 # partial time lapse video triggered via parameter -timelapse
tlvname=timelapse.mp4 # complete time lapse file generated on new day
# remote destination for output file
#DST="https://yourdomain.tld/some/where/specialscript.php" # uncomment to transfer via http/POST
# remote destination and credentials for ftp(s) access
#FTPLOC=ftp://yourdomain.tld/path/to/img-dir/ # uncomment and adjust to use FTP
FTPUSER=username
FTPPASS=password
###################################################################
calcSunStamps() {
zoneinfo=$(date -d @${now} +%z) # time zone
T=$(date -d @${now} +%j) # day of year
pi="3.14159265358979323844" # pi=`echo "4*a(1)" | bc -l`
rad=$(echo "${pi}/180" | bc -l)
h=$(echo "-(5/6)*(${rad})" | bc -l) # Höhe des Sonnenmittelpunkts bei sunrise: Radius+Refraktion
BreiteRAD=$(echo "${lat}*${rad}" | bc -l)
sonnendekl=$(echo "0.409526325277017*s(0.0169060504029192*(${T}-80.0856919827619))" | bc -l)
sonnendeklDEG=$(echo "${sonnendekl} / ${rad}" | bc -l)
arccosint=$(echo "(s(${h})-s(${BreiteRAD})*s(${sonnendekl}))/(c(${BreiteRAD})*c(${sonnendekl}))" | bc -l)
arccosintsign=${arccosint:0:1}
if [ ${arccosintsign} == "-" ]; then usesign="+"; else usesign="-"; fi
arc2cosint=$(echo "(${arccosint}) * (${arccosint})" | bc -l)
acoszeit=$(echo "${pi}/2 ${usesign} a(sqrt(${arc2cosint} / (1 - (${arc2cosint}) ) ) ) " | bc -l)
zeitdiff=$(echo "12*${acoszeit}/${pi}" | bc -l) # KORREKT!
zeitgleich=$(echo "-0.170869921174742*s(0.0336997028793971 * ${T} + 0.465419984181394) - 0.129890681040717*s(0.0178674832556871*${T} - 0.167936777524864)" | bc -l)
sunrise=$(echo "12-(${zeitdiff})-(${zeitgleich})-(${lon}/15)${zoneinfo:0:3}" | bc -l)
sunset=$(echo "12+(${zeitdiff})-(${zeitgleich})-(${lon}/15)${zoneinfo:0:3}" | bc -l)
today=$(date -d 0 +%s)
sunrisestamp=$(echo "scale=0;$today+$sunrise*3600/1-$offset"|bc -l) # sunrise time stamp with offset!
sunsetstamp=$(echo "scale=0;$today+$sunset*3600/1+$offset"|bc -l) # sunset time stamp with offset!
}
# save the current time
datestr=`date -d @${now} +%y%m%d%H%M%S`
if [ "$daymode" == true ]; then # calculate sunrise/sunset
calcSunStamps
fi
# make sure dirs exist
[ ! -d ${JPGDIR} ] && mkdir "${JPGDIR}"
[ ! -d ${TLVDIR} ] && mkdir "${TLVDIR}"
# main
curDate=`date -d @${now} +%y%m%d`
if [ "$1" = "-timelapse" ]; then paramTL=true; else paramTL=false; fi
if [ "$paramTL" == true ]; then # check whether param set - if so, just create a TLV
find ${JPGDIR}${curDate}*.jpg -size 0 -delete
ffmpeg -y -hide_banner -loglevel error -framerate 25 -pattern_type glob -i "${JPGDIR}${curDate}*.jpg" -pix_fmt yuv420p -c:v libx264 -crf 17 "${TLVDIR}${curDate}-${partname}"
# make a local copy
cp -f ${TLVDIR}${curDate}-${partname} ${TLVDIR}${partname}
# send video to webspace
if [ $FTPLOC ] && [ $FTPLOC != "" ]; then
curl --silent -p --insecure --ssl "${FTPLOC}" --user "${FTPUSER}:${FTPPASS}" -T ${TLVDIR}${partname}
fi
else # regular image creation
if ([ "$daymode" == true ] && [ ${now} -ge ${sunrisestamp} ] && [ ${now} -le ${sunsetstamp} ]) || [ "$daymode" == false ]; then
# get the current picture
curl --silent -o ${JPGDIR}${captname} "http://${CAM}/capture"
# for additional weather data in the picture
# if you don't use FOSHKplugin but a current GW1100/GW2000 or HP25xxC you may use it's realtime data instead:
# ADR=192.168.15.229
# temp=`curl -s http://${ADR}/get_livedata_info?|jq ".common_list[0].val"|sed 's/\"//g'`
# humidity=`curl -s http://${ADR}/get_livedata_info?|jq ".common_list[1].val"|sed 's/\"//g'|sed 's/\%//g'`
# ... - see: https://www.wxforum.net/index.php?topic=43811.msg453151#msg453151
if [ "$EMB" == true ]; then
# you may add Logging\IGNORE_LOG = crondaemon in FOSHKplugin config file and "\&crondaemon" to the getvalue-URL (backslash to escape the &) to prevent the output of these lines
tempc=`curl ${ADR}/getvalue?key=tempc 2>/dev/null`
humidity=`curl ${ADR}/getvalue?key=humidity 2>/dev/null`
baromrelhpa=`curl ${ADR}/getvalue?key=baromrelhpa 2>/dev/null`
windspeedkmh=`curl ${ADR}/getvalue?key=windspeedkmh 2>/dev/null`
dailyrainmm=`curl ${ADR}/getvalue?key=dailyrainmm 2>/dev/null`
leafwetness_ch1=`curl ${ADR}/getvalue?key=leafwetness_ch1 2>/dev/null`
solarradiation=`curl ${ADR}/getvalue?key=solarradiation 2>/dev/null`
uv=`curl ${ADR}/getvalue?key=uv 2>/dev/null`
sunhours=`curl ${ADR}/getvalue?key=sunhours 2>/dev/null`
wnowtxt=`curl ${ADR}/getvalue?key=wnowtxt 2>/dev/null|recode l1..utf8`
wprogtxt=`curl ${ADR}/getvalue?key=wprogtxt 2>/dev/null|recode l1..utf8`
dateutc=`curl ${ADR}/getvalue?key=dateutc 2>/dev/null|sed 's/:/\\\:/g'`
# modify block definiton
if [ $BLK == "black" ]; then
BLOCK="drawbox=y=1075:color=black@0.5:width=iw:height=125:t=h,"
elif [ $BLK == "grey" ]; then
BLOCK="drawbox=y=1075:color=black@0.4:width=iw:height=125:t=h,"
elif [ $BLK == "white" ]; then
BLOCK="drawbox=y=1075:color=white@0.4:width=iw:height=125:t=h,"
else
BLOCK=""
fi
# stamp weather data into the picture
ffmpeg -y -hide_banner -loglevel error -i ${JPGDIR}${captname} -vf "[in] \
$BLOCK \
drawtext=font=monospace:fontsize=25:fontcolor=white:text='${NAM}':x=10:y=(h)-30, \
drawtext=font=monospace:fontsize=25:fontcolor=white:text='${TIM}':x=(w)-295:y=(h)-30, \
\
drawtext=font=monospace:fontsize=20:fontcolor=white:text='Temperatur\:\ ${tempc}\°C':x=10:y=(h)-120, \
drawtext=font=monospace:fontsize=20:fontcolor=white:text='Luftfeuchte\:\ ${humidity}\\\\\%':x=10:y=(h)-95, \
drawtext=font=monospace:fontsize=20:fontcolor=white:text='Luftdruck\:\ ${baromrelhpa}hPa':x=10:y=(h)-70, \
\
drawtext=font=monospace:fontsize=20:fontcolor=white:text='Wind\:\ ${windspeedkmh}kmh':x=400:y=(h)-120, \
drawtext=font=monospace:fontsize=20:fontcolor=white:text='Regen/Tag\:\ ${dailyrainmm}mm':x=400:y=(h)-95, \
drawtext=font=monospace:fontsize=20:fontcolor=white:text='Blattfeuchte\:\ ${leafwetness_ch1}\\\\\%':x=400:y=(h)-70, \
\
drawtext=font=monospace:fontsize=20:fontcolor=white:text='Solar\:\ ${solarradiation}W/m²':x=790:y=(h)-120, \
drawtext=font=monospace:fontsize=20:fontcolor=white:text='UVI\:\ ${uv}':x=790:y=(h)-95, \
drawtext=font=monospace:fontsize=20:fontcolor=white:text='Sonnenstd\:\ ${sunhours}h':x=790:y=(h)-70, \
\
drawtext=font=monospace:fontsize=20:fontcolor=white:text='Wetterlage\:\ ${wnowtxt}':x=1190:y=(h)-120, \
drawtext=font=monospace:fontsize=20:fontcolor=white:text='Vorhersage\:\ ${wprogtxt}':x=1190:y=(h)-95, \
drawtext=font=monospace:fontsize=20:fontcolor=white:text='UTC-Zeit\:\ ${dateutc}':x=1190:y=(h)-70 \
\
[out]" ${JPGDIR}${snapname} 2>/dev/null
fi
# define filename to upload & create frame for time lapse video
if [ "$EMB" == true ]; then outname=${snapname}; else outname=${captname}; fi
if [ "$TLV" == true ]; then cp ${JPGDIR}${outname} ${JPGDIR}${datestr}-${outname}; fi
# upload via http/POST
if [ $DST ] && [ $DST != "" ]; then
curl -k -F "image=@${JPG}" -F "user=user" -F "password=password" -F "filename=${JPGDIR}${outname}" -F "fwd_type=SAVE" ${DST}
fi
# upload via ftp(s)
if [ $FTPLOC ] && [ $FTPLOC != "" ]; then
# unsecured ftp
#curl --silent -p --insecure "${FTPLOC}" --user "${FTPUSER}:${FTPPASS}" -T ${JPGDIR}${outname}
# ftps
curl --silent -p --insecure --ssl "${FTPLOC}" --user "${FTPUSER}:${FTPPASS}" -T ${JPGDIR}${outname}
fi
fi
# check new day - if so create a time lapse video
if [ -f ${JPGDIR}${PRG}last.txt ]; then wasDate=$(<${JPGDIR}${PRG}last.txt); else wasDate=${curDate}; fi
if [ "$TLV" == true ] && [ "$curDate" != "$wasDate" ]; then
echo ${curDate}>${JPGDIR}${PRG}last.txt # do this first to prevent another start
find ${JPGDIR}${wasDate}*.jpg -size 0 -delete
ffmpeg -y -hide_banner -loglevel error -framerate 25 -pattern_type glob -i "${JPGDIR}${wasDate}*.jpg" -pix_fmt yuv420p -c:v libx264 -crf 17 "${TLVDIR}${wasDate}-${tlvname}"
# make a local copy
cp -f ${TLVDIR}${wasDate}-${tlvname} ${TLVDIR}${tlvname}
# send video to webspace
if [ $FTPLOC ] && [ $FTPLOC != "" ]; then
curl --silent -p --insecure --ssl "${FTPLOC}" --user "${FTPUSER}:${FTPPASS}" -T ${TLVDIR}${tlvname}
fi
# delete the local partial time lapse video
#rm -f ${TLVDIR}${wasDate}-${partname}
# delete all local already processed images
#rm -f ${JPGDIR}${wasDate}*.jpg
fi
echo ${curDate}>${JPGDIR}${PRG}last.txt
fi