summaryrefslogtreecommitdiff
path: root/getpix.sh
diff options
context:
space:
mode:
authorst33v <github@f3rr3t.com>2016-12-29 15:42:20 +1100
committerst33v <github@f3rr3t.com>2016-12-29 15:42:20 +1100
commit3dc3dce55917e13e40182c1ba311c2782bc33c9c (patch)
tree9c2e90406693ca879edba1505a6e14650877f7bc /getpix.sh
parent6610463f97524004fc56736c1c7791013293322d (diff)
Merged sendpix into getpix; now loops over camz array
Diffstat (limited to 'getpix.sh')
-rwxr-xr-xgetpix.sh79
1 files changed, 44 insertions, 35 deletions
diff --git a/getpix.sh b/getpix.sh
index 743540d..cc8567a 100755
--- a/getpix.sh
+++ b/getpix.sh
@@ -4,59 +4,68 @@
# Copy and process photos from a cam-equipped raspi
########### Constants ##################
-campi="neatherd" # hard-code source hostname for the moment
+# campi="neatherd" # hard-code source hostname for the moment
wanWebServer="f3rr3t.com"
sourcedir="/home/st33v/pix" # where the image is on the source computer (i.e. $campi)
thisdir="/home/st33v/cams" # this directory (on this computer)
-threshold="2000" # minimum value of average pixel brightness. Tests if pic is too dark
+threshold="2000" # minimum value of average pixel brightness. Tests if pic is too dark
########### end Consts ################
-cd ${thisdir}
+# cam names in an array:
+declare -a camz=("neatherd" "lucerne")
+
+
########### Functions ##################
# get the filename of the most recent photo stored on this computer.
newestpicfunc () { newestpic=$(ls ${campi}/*.jpg -t | head -1); }
########### end Funcs #################
-# record the latest photo BEFORE we look for a new one
-newestpicfunc; oldpic=${newestpic}
-# echo "Before: oldpic is ${oldpic}"
+cd ${thisdir}
-# Copy any photos from the camera-equipped source ($campi)
-# This script is on a rapid timer so there should only ever be one photo (if any).
-scp ${campi}:${sourcedir}/*.jpg ${campi}/. 2>/dev/null
-# Delete the photo from the source computer.
-ssh $campi "rm ${sourcedir}/*.jpg" 2>/dev/null
-# cp ${oldpic} ${thisdir}${campi}/zzz.jpg # testing
+for campi in "$camz[@]}"
+do
+ {
+ # record the latest photo BEFORE we look for a new one
+ newestpicfunc; oldpic=${newestpic}
+ # echo "Before: oldpic is ${oldpic}"
-# get the filename of the NEW photo, it there is one
-newestpicfunc; newpic=${newestpic}
-#echo "After: newpic is ${newpic}"
+ # Copy any photos from the camera-equipped source ($campi)
+ # This script is on a rapid timer so there should only ever be one photo (if any).
+ scp ${campi}:${sourcedir}/*.jpg ${campi}/. 2>/dev/null
+ # Delete the photo from the source computer.
+ ssh $campi "rm ${sourcedir}/*.jpg" 2>/dev/null
+ # cp ${oldpic} ${thisdir}${campi}/zzz.jpg # testing
-if [[ "$oldpic" == "$newpic" ]] ; then
- # echo no new photos so exit now
- exit 0
-fi
+ # get the filename of the NEW photo, it there is one
+ newestpicfunc; newpic=${newestpic}
+ #echo "After: newpic is ${newpic}"
-# NeatHerd doesn't have enough RAM to perform image processing, so let's try it on STAN
+ if [[ "$oldpic" == "$newpic" ]] ; then
+ # echo no new photos so exit now
+ exit 0
+ fi
-# Check to see if the pic is too dark (i.e. taken at night)
-mean=$(identify -format %[mean] ${newpic} | sed s/[.].*//)
-# echo "mean is |$mean|"
-# too dark (nighttime)
-if [[ "${mean}" -lt "${threshold}" ]] ; then
- rm $newpic
-# echo mean of $mean is too low. It is nighttime.
- exit 13
-fi
+ # NeatHerd doesn't have enough RAM to perform image processing, so let's try it on STAN
-# Improve sharpness and resize photo, ready for upload to webserver
-# Break into two steps to avoid out-of-memory errors (OS kills process)
-convert ${newpic} -unsharp 1.5x1+0.7+0.02 temp.jpg
-convert temp.jpg -resize 33% -quality 70 ${newpic}
-rm temp.jpg
+ # Check to see if the pic is too dark (i.e. taken at night)
+ mean=$(identify -format %[mean] ${newpic} | sed s/[.].*//)
+ # echo "mean is |$mean|"
+ # too dark (nighttime)
+ if [[ "${mean}" -lt "${threshold}" ]] ; then
+ rm $newpic
+ # echo mean of $mean is too low. It is nighttime.
+ exit 13
+ fi
-scp /home/st33v/cams/$campi/$newpic $wanWebServer:/home/st33v/farm/cam/$campi/.
+ # Improve sharpness and resize photo, ready for upload to webserver
+ # Break into two steps to avoid out-of-memory errors (OS kills process)
+ convert ${newpic} -unsharp 1.5x1+0.7+0.02 temp.jpg
+ convert temp.jpg -resize 33% -quality 70 ${newpic}
+ rm temp.jpg
+ scp /home/st33v/cams/$campi/$newpic $wanWebServer:/home/st33v/farm/cam/$campi/.
+ }
+done
#. ~/cams/sendpix.sh
#exit(0) # force success exit code for fussy systemd