All things Raspberry Pi and Time Lapse

Posts tagged ‘at’

Update on Everything?

I recently started a new job so I will not be posting as much now unfortunately. I am trying to decide how I want the script that uses at to function. The problem is that if the power was consistent that script that is the last one in this post would work beautifully. However since power may not be on 100% of the time because of a snow storm or something else knocks the power out, this script may not function the way it should. If the power is off when the script was scheduled to run, it will run whenever the system starts up, not at the correct time. And this is a major problem. So my next idea was to set all of the times that the camera would take a picture for the whole year. This script accomplishes that.

#!/bin/bash
# jamesmiller
# this script will set all of the times when
# the camera should take a picture.
#
# set some variables
min=0
count=0
# test how many times this script should execute
# I chose 400 because there is 365 days in a year
# and this is a little more than that
while [ $count -lt 400 ]
do
# set what time at should execute the script
at -f /root/camera_1443min now + $min’min’
# add 1 day and 3 minutes to the last time
# 1440min = 1day
min=$((min + 1443))
# increment the count by one
count=$((count + 1))
done

The main problem with this script is that if the power is off, and it misses one or more of these scheduled time, it will execute them when the computer boots. The problem with this is that I will have pictures in the folder along with all of the rest of them that were not taken at the right time. Still trying to figure out how to deal with that. If at had configuration files that would turn “execute old jobs at boot” on and off that would be nice! The other option is to assume that the power will only go out once or twice, and that I should not worry about it, and write a script that executes at startup to put the date and time into a file. Then I could get the date and time from that file and go find the images that were taken at the wrong time.

I ask this question on the Unix/Linux Stack Exchange forum and I am waiting to see if there are any answers that will work.

NOTE: This is kinda complicated to explain in text so I did my best. Leave a comment below if you have questions!

gphoto2 camera scripts

I could not wait for my Raspberry Pi to arrive so I went ahead and wrote the scripts using gphoto to take pictures. These were written on a Fedora desktop, but since it is using standard Linux commands it should work from any distribution.

A very good tutorial on cron and at are availble here at IBM.

This first one is pretty standard. It will take a picture at noon once a day… The actual scheduling of the script will take place using the cron daemon.

#!/bin/bash
# jamesmiller
# 6-22-2012
#
# change directories to the correct folder to save the image
cd /home/jamesmiller/gphoto/1day
# actually take the picture using gphoto2
gphoto2 –capture-image-and-download –filename “%Y%m%d%H%M%S_1day.jpg”

Note the last line is supposed to be all on one line. The crontab entry for this first script will look like this… The twelve in the second position means to take the picture at 12:00 (noon) every day of the month, every month, every day of the week. Note that the time in cron uses a 24 hour clock.

0 12 * * * /home/jamesmiller/gphoto/1day

And the second one is very similar to the first. Except it will take a picture once every 5 minutes for an entire day on the first and fifth days of the month. In the final I will only use one of the days a month, but by shooting two days that gives me an error margin (if the power goes out that day) or some other unforeseen accident occurs.

#!/bin/bash
# jamesmiller
# 6-22-2012
#
# change directories to the correct folder to save the image
cd /home/jamesmiller/gphoto/5min
# actually take the picture using gphoto2
gphoto2 –capture-image-and-download –filename “%Y%m%d%H%M%S_5min.jpg”

Note the last line is supposed to be all on one line. This script is very similar to the last script except for the file location where it will store the images. This will keep the different scripts separate. However the crontab entry for this script is very different! The first (*/5) means to take a picture every 5 minutes, the second piece (4-20) means to only take the picture if the time is between 4am and 8pm, and the (1,5) means on the first and fifth of the month to execute. the last two stars mean every month, every day of the week. This script will provide a time-lapse that looks like 12 days – one for each month of the year.

*/5 4-20 1,5 * * /home/jamesmiller/gphoto/5min

The last script is more complicated. It uses cron and it also uses a different scheduling daemon called at.

#!/bin/bash
# jamesmiller
# 6-22-2012
#
# change directories to the correct folder to save the image
cd /home/jamesmiller/gphoto/1443min
# schedule the next runtime of this script
at -f ../camera_1443min now + 1443min
# store the date and time in a file to be read as the time
# when the picture was taken.
echo `date +%Y%m%d%H%M%S` >> ../1443_time
# actually take the picture using gphoto2
gphoto2 –capture-image-and-download –filename “%Y%m%d%H%M%S_1443min.jpg”

Note the last line is supposed to be all on one line. The purpose of this script is to take a picture at like 4:00am the first day, then the next day at 4:03, and the next day at 4:06 and so on. This last script will provide a very interesting time lapse as it will take one year and compress it into time lapse that looks like a day. It will start in the morning and end at night, but all 4 seasons will have passed. I am not totally sure at what time I want this to start, because there is no reason to take pictures in the dark. The cron details I have not finished working on yet, but I will add them here when I finish it.

cron details to follow

Those are my ideas for a year-long time lapse. This will give me three different looks into the scene over the course of a year. If anyone has other/more ideas for when the camera should take a picture do not hesitate to comment below!

Tag Cloud