This guide sets up a Raspberry Pi Zero 2 W (or similar Pi with a CSI camera) to automatically record or stream video from boot.
It assumes:
Raspberry Pi OS Lite (Bookworm or newer) (you can do 64 bit, apparently it's slightly better for this.)
Headless setup (SSH only, no GUI)
Official Raspberry Pi Camera Module or compatible (in this I'm using the IMX708 12 MP camera https://docs.arducam.com/Raspberry-Pi-Camera/Native-camera/12MP-IMX708/)
Download Raspberry Pi Imager Select Raspberry Pi OS Lite (64-bit).
Configure advanced settings:
Enable SSH
Set username/password (most of this assumes a username of piuser)
Configure WiFi (SSID + password + country(?))
Set hostname (e.g., pi-cam)
Flash to microSD and boot the Pi.
ssh piuser@pi-cam.local
(or use the Pi’s IP address)
sudo apt update && sudo apt upgrade -y (this will take a while)
verify has rpicam:
which rpicam-still should return something.
sudo apt install -y ffmpeg v4l-utils git motion vim (vim is optional but I prefer it. This assumes you know vim, but you can just replace "vim" with "nano" as needed)
Edit /boot/firmware/config.txt with sudo vim /boot/firmware/config.txt (see here: https://docs.arducam.com/Raspberry-Pi-Camera/Native-camera/12MP-IMX708/)
change camera_auto_detect=1 to camera_auto_detect=0
Locate the line [all] and add the following line below it:
dtoverlay=imx708 (you may need it to be different depending on what camera you have. Check out the arducam docs for more info)
reboot with sudo reboot (optional)
check that it recognized the camera with rpicam-still --list-cameras (should return something)
test with rpicam-hello -t 5000 (won't show anything when headless, but will log things out)
Clone this repo into the rpi: git clone https://github.com/jstephencorey/rpi-surveillence.git
Go into it with cd rpi-surveillence
Make the setup file runnable with chmod +x setup_local.sh setup_upload.sh shutdown_services.sh capture.py motion_postprocess.py clip_uploader.py
Run the setup sudo ./setup_upload.sh
reboot with sudo reboot TODO is this necessary? I think it isn't
for testing: git stash; git pull; chmod +x setup_local.sh setup_upload.sh shutdown_services.sh capture.py motion_postprocess.py clip_uploader.py; sudo ./setup_upload.sh
This is set up to go on my personal server in a docker container. You'll likely need to change several things (e.g. the attached volume and it's reference in app.py) to make it work for you.
git clone https://github.com/jstephencorey/rpi-surveillence.git
cd rpi-surveillence/flask_api
edit the .env file with vim .env. Currently you just need to put it there, nothing is being used.
docker compose up -d --build
Verify it's working with postman or bruno or something.
For testing: cd ../; git pull; cd ./flask_api; docker compose up -d --build;
-
Connect the External Drive:
- Plug the external drive into your Raspberry Pi.
-
Identify the Drive:
- Use a command like
lsblkorfdisk -lto list all connected drives and identify the external drive's device name (e.g.,/dev/sda1).
- Use a command like
-
Create a Mount Point:
- Choose a directory where you want to mount the drive, I used
/mnt/external_drive. You can create this directory using:sudo mkdir /mnt/external_drive
- Choose a directory where you want to mount the drive, I used
-
Mount the Drive:
- Mount the drive to the created directory:
sudo mount /dev/sda1 /mnt/external_drive
- Mount the drive to the created directory:
-
Set Permissions:
- Ensure the user running your application has write permissions to the mount point:
sudo chown -R piuser:piuser /mnt/external_drive
- Ensure the user running your application has write permissions to the mount point:
-
Automate Mounting (Optional):
- To automatically mount the drive on boot, add an entry to
/etc/fstab. Open the file with:sudo vim /etc/fstab - Add a line like:
UUID=<the uuid you can see with blkid or something> \mnt\external_drive exfat defaults,uid=piuser,gid=piuser,umask=000,nofail 0 0 - Adjust the filesystem type (
exfatin this example) to match your drive's format. I'm using exfat to be able to open it on windows.
- To automatically mount the drive on boot, add an entry to
In order to start it, run setup_local.sh
First off, currently I have a working surveillance camera! It works and will save videos to my home server. That's a cool thing to have and celebrate (: Server: send to temp folder instead of root before processing Add an av1 handling GPU to my server and add in situ AV1 processing Let it run on my computer? Also testing to find the right settings for good compression and good enough quality. Need a new server motherboard for that... 🥲 Join videos next to each other? (e.g. partial/part_###, final?) - I think this would be good, especially with the discovered limit of ~100 mb files I can send from the rpi zero 2 w before it breaks. Rename the repo 🙈 And rename references to this repo within it. Rpi: Set up a non-SD card drive to write to? Find out if that's actually better? idk, I think it's flash, still... Get Encryption set up (and jupyter or something to decrypt.) At some point re-set-up everything from scratch on a new rpi to make sure it's all repeatable Get physical stuff set up? switch, battery, etc.(3d printing?)