Add motion detection to camera server

🔍 New features:
- motion.py: Frame differencing motion detector
- Background thread compares frames continuously
- Configurable threshold, cooldown, sensitivity
- POSTs events + snapshot to collector

📡 New endpoints:
- GET /motion/stats - Detection statistics
- POST /motion/enable - Start detection
- POST /motion/disable - Stop detection

⚙️ Configuration (in .env):
- MOTION_ENABLED: true/false
- MOTION_THRESHOLD: Pixel diff threshold
- MOTION_COOLDOWN: Seconds between events
- COLLECTOR_URL: Where to POST events

Next: Event collector in vixy-mcp 🦊
This commit is contained in:
2025-12-16 16:15:30 -06:00
parent a17c09cac1
commit 6ecdf998c1
5 changed files with 478 additions and 116 deletions

47
server/env.example Normal file
View File

@@ -0,0 +1,47 @@
# vixy-vision Server Configuration
# Copy to .env and customize
# ============ Required ============
# API Key for authentication (generate with: python3 -c 'import secrets; print(secrets.token_urlsafe(32))')
API_KEY=your-secret-key-here
# Camera identifier (used in events)
CAMERA_ID=basement
# ============ Camera Settings ============
# Camera device index (0 = first USB camera)
CAMERA_INDEX=0
# Resolution (camera will use closest supported)
CAMERA_WIDTH=1920
CAMERA_HEIGHT=1080
# JPEG quality (1-100)
JPEG_QUALITY=85
# ============ Motion Detection ============
# Enable motion detection (true/false)
MOTION_ENABLED=true
# Pixel difference threshold (lower = more sensitive)
MOTION_THRESHOLD=25
# Minimum % of frame that must change to trigger event
MOTION_MIN_AREA=0.5
# Seconds between motion events (prevents spam)
MOTION_COOLDOWN=5.0
# Seconds between frame checks
MOTION_INTERVAL=0.5
# ============ Event Collector ============
# URL to POST motion events to (on Mac mini)
COLLECTOR_URL=http://192.168.1.50:8780/events
# API key for collector (optional)
COLLECTOR_API_KEY=