Skip to content

This code enables a Raspberry Pi (with a Raspberry Pi Camera attached) to take a picture each minute while robotics practice is going on.

License

Notifications You must be signed in to change notification settings

Bionic-Bison-5535/Raspberry-Pi-Time-Lapse

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

82 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Raspberry Pi Time-Lapse

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.

Setup

To set up this code to run on any Raspberry Pi with a Raspberry Pi Cam, simply follow the following steps:

  1. INSTALL/ENABLE NECESSARY SOFTWARE
    Enter the following into the Raspberry Pi's terminal, one line at a time:
    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
    
    This will install node.js, shell.js, and this repository on your Pi. It will also enable your Raspberry Pi Cam.
  2. GET IPv4 ADDRESS
    Enter ifconfig into the terminal and look for your IPv4 address in the mess of numbers. It should be after inet in the wlan0: category. It will look something like 192.168.1.82 and will probably start with 192.168. if you are using a home network and 10.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.
  3. CRONTAB AUTOSTART
    Type crontab -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:
    @reboot node /home/pi/Raspberry-Pi-Time-Lapse/server.js
    
    Please notice that if your username is not "pi" you should replace the "pi" in "/home/pi" with your username. Press CTRL+o and then Enter to save, and then CTRL+x to exit the nano editor. Now the time-lapse software will automatically start whenever your Pi turns on.
  4. SET USERNAME
    If the username on your Pi is "pi", you can skip this step. Otherwise, open server.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 with CTRL+s.
  5. REBOOT PI
    Reboot the Pi by entering sudo reboot into the terminal.
  6. 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:
    http://192.168.1.82:8000/home
    
    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.

Documentation

To Get a Live Camera View

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.

To Save a Live Camera View

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 the Time-Lapse Recording Times

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.

To Stop the Time-Lapse Recorder

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.

To Wirelessly Reboot the Pi

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.

To Wirelessly Shut Down the Pi

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).

To Get an Image From a Certain Time on a Certain Day

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.


To Watch a Timelapse Video

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.

Table of URL Parameter Actions

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

About

This code enables a Raspberry Pi (with a Raspberry Pi Camera attached) to take a picture each minute while robotics practice is going on.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published