The mechanical bits

The mechanical arrangement is pretty simple. I drilled three holes on the lid of a junction box, 3.5mm x 2 + a hole of 14 mm diameter. A 3d-printed bracket holds the camera in place using M3 screws. The part prints in some 10 minutes and is good for most camera modules. A different bracked it used to hold the Raspberry Pi Zero W inside the junction box. This part prints in 10 minutes as well. Two more M3 screws are needed there. I drilled an additional hole on the junction box to hold the tripod in place. One of the knockouts was pierced in order to fit the USB cable through the hole.

The software side

The Raspberry Pi runs standard Raspbian. I set it to boot to the terminal using raspi-config and enabled the camera and the SSH service through the applications as well.

You could make the RPi connect to your wifi network but I thought it would be tedious to have to use a keyboard and a screen to log on to the RPi and change the password whenever I changed my router. Therefore, I chose to set the RPi as a wifi hotspot so that I can connect to it from a Laptop and dump the pictures or do whatever I please. The process to set up the system is surprisingly straightforward. You need to install hostapd and dnsmasq. The steps are described here:

https://www.raspberrypi.org/documentation/configuration/wireless/access-point.md

Once I got the wifi setup properly, I was able to get rid of the screen and the keyboard and work on the software from my laptop through a SSH connection. The next step was to set up the camera software. I use fswebcam to capture the snapshots. Detailed step-by-step instructions can be found here:

https://www.raspberrypi.org/documentation/usage/webcams/

When I followed this procedure I faced a little problem: fswebcam complained that /dev/video0 didn't exist. This can be sorted out by loading the proper kernel module by running modprobe bcm2835-v4l2

Most camera modules don't have the ability to autofocus and one needs to adjust the focal length by twisting the lens. This process is tedious if one has to wait to see the snapshots from fswebcam. It is much better to watch a live videostream. This can be done using gstreamer, the best piece of software I discovered in 2017. I believe this is installed in Raspbian by default but one can install it by issuing apt-get install gstreamer1.0 at any time. The TCP video streaming server is started from the RPi by running:

raspivid -fps 26 -h 450 -w 600 -vf -n -t 0 -b 200000 -o - | gst-launch-1.0 -v fdsrc ! h264parse ! rtph264pay config-interval=1 pt=96 ! gdppay ! tcpserversink host=192.168.4.9 port=5000

And from the laptop one can run the following command to watch the video: 

gst-launch-1.0 -v tcpclientsrc host=192.168.4.9 port=5000 ! gdpdepay ! rtph264depay ! avdec_h264 ! autovideosink sync=false

In my case, I made the mistake of pointing the camera upside down, this can be fixed from the client side by adding  "! videoflip method=rotate-180" to the pipeline before autovideosink.

Once the camera is focused properly, one can stop the gstreamer on both the server and the client and set up fswebcam to capture the snapshots. At the moment I'm running this command by manually logging into the RPi but a script can be set up to run automatically on boot by adding the command to rc.local (https://www.raspberrypi.org/documentation/linux/usage/rc-local.md).

Notes about the power consumption of this device

I made a quick measurement of the power consumption of the Raspberry Pi and basically, it takes about 0.08 A when iddle (no streaming), about 0.17 A when running the video stream through wifi as described above and 0.02 A when on halt (after issuing a shutdown command leaving the USB cable connected). This is quite a modest consumption. From my rough estimates, you could easily run the video stream through wifi for about 2 hours by feeding the Raspberry Pi from a £1 USB powerbank (these can fit 0.25 A for about 2 hours). What a time to be alive.