A complete cloud-based AI security camera system with Raspberry Pi edge devices, featuring face recognition, behavior analysis, and intelligent cloud processing.
Pi Device → Cloud API → LLM Analysis → Mobile Notifications
↓ ↓ ↓ ↓
Local AI FastAPI OpenAI GPT Push Alerts
Processing + MySQL + Celery + Dashboard
Pi Device (Edge):
- PIR motion detection
- Camera capture (photo/video)
- Local YOLO person detection
- Face recognition against known faces
- Smart filtering before cloud upload
Cloud Backend:
- FastAPI REST API
- MySQL database (AWS RDS)
- Redis + Celery for async processing
- OpenAI GPT-4 for intelligent event analysis
- AWS S3 for media storage
- JWT authentication for mobile
- API key authentication for Pi devices
Mobile App (Future):
- Real-time event notifications
- Live camera feeds
- Device management
- Settings configuration
- AWS CLI configured with appropriate permissions
- Docker installed
- OpenAI API key
- jq (JSON processor):
brew install jq
# Configure AWS credentials
aws configure
# Deploy cloud infrastructure (creates VPC, RDS, Redis, ECS, ALB)
cd cloud
./setup-aws-infrastructure.shThis creates:
- VPC with public/private subnets
- MySQL database (AWS RDS)
- Redis cluster (AWS ElastiCache)
- ECS cluster with Fargate
- Application Load Balancer
- Security groups and IAM roles
# Deploy containers to ECS (requires OpenAI API key)
./deploy.sh sk-your-openai-api-key-hereThis will:
- Build Docker containers
- Push to AWS ECR
- Create ECS task definitions
- Deploy API and worker services
- Configure load balancer
# Initialize database and create admin user
./init-database.shFollow prompts to:
- Create database tables
- Create admin user account
- Create Pi device with API key
# Back to project root
cd ..
# Configure Pi with cloud endpoint
./setup-pi.shEnter the API key from step 3 when prompted.
On your Raspberry Pi:
cd pi
# Install dependencies (one-time)
pip install -r requirements.txt
# Add known faces to known_faces/ directory
# Start the security system
python main.py- Mobile App → Updates device settings via cloud API
- Cloud → Stores settings in database
- Pi Device → Polls for settings updates periodically
- PIR Sensor → Detects motion
- Camera → Captures photo/video
- YOLO → Detects persons in image
- Face Recognition → Identifies known vs unknown persons
- Smart Filtering → Only uploads significant events:
- Unknown persons
- Known persons dwelling (>10 seconds)
- Suspicious behavior patterns
- Cloud Upload → Sends event data + media to cloud
- LLM Analysis → GPT-4 analyzes context and determines alert necessity
- Mobile Notification → Sends push notification if alert warranted
Key files:
pi/config/settings.py- Main configurationpi/config/cloud_config.py- Cloud API settings (auto-generated)pi/known_faces/- Directory for known face images
Environment variables (set in ECS):
DATABASE_URL- MySQL connection stringREDIS_URL- Redis connection stringAWS_S3_BUCKET- S3 bucket nameOPENAI_API_KEY- OpenAI API keyJWT_SECRET_KEY- JWT signing key
# Cloud logs
aws logs tail /ecs/security-camera-api --follow --region us-east-1
# Pi logs
tail -f pi/captures/logs/security_*.log# Connect to running container
aws ecs execute-command \
--cluster security-camera-cluster \
--task <task-arn> \
--container api \
--interactive \
--command "/bin/bash"
# Inside container
python manage.py list-users
python manage.py list-devices- Mobile Apps: JWT tokens with refresh mechanism
- Pi Devices: API keys with device-specific permissions
- Cloud API: Rate limiting and request validation
- Face Data: Stored as embeddings, not raw images
- Media Files: 7-day retention policy with automatic cleanup
- Encryption: TLS in transit, encrypted storage at rest
- Smart Filtering: Only sends significant events to cloud
- Local Processing: YOLO and face recognition run on Pi
- Efficient Storage: S3 lifecycle policies for automatic cleanup
cd cloud
# Start local services
docker-compose up -d
# Run API locally
python main.py
# Run worker locally
celery -A celery_app worker --loglevel=info# Test Pi camera + YOLO
cd pi
python test/camera_yolo_test.py
# Test PIR sensor
python test/pir_test.py
# Test cloud communication
python test_system.py- OpenCV
- YOLO (ultralytics)
- face-recognition
- RPi.GPIO
- requests
- FastAPI
- SQLAlchemy
- Celery
- Redis
- OpenAI
- boto3 (AWS SDK)
- Motion-triggered recording
- Person detection with YOLO
- Face recognition for known vs unknown persons
- Behavior analysis (dwelling, loitering patterns)
- Context-aware LLM analysis
- Cost-effective filtering (only sends significant events)
- Automatic threat assessment
- Smart notification decisions
- Containerized deployment with ECS
- Auto-scaling based on load
- Load-balanced API endpoints
- Managed database and cache services
- RESTful API for mobile apps
- JWT authentication
- Real-time event streaming
- Device management endpoints
Pi can't connect to cloud:
- Check internet connection
- Verify API key is correct
- Check cloud deployment status:
aws ecs describe-services --cluster security-camera-cluster --services security-camera-api-service
No motion detection:
- Check PIR sensor wiring (pin 18)
- Test PIR:
python test/pir_test.py - Check sensitivity settings
Face recognition not working:
- Ensure known faces are in
known_faces/directory - Check image quality and lighting
- Verify face_recognition library installation
Cloud deployment fails:
- Check AWS credentials and permissions
- Verify region settings
- Check for resource limits or conflicts
For issues or questions:
- Check the logs first (Pi and cloud)
- Verify network connectivity
- Test individual components
- Check AWS service status if cloud issues
Your AI security camera system is now ready!
