diff --git a/.gitignore b/.gitignore index b3666ee..32ac57a 100644 --- a/.gitignore +++ b/.gitignore @@ -57,5 +57,9 @@ backend/backend # Go coverage output *.out +# Environment variables +.env +*.env + # Dependency directory (if you ever vendor dependencies) vendor/ \ No newline at end of file diff --git a/CAMERA_SETUP.md b/CAMERA_SETUP.md new file mode 100644 index 0000000..fd712f5 --- /dev/null +++ b/CAMERA_SETUP.md @@ -0,0 +1,130 @@ +# FiremeX Camera Setup Guide + +This guide explains how the camera integration works in FiremeX, specifically how to bridge your physical MacBook webcam into the system via Home Assistant (HA). + +## ๐๏ธ Architecture Overview + +Home Assistant runs in a Docker container, which means it cannot directly access the hardware of the host machine (your Mac's built-in webcam). To solve this, we create a small network bridge using a Python server. + +```mermaid +flowchart TD + subgraph Host Machine (Mac) + Cam[Built-in Webcam] + Py[Python MJPEG Server\n:8090] + end + + subgraph Docker + HA[Home Assistant\n:8123] + end + + subgraph FiremeX System + Go[Go Backend\n:8080] + React[Frontend App\n:5173] + end + + Cam -->|Video Frames| Py + Py -->|MJPEG Stream over HTTP| HA + HA -->|Proxy Stream Request| Go + Go -->|Proxied Stream| React +``` + +## ๐ ๏ธ Step-by-Step Setup + +### Step 1: Install Python Dependencies on your Mac + +You need a small Python script to capture webcam frames and serve them over HTTP as an MJPEG stream. + +```bash +pip3 install opencv-python flask +``` + +### Step 2: Create the Webcam Server Script + +Create a file named `webcam_server.py` on your Mac (e.g., on your Desktop or in the project root): + +```python +import cv2 +from flask import Flask, Response + +app = Flask(__name__) + +# 0 is usually the default built-in webcam +camera = cv2.VideoCapture(0) + +def generate_frames(): + while True: + success, frame = camera.read() + if not success: + break + + # Encode frame as JPEG + _, buffer = cv2.imencode('.jpg', frame) + frame_bytes = buffer.tobytes() + + # Yield as MJPEG stream + yield ( + b'--frame\r\n' + b'Content-Type: image/jpeg\r\n\r\n' + frame_bytes + b'\r\n' + ) + +@app.route('/stream') +def stream(): + return Response( + generate_frames(), + mimetype='multipart/x-mixed-replace; boundary=frame' + ) + +@app.route('/') +def index(): + return '
Manage active network streams & devices
+Manage Home Assistant camera streams & devices
Configure a new camera stream for the secure network.
+Select a Home Assistant camera entity to add to FiremeX.