A comprehensive home security solution that monitors RTSP-enabled cameras, detects visitors using motion detection, and provides real-time alerts and daily summaries.
- Features
- System Architecture
- Prerequisites
- Detailed Installation
- Configuration
- Usage
- Development
- Troubleshooting
- Performance Considerations
- Security Considerations
- Version History
- Contributing
- License
- Support
- 📹 Live Streaming: View real-time video feeds from multiple RTSP cameras with minimal latency
- 🚨 Motion Detection: Intelligent detection of movement and visitors using OpenCV image processing
- 📸 Automatic Capture: Save high-quality snapshots (configurable resolution) when motion is detected
- 📊 Dashboard: Web-based interface to monitor and review activity with customizable layouts
- 📧 Daily Reports: Email summaries with visitor timestamps, images, and motion analytics
- 🔍 Searchable History: Easily review past visitor events with advanced filtering options
- 🔔 Real-time Notifications: Instant alerts via email, browser notifications, or webhook integrations
- 📱 Mobile Responsive: Access your security system from any device with a responsive design
- 🌙 Night Mode: Enhanced visibility in low-light conditions with automatic day/night mode switching
- 🔄 Auto-Recovery: System auto-restarts stream connections if cameras disconnect
┌───────────────┐ ┌───────────────┐ ┌───────────────┐
│ RTSP Cameras │────▶│ FFmpeg HLS │────▶│ Web Browser │
└───────────────┘ │ Conversion │ └───────────────┘
└───────┬───────┘
│
┌───────▼───────┐ ┌───────────────┐
│ Node.js │◀───▶│ MongoDB │
│ Backend │ │ Database │
└───────┬───────┘ └───────────────┘
│
┌───────▼───────┐ ┌───────────────┐
│ React.js │────▶│ Email │
│ Frontend │ │ Service │
└───────────────┘ └───────────────┘
The system utilizes a microservices architecture with:
- Stream Processing Service: Handles camera connections and video transcoding
- Detection Service: Processes frames for motion detection
- Storage Service: Manages image and video storage with retention policies
- Notification Service: Handles alerts and report generation
- Web Interface: Provides user dashboard and controls
- Node.js 16+ (v16.15.0 or higher recommended for optimal performance)
- MongoDB 5.0+ (with replica set for production deployments)
- FFmpeg 4.4+ with libx264 and libx265 support
- TP-Link Tapo cameras with RTSP enabled (tested with C200, C310, and C320WS models)
- Minimum hardware requirements:
- CPU: 4-core processor (Intel i5/AMD Ryzen 5 or better)
- RAM: 4GB minimum, 8GB recommended
- Storage: 50GB+ SSD recommended for performance
- Network: Gigabit Ethernet recommended for multiple camera streams
# Update system packages
sudo apt update && sudo apt upgrade -y
# Install required dependencies
sudo apt install -y ffmpeg build-essential python3-dev
# Install MongoDB (Community Edition)
wget -qO - https://www.mongodb.org/static/pgp/server-5.0.asc | sudo apt-key add -
echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu focal/mongodb-org/5.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-5.0.list
sudo apt update
sudo apt install -y mongodb-org
sudo systemctl enable mongod
sudo systemctl start mongod# Install Homebrew if not installed
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
# Install required dependencies
brew install node ffmpeg mongodb-community
brew services start mongodb-communitygit clone https://github.com/yourusername/home-security.git
cd home-securitynode scripts/setup.jsThe setup script performs the following actions:
- Verifies system requirements
- Creates necessary directories
- Initializes the database with default settings
- Sets up initial user accounts
- Tests camera connectivity
Create a .env file in both the backend and frontend directories using the provided templates:
backend/.env:
# Server Configuration
PORT=5000
NODE_ENV=development
LOG_LEVEL=info
CORS_ORIGIN=http://localhost:3000
# Database
MONGODB_URI=mongodb://localhost:27017/home_security
DB_BACKUP_PATH=./backups
# Camera Configuration
CAMERA1_NAME=Front Door
CAMERA1_URL=rtsp://username:password@camera1-ip:554/stream1
CAMERA1_DETECTION_SENSITIVITY=0.75
CAMERA2_NAME=Backyard
CAMERA2_URL=rtsp://username:password@camera2-ip:554/stream1
CAMERA2_DETECTION_SENSITIVITY=0.60
# HLS Streaming
HLS_SEGMENT_DURATION=4
HLS_OUTPUT_PATH=./storage/hls
HLS_PLAYLIST_SIZE=6
# Motion Detection
MOTION_DETECTION_ENABLED=true
MOTION_SENSITIVITY=0.65
DETECTION_INTERVAL_MS=500
MIN_AREA_PERCENT=0.5
COOL_DOWN_PERIOD_MS=10000
# Storage
STORAGE_PATH=./storage
SCREENSHOT_PATH=./storage/screenshots
RETENTION_DAYS=30
# Email Configuration
EMAIL_SERVICE=gmail
EMAIL_USER=your-email@gmail.com
EMAIL_PASS=your-app-password
REPORT_RECIPIENT=your-email@example.com
DAILY_REPORT_TIME=08:00
NOTIFICATIONS_ENABLED=true
# Security
JWT_SECRET=your-jwt-secret-key
JWT_EXPIRY=8h
RATE_LIMIT_WINDOW_MS=900000
RATE_LIMIT_MAX=100
frontend/.env:
REACT_APP_API_URL=http://localhost:5000/api
REACT_APP_SOCKET_URL=http://localhost:5000
REACT_APP_VERSION=1.0.0
# Install backend dependencies
cd backend
npm install
# Install frontend dependencies
cd ../frontend
npm installcd frontend
npm run build# Start MongoDB (if not already running)
mongod --dbpath=/path/to/data/directory
# Start the backend (in a new terminal)
cd backend
npm start
# For development mode with auto-reload:
npm run dev
# Start the frontend for development (in a new terminal)
cd frontend
npm startFor production deployment, it's recommended to use process managers:
# Install PM2 globally
npm install -g pm2
# Start the backend with PM2
cd backend
pm2 start server.js --name "home-security-backend"
# Configure PM2 to start on system boot
pm2 startup
pm2 save- Download the Tapo app on your mobile device
- Add your camera to the app
- Navigate to Settings > Advanced Settings > RTSP
- Enable RTSP and note down the username, password, and port
- The RTSP URL format is:
rtsp://username:password@camera-ip:554/stream1
- High Definition Stream:
rtsp://username:password@camera-ip:554/stream1(1080p) - Standard Definition Stream:
rtsp://username:password@camera-ip:554/stream2(720p) - Low Definition Stream:
rtsp://username:password@camera-ip:554/stream3(360p)
Choose the appropriate stream based on your network bandwidth and processing capabilities.
The system uses advanced computer vision techniques for motion detection. Configure the sensitivity in backend/config/detection.js:
// Example settings for different environments
const detectionSettings = {
indoor: {
sensitivity: 0.65,
minArea: 0.02,
cooldownPeriod: 10000,
regionMask: [0, 0, 1, 1] // Full frame
},
outdoor: {
sensitivity: 0.55, // Lower sensitivity for outdoor (more noise)
minArea: 0.03, // Larger minimum area to reduce false positives
cooldownPeriod: 15000,
regionMask: [0, 0.3, 1, 0.7] // Only middle portion of frame
}
};- Set up a Gmail account (or other supported email provider)
- Enable 2-Factor Authentication
- Generate an app password: Google Account > Security > App Passwords
- Update email settings in
backend/.env
Edit the email templates in backend/services/email/templates/ to customize the appearance of daily reports and notifications.
- Live View: Real-time camera feeds with motion indicators
- History: Timeline of detected events with filtering options
- Analytics: Charts and statistics about motion events
- Settings: System configuration and camera settings
- Alerts: Notification preferences and history
F- Toggle fullscreen modeM- Mute/unmute audio1-9- Switch between camera viewsS- Take a screenshot of current viewR- Start/stop recordingTab- Cycle through cameras
The responsive design works on mobile devices. For optimal experience:
- Use Chrome or Safari on iOS/Android
- Add to home screen for full-screen experience
- Enable notifications in browser settings
home-security/
├── backend/ # Backend server code
│ ├── config/ # Configuration files
│ ├── controllers/ # Request handlers
│ ├── models/ # Database models
│ ├── routes/ # API routes
│ ├── services/ # Business logic
│ ├── utils/ # Utility functions
│ └── server.js # Express application
├── frontend/ # Frontend application
│ ├── public/ # Static files
│ └── src/ # React source code
├── scripts/ # Utility scripts
├── storage/ # Data storage
└── tests/ # Test files
# Run backend unit tests
cd backend
npm test
# Run backend integration tests
npm run test:integration
# Run frontend tests
cd frontend
npm test
# Run end-to-end tests
npm run test:e2eThe project follows Airbnb JavaScript Style Guide. Run linting with:
# Backend linting
cd backend
npm run lint
# Frontend linting
cd frontend
npm run lintnode scripts/backup.js --output=/path/to/backup/directoryThis will create a backup of:
- MongoDB database (full dump)
- Captured screenshots (with metadata)
- Generated reports (PDF and HTML formats)
- System configuration
cd backend
npm run migrate- Verify camera is powered on and connected to network
- Check RTSP URL, username, and password
- Ensure port 554 is not blocked by firewall
- Try connecting with VLC player to verify RTSP stream
- Check logs:
backend/logs/camera.log
- Adjust sensitivity in settings
- Check camera position for moving objects (trees, etc.)
- Verify adequate lighting conditions
- Review detection zones configuration
- Check logs:
backend/logs/detection.log
- Verify MongoDB is running:
systemctl status mongod - Check connection string in
.env - Ensure database permissions are correct
- Run repair if database was not shutdown properly:
mongod --repair --dbpath=/path/to/data/directory
- Check logs:
backend/logs/database.log
Important log files for troubleshooting:
backend/logs/app.log- Main application logsbackend/logs/error.log- Error-level logsbackend/logs/camera.log- Camera connection detailsbackend/logs/http.log- API request logs
For more advanced troubleshooting:
- Run diagnostic script:
node scripts/diagnostics.js - Include diagnostics output when seeking support
- Open an issue in the GitHub repository with detailed steps to reproduce
- Each 1080p camera stream requires approximately 2Mbps bandwidth
- CPU usage scales with number of cameras and detection sensitivity
- Consider dedicated hardware for 4+ cameras
- Use lower resolution streams for detection (720p or lower)
- Adjust motion detection interval based on CPU capability
- Set appropriate retention periods to manage disk usage
- Use network QoS to prioritize camera traffic
- Consider edge processing if cameras support it
The system has been tested with:
- Up to 8 cameras on a quad-core 3.5GHz CPU with 16GB RAM
- Up to 90 days of history with 1TB storage
- Up to 10 concurrent dashboard users
-
Network Security
- Use HTTPS in production (SSL certificates provided via Let's Encrypt)
- Keep RTSP streams on a separate VLAN or subnet
- Change default camera credentials
- Use a VPN for remote access instead of direct port forwarding
-
Data Protection
- Encrypt sensitive data at rest using MongoDB encryption
- Implement proper access controls with role-based permissions
- Regular database backups with encryption
- Implement data retention policies to comply with privacy regulations
-
Authentication
- Use JWT for API authentication with short expiration times
- Implement rate limiting to prevent brute force attacks
- Enforce strong password policies (minimum length, complexity)
- Support multi-factor authentication for admin accounts
- Implement IP-based access restrictions for sensitive operations
-
Updating Dependencies
- Regularly run
npm auditto check for vulnerabilities - Set up automated dependency updates via dependabot
- Follow security best practices for Node.js applications
- Regularly run
- v1.0.0 (2023-05-15) - Initial release
- v1.1.0 (2023-06-30) - Added multi-camera support and email notifications
- v1.2.0 (2023-08-15) - Improved motion detection algorithm and mobile UI
- v1.3.0 (2023-10-20) - Added analytics dashboard and performance optimizations
- v1.4.0 (2023-12-10) - Added HLS streaming support and browser notifications
- v1.5.0 (2024-02-28) - Added customizable detection zones and event filtering
- v1.6.0 (2024-04-15) - Added AI-based object detection (persons, vehicles, animals)
- Fork the repository
- Create a feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Create a Pull Request
Please read CONTRIBUTING.md for detailed guidelines.
This project is licensed under the MIT License - see the LICENSE file for details.
For support, please:
- Check the FAQ
- Search for similar issues in the issue tracker
- Open a new issue with detailed description and steps to reproduce
- For urgent matters, contact: support@example.com