A Python time-lapse program.

A free program…

This is the Python code I cobbled together to make a time-lapse movie of my rather exciting flowering cactus. I’m sure this has been done better by lots of people. It runs on a Raspberry Pi Zero, with not much memory, and no online storage, so it sends the pictures to another Pi Zero, called PiBigStore, which happens to have a 2 Terabyte USB drive. Help yourself to a copy, if you like. Change the server name, and password, obviously. If you know ways this can be improved, feel free to comment.

# Time lapse pictures
import os
import time
import ftplib
from picamera import PiCamera
import schedule

def send_to_PiBigStore():
    hour = int(time.strftime(“%H”))
    #print(hour)
    if hour < 7 or hour > 21:
        time.sleep(250)
        return
    
    file_name = “cactus” + time.strftime(“%Y%m%d-%H%M%S”) + “.jpg”
    camera.capture(“/var/tmp/” + file_name)
    
    connected = True
    ftp = ftplib.FTP()
    try:
        ftp.connect(“PiBigStore”)
    except ftplib.all_errors:
        connected = False
        print(“Couldn’t connect to PiBigStore.”)
        ftp.quit()
        
    try:
        ftp.login(“pi”,”password goes here”)
    except ftplib.all_errors:
        connected = False
        print (“Failed to login to PiBigStore server.”)
        ftp.quit()
    
    if connected:
        ftp.cwd(“/media/pidrive/data/cactus/”)
        ftp.storbinary(‘STOR ‘+file_name, open(“/var/tmp/”+file_name, “rb”))
        print (“Sent to PiBigStore “, file_name)
    ftp.quit()
    os.remove(“/var/tmp/”+file_name)

# Main loop
schedule.every(5).minutes.do(send_to_PiBigStore)
camera = PiCamera()
camera.rotation = 90

while True:
    schedule.run_pending()
    time.sleep(10)
A foot-tall cactus on a windowsill, with a Raspberry Pi Zero with camera, mounted on a Lego tower.

Me, wearing a Panama hat, spectacles, and a fine growth of facial hair.

Author: Walrus

Just this guy, you know.