🌱

Raspberry Pi Garden Camera

26/08/2021

Intro

This is a blog post about how I set up a Raspberry Pi to capture automatically images of my garden. This year is the first year that I’ve had a garden that I am in charge of, and I wanted a way to capture images of my garden over a long time to track the progress and maybe make a cool timelapse with afterwards. Gardening has been a hobby of mine for quite a while, but now I finally have one of my own, so of course I’m going to chuck a Raspberry Pi or two in the mix.

The Pi

I’ve been learning Go in my spare time for the last year (on and off), so naturally that is the language I reached for to complete this project. I really like using Go on my RaspberryPi projects since it’s a compiled language (besides all the benefits of using Go), all I have to do to deploy is compile my code to a binary for the specific OS (Linux) and architecture (ARM) I need and I know it will work.

Infrastructure

I opted to use AWS since it’s the cloud provider I am most comfortable with and I already had an account with them. I am using S3 to store the images taken from the Pi and AWS Gateway to manage the HTTP endpoint that will return the latest image from S3 via a Lambda (also written in Go).

How it all works

There is a cronjob on the Pi that takes images at regular intervals (currently every 6 hours, excluding midnight). These images are then sent to S3 and deleted from the Pi to save disk space. The S3 images are publicly accessible and their URLs are exposed from a HTTP endpoint I created. When then endpoint is hit, a Labmda spins up and returns the name and URL of the most recent image in the S3 bucket.

Thoughts and Feelings

This is the first project I’ve seen through to the finish in a while, and I’m quite happy with its simplicity and portability. I do want to increase the amount of photos that are taken each day, maybe every three hours instead of six. I also want to build a decent image gallery for the photos, but that is not very time sensitive, so I can play with that in the future.

I didn’t write any automated tests for the project at this time, and I do want to go back and write them. Those who have worked with me know that I’m quite the proponent of TDD, so I really should go and write some tests, especially if I want to grow this project.

As for the photos themselves, they are visible here. Currently, it’s a pretty basic page that displays the most recent photo, but I intend to slowly grow this into a gallery for all of the photos.