I'm running a script (taking time-lapse photos) that I would like to execute every minute. I'm using the Raspberry Pi camera board and thus using the
raspistill function, but am not using the in-built time-lapse feature in
raspistill because I want to upload each image I take every time after I take it. As a result, I'm using the
sleep function to ensure that there is a delay of 60 seconds between each pair of photos. (the script never takes anywhere as long as 60 seconds to execute).
Over the course of 20 minutes (i.e. 20 executions of the script) I have noticed a drift in the capture times. Rather than a photo being captured on the minute every minute, the 20th photo is captured ten seconds after the minute. Is there any reason why this might be so, and is there a better approach for me to get the images taken accurately?
I'm taking photos using
raspistillat constant intervals for a time-lapse but would like to upload the photos once they are captured. What is the best way to do this?
My code is as follows:
#!/bin/bash TIME_INTERVAL=60 x=1 while [ $x -le 100 ]; do starttime=$(date +"%s%N") # current epoch time in ns # rest of my code goes here. x=$(( $x + 1 )) # this is convoluted because $(()) apparently doesn't like converting from a # string to a floating-point, so $starttime must be an integer sleep $(( $TIME_INTERVAL + ($starttime - $(date +"%s%N") ) / 1000000000)) done;