During the summer months on my commute to work, every morning I would have the pleasure of watching the sun rise over the South Wales valeys. I came to miss what was a daily event in the summer so I wanted a way to capture the sun rise every morning using
my raspberry pi. So I purchased a raspberry pi camera and got it hooked up to the board and tested using raspistill -t 0 test.png
To capture the timelapse of the sunrise I first began with writing a simple python script that would fire the camera on, take a picture and write it to the disk every 60 seconds. After which the main function of the code creates a loop which runs for
1 hour so it would take 60 720p pictures. The fist morning, I woke up at around 4 am and fired on my raspberry pi and executed the script, and it did the trick, by the time the sun rose there was a folder full of images.
The next step was to take these images and compile them into a mp4 using ffmpeg, this was rather tricky to get the bitrate correct to show the images smoothly. Now as you can tell the fatal flaw with this idea is I for one don't really want to be waking
up at 4am every morning, so nextup researched and implemented a crontask that would fire the pi on at 4am and execute the code. I modifyed the script slightly to automate the generation of the timelapse once the capture had been completed,
remove the timlapse images and then copy the newly created timelapse onto my Nas drive.
This worked great for a few weeks, asside from a few misshaps where data was lossed as a result of the WiFi network going down, so I had to cahce the last copy of the timlapse images just incase. Another crontab was then used to remove the previous days
images, but as they're copyed onto the nas, if the connections down then task would fail and I'd still have yesterdays images.
It was all good, but I soon noticed a pattern which took by suprise at first (silly in retrospect) essentially by the end of the week I thought there was a bug with the ffmpeg export as the first minute or two of the video was black. What i came to realise
is that it was in fact due to the sun rising slightly later each day hence the black frames. In order to fix this I made yet another python process which hooks into NASA's sunrise data, and stripped out the exact time the sun is due
to rise at my geo. this python script then tells the cron job when to execute minus 5 minutes or so. The result is a nice library of tools for capturing images with the pi and I learnt alot about cron jobs and scheduling not to mention
the fun experience of using a REST API to probe data.
Another use I intend to use this for is during the autum / fall so that I can record the sun going down but also schedule a 'Leaf watcher' to create a timelapse of the fall. Hopfully by the end of the year I'll be able to combine sunrise / sunset for
each day of the year into a nice 5-10 minute feature.
Here's an example: