Skip to content

Instantly share code, notes, and snippets.

@Mario-F
Last active April 14, 2020 14:12
Show Gist options
  • Save Mario-F/c38ac7791c31ffab367e57cac611c6ab to your computer and use it in GitHub Desktop.
Save Mario-F/c38ac7791c31ffab367e57cac611c6ab to your computer and use it in GitHub Desktop.
Capture Timelapse on RPI with FTP Upload
#!/bin/bash
#
# Used to capture images on RaspberryPI and store on FTP Server
# German Blogpost: https://blog.fritschen.net/computer/raspberry/timelapse-langzeit-mit-raspberry-pi-zero/
#
# CONFIG - START
#
# FTP servers userdata
FTPSERVER=""
FTPUSER=""
FTPPASS=""
FTPPATH=""
# (Optional) Format of folder and filename timestamp
FOLDERSTAMP=$(date +%Y_%m_%d)
FILESTAMP=$(date +%y%m%d-%H%M)
# (Optional) File for saving the global increment value
INCFILE="/home/pi/incr.txt"
# (Optional) Temp directory for saving images (should not resides on the SD-Card)
LOCALPATH="/tmp"
# (Optional) Parameters for raspistill
RASPISTILLPARAMETERS=""
#
# CONFIG - END
#
# Get increment value and increment it
if [ ! -f "$INCFILE" ]; then
echo "0" > $INCFILE
fi
OLD_INCR=$(cat $INCFILE)
NEW_INCR=$((OLD_INCR+1))
echo "$NEW_INCR" > $INCFILE
printf -v USE_INCR "%07d" $NEW_INCR
FILENAME="tl_${FILESTAMP}_${USE_INCR}.jpg"
# Take Image
raspistill -o $LOCALPATH/$FILENAME $RASPISTILLPARAMETERS
# Upload Image
ftp -n <<EOF
open $FTPSERVER
user $FTPUSER $FTPPASS
passive
mkdir $FTPPATH
mkdir $FTPPATH/$FOLDERSTAMP
put $LOCALPATH$FILENAME $FTPPATH/$FOLDERSTAMP/$FILENAME
EOF
# Delete Image
rm $LOCALPATH$FILENAME
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment