Project : Timelapse of a contruction site

A friend of mine wanted me to find a way for his house contruction to be captured as a timelapse video.
My first thought was to use my GoPro as it has the functionality built in, however, power would be an issue…
Then I found off the shelve products, but they were rather expensive….and then I thought…why not the RPi??

 

So the requirements were

1) Run on regular power
2) As little as possible access needed during the 24 weeks contruction period. Best if none at all…
3) Needs to be possible to extract the pictures on to a Windows/Mac PC at the site – if it would run out of space during the period
4) Only record images during the contruction time to save space on the SD card/external HD and to limit post proccessing needs.
5) Fairly cheap
6) Autostart on powerup – in case the power would fail at the site. Plug and play…
7) Use an external HD for the pictures if possible (optional…)

So I ordered the camera and found this project and decided to use it as my base as it fulfilled most of my requirements.

 

Project resources

1) RPi. Link
2) PiCam v2.1. Link
3) Watertight box for housing
4) Software to extract pictures onto a Windows/Mac from the SD Card. Link

 

 

The code

The code ended up like this and was based on the Fotosyn project:

import os
import time
import RPi.GPIO as GPIO
from datetime import datetime

# Grab the current datetime which will be used to generate dynamic folder names
d = datetime.now()
initYear = "%04d" % (d.year)
print (initYear)
initMonth = "%02d" % (d.month)
print (initMonth)
initDate = "%02d" % (d.day)
print (initDate)
initHour = "%02d" % (d.hour)
print (initHour)
initMins = "%02d" % (d.minute)
print (initMins)

# Define the location where you wish to save files. Set to HOME as default. 
# If you run a local web server on Apache you could set this to /var/www/ to make them 
# accessible via web browser.
folderToSave = "timelapse_" + str(initYear) + str(initMonth) + str(initDate) + str(initHour) + str(initMins)
os.mkdir(folderToSave)

# Set the initial serial for saved images to 1
fileSerial = 1

# Run a WHILE Loop of infinitely
while True:
 
   d = datetime.now()
   # Loop to only take pictures within timeframe
   if (d.hour>6 and d.hour<19):

   hour = "%02d" % (d.hour)
   print ('The hour is: '+ hour + ' taking a picture...')
   # Set FileSerialNumber to 000X using four digits
   fileSerialNumber = "%04d" % (fileSerial)
 
   # Capture the CURRENT time (not start time as set above) to insert into each capture image filename
   hour = "%02d" % (d.hour)
   mins = "%02d" % (d.minute)
 
   # Define the size of the image you wish to capture. 
   imgWidth = 1920 # Max = 2592 
   imgHeight = 1080 # Max = 1944
   #print " ====================================== Saving file at " + hour + ":" + mins
 
   # Capture the image using raspistill. Set to capture with added sharpening, auto white balance and average metering mode
   # Change these settings where you see fit and to suit the conditions you are using the camera in
   os.system("raspistill -w " + str(imgWidth) + " -h " + str(imgHeight) + " -o " + str(folderToSave) + "/" + str(fileSerialNumber) +".jpg -sh 40 -awb auto -mm average -v")

   # Increment the fileSerial
   fileSerial += 1
 
   # Wait 60 seconds (1 minute) before next capture
   time.sleep(60)
 
 else:
 
   # Just trapping out the WHILE Statement
   print ("Doing nothing at this time - wait 10min and check the time again")
   time.sleep(600)

(The entries for when the pictures are taken, can be edited as needed and so can the resolution etc. Right now, it takes pictures between 7:00 and 19:00 )

 

Autostart of the code

The code is started automatically using a crontab by typing “crontab -e” in the console and adding this line:

@reboot python /home/pi/Mycode/rapsiLapseCam_03.py 

That worked!

Now….adding the external HD

The basic mounting and automount was done using this guide

But actually using the HD turned out to be a little problematic due to permissions…
I could not get write access on the HD! After some troubleshooting as searching it turned out it is mounted as root by default and the pi user and thus crontab didnt have permissions to write. Thats when I found that there are several crontabs….I just needed to use the right one.
So instead of using “crontab -e” I just had to use “sudo crontab -e”. That sorted the persmissions.

However I still needed the images to be saved in the correct location (in this case /mnt/Timelapse).
That was fixed by amending the crontab line from this:

@reboot python /home/pi/Mycode/rapsiLapseCam_03.py

to this….

 @reboot cd /mnt/Timelapse && python /home/pi/Mycode/rapsiLapseCam_03.py 

All the Raspberry related stuff is done. The project now just needs a case 🙂

Optional future features

  1. Diode to state if the code is running
  2. Diode to state if its recording pictures
  3. Replace rapsistill library with PiCam library

Test video