This code enables a Raspberry Pi circuit board (with a Raspberry Pi Cam attached) to take a picture each minute robotics practice is going on at the New Buffalo STEAM building. By using the Raspberry Pi's local IPv4 address on port 8000
, you can access any photos that have been taken and even watch a video of any day's time-lapse.
To set up this code to run on any Raspberry Pi with a Raspberry Pi Cam, simply follow the following steps:
- INSTALL/ENABLE NECESSARY SOFTWARE
Enter the following into the Raspberry Pi's terminal, one line at a time:This will install node.js, shell.js, and this repository on your Pi. It will also enable your Raspberry Pi Cam.sudo apt-get update sudo apt-get dist-upgrade curl -sL https://deb.nodesource.com/setup_20.x | sudo -E bash - sudo apt-get install -y nodejs npm install shelljs git clone https://github.com/Bionic-Bison-5535/Raspberry-Pi-Time-Lapse.git sudo raspi-config nonint do_legacy 0
- GET IPv4 ADDRESS
Enterifconfig
into the terminal and look for your IPv4 address in the mess of numbers. It should be afterinet
in thewlan0:
category. It will look something like192.168.1.82
and will probably start with192.168.
if you are using a home network and10.10.
if you are using public wifi. Write down your IPv4 address somewhere (or memorise it). Note that before performing this step it is absolutely necessary that you connect your Pi to wifi. - CRONTAB AUTOSTART
Typecrontab -e
into the terminal and press enter. If you are prompted to choose an editor, choose nano. At the bottom of the document that will open, make a new line and type:Please notice that if your username is not "pi" you should replace the "pi" in "/home/pi" with your username. Press@reboot node /home/pi/Raspberry-Pi-Time-Lapse/server.js
CTRL+o
and thenEnter
to save, and thenCTRL+x
to exit the nano editor. Now the time-lapse software will automatically start whenever your Pi turns on. - SET USERNAME
If the username on your Pi is "pi", you can skip this step. Otherwise, openserver.js
from the folder/home/pi/Raspberry-Pi-Time-Lapse/
with Text Editor and change "pi" in line 7 to whatever your username is. Save the file withCTRL+s
. - REBOOT PI
Reboot the Pi by enteringsudo reboot
into the terminal. - ACCESS USER INTERFACE
When your Pi finishes turning on, open a web browser such as Chrome in a device connected to the same wifi network and enter in the URL bar your IPv4 address and then an immediate:8000/home
. So, the URL should look something like this:The timelapse page should now load. If something isn't working, try making sure that you correctly followed each of the five steps. If you are unable to figure out what went wrong, please head to the Help discussion page in this repository to ask any questions you may have or simply mention what is going wrong. I will be glad to help.http://192.168.1.82:8000/home
When you go to the home page at yourip:8000/home
, the image that loads after approximately five seconds will be a single snapshot that was taken as soon as you accessed the website. Alternatively, you may go to yourip:8000/live.jpg
to access the image itself, without the surrounding website. This image will not be saved.
If you want to save a picture of the current view to access later on, simply add a ?pic
to the end of a URL. You can access this image later with the "Retrieve Single Image" section on the homepage.
To change when a time-lapse is recorded and/or on what days of the week, simply edit lines 9-22 in server.js
in the folder /home/pi/Raspberry-Pi-Time-Lapse
on the Pi. Then save it with CTRL+s
and reboot the Pi.
Add a ?stop
to the end of the URL. This is useful in our situation if, for example, the robotics season is over until next year and we don't want a bunch of pictures of the vacant STEAM building over the summer. We can still access previously taken pictures, but more pictures will not be taken until the day we add ?start
to the end of the URL.
Add a ?reboot
to the end of the URL. Be sure to close out of this page immediately or you will get stuck in a reboot loop. When you go to the URL with ?reboot
at the end, you will recieve no response, so your web browser will keep trying to reload the page. As soon as the Pi has turned back on, if the page is still open, the web browser's attempts to reload will be sucessful and the Pi will reboot again. Don't do this.
Add a ?shutdown
to the end of the URL. If you don't want anyone on the wifi network besides yourself to be able to do this, add a password to line 8 in server.js
on the Pi and use your password in the URL command. For example, if your password is "hello1234", add ?shutdownhello1234
to the end of the URL to shut down the Pi. Please ensure that you do not use non-URL-typical characters in your password, such as spaces, percents, octothorpes, question marks, etc.
Note that you will not be able to access any timelapses while the Pi is shut down. Shutting down the Pi should be exclusively used only before unplugging it. If you unplug the Pi while it is running, you may damage the SD card and ruin everything on your Pi, so always shut down the Pi before cutting the power to it. (Believe me, I already had to reformat an SD card and loose everything on a Pi after simply unplugging it).
Go to the home page (yourip:8000/home
) and choose a date and time from the menu in the "Retrieve Single Image" section. Then click the "Load Image" button and wait approximately two seconds for the 4K image to load.
Go to the home page (yourip:8000/home
) and choose a date, a start time, and an end time from the menu in the "Retrieve Time-lapse Video" section. Then click the "Load Time-lapse" button. You will see a loading bar in the lower-right corner of the screen. The website must retrieve and store all of the images in order to allow the video to play back at a reasonable speed. By default, the video will play at a rate of 5 minutes per second. You can use the pause/play button and the video progress slider at the bottom of the screen to control playback, or you can go through the images one at a time with the back/next buttons.
URL Ending | Action | Additional Notes |
---|---|---|
?pic |
Take a picture and save it | Picture will be saved as Mmm_DD_YYYY_HH:MM.jpg . For example, a picture on January 1st of 2025 at 3:30pm would save as Jan_01_2025_15:30.jpg . |
?stop |
Stop the timelapse recording system | No pictures will be taken unless you use the ?pic parameter or resume the recording system with ?start . |
?start |
Resume the recording system | To be used after ?stop . Recording times will still apply as if the system had never been paused. |
?reboot |
Reboots the Pi | |
?shutdown |
Shuts down the Pi | To be used before unplugging the Pi. |
?shutdownhello |
Shuts down the Pi | This is an example of how to shut down the Pi when the set shutdown password is hello , as set in line 8 of server.js |