I now know what the problem with the time lapse setup was. For some reason Canon decided to put every like 100 pictures into a new folders and name the folders 157CANON and 158CANON and so on. So it was leaving these pictures on the camera card and not downloading them onto my card. This causes a problem because the card (in the camera) filled up and then it stopped taking pictures. That makes sense why it wont take a picture when the card is full, but it doesn’t make sense why Canon operates this way. However this is the easy part of the problem. The harder part was getting it to take a picture again. I would reformat the SD card using the cameras reformat option and then try to take a picture from gphoto2. It would give an “unspecified error” and that was not very helpful in figuring out the problem. The solution (which took me forever to figure out) was that the first picture has to be physically taken from the camera. After that first picture is taken by actually pushing the physical button on the camera, then gphoto2 will take pictures just fine.
So the solution is to make sure that I take that first picture and then make sure that the SD card does not fill up. This is possible to achieve from gphoto2 because it is possible to naviagate into the sd card that is in the camera by issueing the command
and then some* of the regular linux commands work. I say * because very few work and those that do have minor quirks. The main command “cd” works like normal, but there are some issues with tab completion. I wrote this script that uses a here document to actually execute the commands. This was the only way I could figure out how to get it to work. This script is not finalized because I think I will actually want to save the pictures that it is leaving in this folder until I can be certain that it is downloading the same picture onto the Raspberry Pi. (UPDATE) I setup and let it shoot for a day as a test and I confirmed that it is starting a new folder every 100 pictures. And it is NOT saving a copy of it to the Raspberry Pi. It takes the 100th picture and leaves it on the card. And leaves it in the terrible naming format as well.
To be updated….
Hopefully going to install the project back in the greenhouse this weekend!!
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.
# this script will set all of the times when
# the camera should take a picture.
# set some variables
# 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 ]
# 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))
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!
Now that I have my Raspberry Pi I wrote and tested the script to set the time on the Raspberry Pi using my Canon Powershot A510. This is a follow up of my previous post. This is tested and works with a Canon Powershot A510 but it may work with other Canon Cameras, however some may require a little modification to the script.
# this script works with the Canon Powershot A510
# other models may or may not work
# use gphoto2 to get the camera time
camera_time=`gphoto2 –summary | grep -i “unix time” | cut -d ” ” -f4`
# for some reason I had to subtract some time to get it to be correct
camera_time=$(($camera_time – 3592))
# convert UNIX time to readable time
time=`date -d @$camera_time`
# the next four (4) lines cut the timestamp into specific parts so
# that it can be used when setting the time
b=`echo $time | cut -d ” ” -f2`
c=`echo $time | cut -d ” ” -f3`
d=`echo $time | cut -d ” ” -f4`
f=`echo $time | cut -d ” ” -f6`
# this sets the variable real_time equal to the values from gphoto2
# and puts them in the correct order
real_time=`echo $c $b $f $d`
# set the system time equal to the time from gphoto2
date -s “$real_time”
And this script is put into a cron job that is set to run at startup using these details here.
If the power goes out and the camera and the Raspberry Pi shut down, when the power comes back the camera should startup faster than the Raspberry Pi and when the script runs it can set the time correctly. The camera has a small battery to keep time, and it will last for a long time with no power and still keep time.
Everything is setup outside my window taking pictures of our garden today. This is my chance to test and get all of the bugs worked out before I setup for a long period of time. Already I have changed several things and I updated the scripts post to reflect these changes.
I will probably post pictures of the setup tomorrow along with the time lapse that it is taking today.