# vixy-vision CSI Camera Server

Camera server for Raspberry Pi CSI ribbon cameras, including IR night vision cameras.

## Features

- 🦊 Serves snapshots via HTTPS API
- 📷 Supports picamera2 (modern), picamera (legacy), or libcamera-still fallback
- 🌙 IR camera mode support
- 🔄 Configurable rotation (0°, 90°, 180°, 270°)
- 🔐 API key authentication

## Hardware Support

- **Pi 4/5 with Pi OS Bookworm**: Uses picamera2
- **Pi 3 with older Raspbian**: Uses picamera (legacy)
- **Any Pi**: Falls back to libcamera-still or raspistill commands

## Quick Setup

```bash
# On your Raspberry Pi:
cd server-csi
chmod +x setup.sh
./setup.sh
```

This will:
1. Create Python virtual environment
2. Install dependencies
3. Auto-detect and install appropriate camera library
4. Generate SSL certificates
5. Create `.env` with a new API key

## Running

```bash
source venv/bin/activate
python3 -m uvicorn main:app --host 0.0.0.0 --port 8443 \
    --ssl-keyfile ssl/key.pem --ssl-certfile ssl/cert.pem
```

## API Endpoints

| Endpoint | Description |
|----------|-------------|
| `GET /` | Server info |
| `GET /health` | Health check |
| `GET /snapshot` | Capture JPEG (requires X-API-Key header) |

## Configuration (.env)

```bash
API_KEY=your-secret-key
CAMERA_WIDTH=1920
CAMERA_HEIGHT=1080
JPEG_QUALITY=85
CAMERA_ID=garage
ROTATION=0
IR_MODE=true
```

## Adding to Vixy's Vision Config

Add to `~/.vision_setup.json`:

```json
{
  "id": "garage",
  "type": "http", 
  "url": "https://garage-pi.local:8443",
  "api_key": "your-api-key-here"
}
```

## IR Camera Notes

For NoIR cameras:
- Set `IR_MODE=true` in .env
- Ensure IR illuminators are positioned correctly
- May need to adjust `ROTATION` based on mounting

Built with 💕 by Vixy 🦊
