Introduction
Even though we live in a quiet neighborhood I wanted to have a few cameras around the property. I'm sure it will provide hours of watching mongoose, the occasional wild pig, feral cats, chickens, and turkeys in our neighborhood.
The first camera project is for our driveway. It will be paired with a motion detector.
Design
The camera is coded in Python.
You will need an MQTT broker for all of this to work together. You can use Adafruit IO.
In my implementation I set up a Mosquitto MQTT broker on a RaspberryPi 4 Model B running Debian Bookworm and Mosquitto v2.022.
For image and clip storage this project supports both writing to a local file server as well as to Dropbox. For local file storage I have a another Raspberry Pi running Openmediavault.
Code
Driveway Camera
The code for this project can be found on Github.
It is one part of the larger home monitoring project.
Libraries Required
- base64
- time
- os
- paramiko (ssh)
- scp
- uuid
- datetime
- dotenv
- paho.mqtt.client
- logging
- libcamera
- picamera2
- dropbox
Feature Highlights
- Loads all configurations from .env file.
- Streams a live feed of the camera locally using PyavOutput
- Has a still camera configuration to snap an image as soon as motion is detected
- Utilizes two encoders; H264Encoder for the live feed and MJPEGEncoder for the 30 second capture when motion is detected
- Utilizes ssh/scp to move files to the local file server
- Utilizes encrypted transport for all MQTT traffic
- Configurable via MQTT, camera will send image and capture video to local file storage, Dropbox, or both
- Utilizes separate publish and subscribe MQTT clients
The TL;DR nuts and bolts
MediaMTX is launched with the camera start up to display the rtsp live stream in a web page. The URL will look like http://<IP of your camera>:8889/cam
The camera will subscribe to:
- monitoring.motion-detect
- monitoring.storage
The camera will publish to:
- monitoring.recording
- monitoring.picamera
When the camera receives a message on monitoring.motion-detect, it will do the following:
- Take a still image and publish it to monitoring.picamea
- Publish that recording has started to monitoring.recording
- Capture a 30 second mp4 clip
- Copy the image and 30 second clip to local storage, remote storage, or both
- Publish that recording has completed to monitoring.recording
Case
I used OpenSCAD and the YAPP Box (Yet Another Parametric Project Box Generator) library from mrWheel. This library is well documented and has a lot of features.
Node-Red Dashboard
Node-Red Dashboard will display the following:
- Live camera feed
- Last still shot taken when motion was detected
This is what the camera flow in Node-Red looks like.
Live camera feed in Node-Red
The easiest way to get the live feed in Node-Red is to use the template node and embed the URL for the stream in an iframe.
<iframe src="http://192.168.68.70:8889/cam" width="856" height="480" frameborder="0"></iframe>
Still shot in Node-Red
When motion is detected the code will base64 encode the image and send it to the MQTT feed monitoring.picamera.
An MQTT in node in the Camera flow susbscribes to the feed and when a message is received will update the dashboard page with the image.
The easiest way to display the image in Node-Red is to use the template node and embed the image.
<img style = "width:854px; height:480px;" :src="`data:image/jpg;base64,${msg.payload}`" />
I know both of these seem deceptively simple, but they work!
Project Construction
The Camera
Insert the Raspberry Pi 4 into the case and secure to the 4 self-threading standoffs. Use M2 screws.
Attach the cable for the camera to the Raspberry Pi 4.
Attach the camera to the lid by securing with the 4 self-threading standoffs. Use M2 screws.
The Camera fully assembled.
The Case
The case is printed using Polymaker PolyLite ASA filament. This is a weather resistent filament which makes it perfect for the camera on the house under an eave.
3D Printing Settings
- Extruder temperature: 250
- Platform temperature: 85
- Base print speed: 40mm/s
- Infill: Hexagon 15%
- Supports: No
- Raft: No
- Brim: Yes, fully enabled, no brim generated in holes
Like the motion detector and all other outdoor projects, I will use waterproof silicone and electrical tape to seal cases and protect the circuit boards.
This project is part of the larger Home Hub Project with Node-Red
This page (Home Hub: Camera) was last updated on January 21, 2026.