Capturing a time lapse from a Raspbery Pi camera

After running into a bug with VLC capturing images from an RTSP stream in Linux, I decided to go a different route for capturing time lapses from my 3D printer and that was to use a local script on the PI that can be run with command line parameters to set the interval and duration of the capture and have the images output to a network share, this should satisfy the same goal as the RTSP stream by not having the PI store or write data to the SD card and so prolong its life

I went about the process in this order:

  • Setup a share on my workstation
  • On the pi “sudo apt-get install samba-common smbclient samba-common-bin smbclient cifs-utils”
  • Add the share to /etc/fstab by appending “//<server>/Timelapse /mnt/timelapse cifs guest,rw,iocharset=utf8,file_mode=0777,dir_mode=0777 0 0”
  • Reboot the Pi to ensure the mount is permanent

After that I wrote a simple script to allow for timelapse capture:

#!/bin/bash
#Timelapse from an RPi Camera
if [ $# == 0 ]
then
echo
echo “usage: $0 [runtime] [interval] [destination]”
echo
echo ‘All times are in seconds (3600 seconds per hour)’
echo
echo “example:  $0 3600 60 ~/images/timelapse”
exit
fi
runtime=$1
interval=$2
if [ $# -gt 2 ]
then
store_path=$3
else
store_path=/mnt/timelapse
fi
while [ $SECONDS -lt $runtime ]
do
datetime=$(date +”%FT%H%M%S”)
raspistill -vf -hf -o $store_path/$datetime.jpg
sleep $interval
done
echo ‘time lapse complete’

Unfortunately I ran into trouble where whenever calling raspistill I would get an ENOSPC error and it would fail to do any capturing, I ran a firmware update and that led me down a rabbit hole where it looks like the rpi-update is broken on older Pis such as my Rpi 1B, this required downloading the files manually and forcing the update without a download as per the below:

curl -L https://github.com/Hexxeh/rpi-firmware/archive/master.tar.gz -o master.tar.gz
cd /root/.rpi-firmware
sudo tar -xvzf /home/pi/master.tar.gz –strip-components=1
sudo SKIP_DOWNLOAD=1 rpi-update

Finally, with all of that complete I tried again and it failed, reason being I still had my streaming script running from the previous article! I went through and disabled the service I had setup previously:

systemctl disable stream-rstp.sh

And tested and successfully got an image off the camera, I tested my script, and it worked!

I can now grab high resolution time lapses of my 3D printer by SSHing into my Pi and running a single command string!

 

Leave a Reply

Your email address will not be published. Required fields are marked *