A collection of ways to do things on a Raspberry Pi

View the Project on GitHub tigoe/PiRecipes

A Timelapse Webcam Application

This application uses node.js and fswebcam to create a timelapse cam. You can use it with a Pi camera, or with a USB webcam. Here is the man page for fswebcam.

screenshot of a webcam inteface Figure 1. Screenshot of the timelapse webcam interface, showing the controls for setting fswebcam parameters at the top, and the camera image below.

The Client Interface

The client interface shows the latest image and a series of input controls to change the fswebcam settings. Clicking the Update Parameters button updates the server’s fswebcam settings. The client starts by getting the fswebcam parameters from the server and the list of cameras and populates its input elements with that information. Then it starts an interval which regularly fetches the latest image.

The interface is shown in Figure 1 above.

The Code

The code can be found in this repository. Copy all the files of the timelapse-cam directory onto your Pi. Make sure to copy the empty img directory too, or fswebcam will produce an error when it tries to save the first image.


To run this app, you’ll need to install the following components on your Pi:

The command line installs are as follows:

$ sudo apt update
$ wget -O - https://raw.githubusercontent.com/sdesalas/node-pi-zero/master/install-node-v15.6.0.sh | bash
$ npm install pm2 -g
$ sudo apt install fswebcam

For more on installing node.js, see this link.

Once you have downloaded the git repository for the app onto your Pi, don’t forget to node install to bring in the required libraries.

The Software Components

The components are as follows:

The Server API

The node.js server initializes fswebcam and takes a picture once on a regular interval. The images are saved in the img subdirectory of the public directory with the following filename format: imageyyyy-mm-dd_hh:mm:ss.jpg (or .png if you change the file format).

The server runs on port 8080.

The server has the following HTTP endpoints:

To run the server from the command line, type either

$ node server.js 

or if you want to run it in the background,

$ pm2 start server.js