Show HN: CheapSecurity – Lightweight, Self-Hosted CCTV for Linux SBCs
CheapSecurity: A Budget-Friendly, Private CCTV System for Linux SBCs
Welcome to CheapSecurity, a streamlined, self-hosted surveillance solution tailored specifically for Linux-based Single-Board Computers (SBCs) utilizing standard USB webcams.
This project is designed to be a costly cloud-based affordable and privacy-centric alternative to commercial home monitoring, ensuring that your visual data remains entirely under your own jurisdiction.
🛡️ Project Philosophy
"True security comes from ownership."
The core tenets of CheapSecurity are:
- Privacy-First: By keeping all footage on local storage, the system removes the need for third-party cloud subscriptions and guarantees that your data never exits your local network.
- Cost-Effective: Instead of buying expensive proprietary kits, you can repurpose a spare Linux board and a basic USB webcam.
- Minimalist Architecture: The codebase is optimized for low-power environments, ensuring smooth operation even on entry-level hardware.
🚀 Key Capabilities
General Highlights
- Hardware Agnostic: Works with nearly any standard USB webcam.
- Resource Efficient: Specifically tuned for boards like the Raspberry Pi or Orange Pi.
- Data Sovereignty: You define the storage paths, how long files are kept, and who can access them.
- Rapid Deployment: Built for a "plug-and-play" experience with minimal maintenance.
Detailed Feature Set
| Feature | Description |
|---|---|
| Live Stream | MJPEG stream accessible via a dedicated web dashboard. |
| Motion Detection | Uses frame differencing to trigger events. |
| Smart Recording | Automatic clips with a pre-motion buffer to capture the lead-up to an event. |
| Email Alerts | Sends a snapshot image immediately upon motion detection. |
| Telegram Bot | Automatic video uploads and interactive commands: /snapshot, /video [seconds], and /help. |
| Night Mode | Software-based enhancement using CLAHE + brightness/contrast boosts. |
| File Management | Bulk actions: select all, download as ZIP, send to Telegram, or delete. |
| Auto-Cleanup | Storage management based on file age, total disk size, or emergency low-disk triggers. |
| OS Integration | Ready for systemd autostart. |
License: This project is distributed under the GNU AGPLv3.
🛠️ Technical Workflow
The following diagram illustrates how CheapSecurity processes video data:
The Math Behind Motion
Motion is detected by calculating the absolute difference between frames. If the number of pixels exceeding a certain threshold is greater than the minimum area , motion is triggered:
📦 Installation Guide
Prerequisites
- Python: Version 3.10 or higher.
- OpenCV: Must have V4L2 support.
- Hardware: A USB webcam (defaults to
/dev/video0). - Optional: SMTP details (Email) and a Bot Token/Chat ID (Telegram).
Setup Steps
-
Verify OpenCV: Run the following command to check your version:
python3 -c "import cv2; print(cv2.__version__)" -
Install OpenCV (If missing):
- Option A (Recommended for ARM/SBCs): Use the system package manager for optimized binaries.
- Option B (x86/amd64): Use
pip install opencv-python-headless(no GUI needed).
-
Environment Setup: Choose the method that matches your OpenCV installation:
Method A: System OpenCV (ARM)
cd $HOME/CheapSecurity python3 -m venv venv --system-site-packages source venv/bin/activate pip install -e .Method B: Pure Pip (x86)
cd $HOME/CheapSecurity python3 -m venv venv source venv/bin/activate pip install opencv-python-headless pip install -e . -
Hardware Configuration: Identify your camera:
v4l2-ctl --list-devices -
Application Configuration:
cp config.json.example config.json nano config.jsonNote:
config.jsonis ignored by git for security; never commit your credentials. -
Launch:
./venv/bin/python -m cheapsecurity.appAccess the UI at:
http://<your-device-ip>:5000
⚙️ Configuration Reference
Modify config.json to tune the system behavior:
| Section | Key | Purpose |
|---|---|---|
| Camera | device | V4L2 index (e.g., 0 for /dev/video0) |
width, height, fps | Resolution and frame rate settings | |
night_mode | Toggle low-light enhancement | |
night_mode_fps | Target FPS during night mode | |
night_mode_gain | Analog gain target | |
night_mode_brightness | Brightness boost level | |
night_mode_contrast | Contrast boost level | |
| Motion | threshold | Pixel difference sensitivity (0-255) |
min_area | Minimum pixel area to trigger (full-res) | |
cooldown_seconds | Duration to keep recording after motion stops | |
scale | Downscale factor to reduce CPU load | |
| Recording | dir | Local directory for video storage |
max_duration_seconds | Maximum length of a single clip | |
pre_buffer_seconds | Amount of lead-in footage to save |