Security-Cam Documentation

website·Indexed 31 days ago

https://dev.infinitel8p.com/Security-Cam/

A security camera system for the Raspberry Pi Zero 2 W featuring modular trigger sensors, a Flask backend API on port 5005, and an Astro dashboard. Includes guides on hardware installation, MediaMTX setup, sensor calibration, and REST endpoint authentication for managing system functions and logs.

Tokens
18.7K
Snippets
90
Records
154
Agent score
50%

What's inside Security-Cam

  1. Overview of Security-Cam for Raspberry Pi Zero 2 W

    Security-Cam is a security camera system designed for the Raspberry Pi Zero 2 W. It automatically records video when a modular trigger sensor is activated, provided that no tracked devices (via Bluetooth or WiFi) are detected nearby. Recording stops once the sensor resets. The system supports a variety of modular sensors that can be swapped without changing code.
  2. Retrieve deployment and archive information

    Access metadata about the current installation and new content counts.

    • Deployment Info: GET /deploy_info returns the git_branch and git_commit if the project is a git repository.
    • Archive Count: GET /archive/new_count?since=<ISO_TIMESTAMP> returns the number of recordings, timelapses, and snapshots created after the specified time. This is used for dashboard notification badges and is updated via SSE archive_updated events.
    # Get deployment info
    curl http://<pi-ip>:5005/deploy_info
    
    # Count new recordings since a date
    curl "http://<pi-ip>:5005/archive/new_count?since=2026-04-01T10:00:00%2B00:00"
  3. Access the Security Camera Logs page

    The Logs page allows you to inspect, search, and filter system log output in real time for debugging and monitoring. It is accessible via the browser using the Raspberry Pi's IP address.
    http://<raspberry-pi-ip>:3000/logs
  4. Enable night vision using Waveshare RPi Camera (F)

    The system supports clear visibility in complete darkness by utilizing the built-in infrared LEDs of the Waveshare RPi Camera (F).
  5. Understand the automatic recording trigger flow

    The security camera uses a modular trigger system to start recordings automatically based on the following logic:

    1. Sensor fires: A hardware event is detected (e.g., door opens, motion detected).
    2. Presence check: The system checks if any tracked Bluetooth or WiFi devices are nearby.
    3. Decision:
      • If nobody is home: Recording starts automatically.
      • If someone is home: The trigger is ignored to prevent false alarms.
    4. Stop: Recording stops after the sensor releases and a configurable hold timeout expires.

    Note: Manual recording via the dashboard bypasses the presence check and always starts regardless of sensor state.

  6. Access the Security-Cam Dashboard

    The system provides a network-accessible dashboard that allows users to view the live feed, browse the video archive, monitor system health, and manage settings from any device on the local network.
  7. Locate your device's Bluetooth MAC address

    The Bluetooth MAC address is required to identify a device in scan results and for the security camera's presence detection.

    • Android: Navigate to Settings → About phone → Status information → Bluetooth address
    • iPhone: Navigate to Settings → General → About → Bluetooth
  8. Prevent disk overflow using Auto-delete

    The auto-delete feature prevents the SD card from filling up by removing the oldest recordings when disk usage exceeds a specific threshold. The system checks disk usage before every new recording and every 5 minutes in the background.

    To enable:

    1. Go to Settings > Storage.
    2. Toggle Auto-delete old recordings to on.
    3. Set the usage threshold (default is 85%).
    4. Click Save.
  9. Connect the DS3231 Real Time Clock (RTC) Module

    The DS3231 RTC module provides timekeeping for the system. The NC (Not Connected) pin on the module is not used.

    Wiring Mapping:

    DS3231 PinWire ColorRaspberry Pi PinFunction
    3.3VRedPin 13V3
    SDAOrangePin 3SDA
    SCKYellowPin 5SCL
    GNDGreenPin 6 or 9GND
  10. Filter and analyze API logs using logger namespaces

    The backend writes to logs/api/security-cam.log. Each log entry includes a timestamp, level, and a dot-separated logger name indicating the subsystem. You can use grep to filter logs by these namespaces.
    # All Bluetooth activity
    grep "bt\." /opt/security-cam/logs/api/security-cam.log
    
    # Just pairing issues
    grep "bt.pair" /opt/security-cam/logs/api/security-cam.log
    
    # Only errors and warnings
    grep -E "WARNING|ERROR" /opt/security-cam/logs/api/security-cam.log
    
    # Follow live Bluetooth activity
    tail -f /opt/security-cam/logs/api/security-cam.log | grep "bt\."
  11. Connect and test the KY-025 Magnet Reed Switch

    The KY-025 magnetic reed switch is connected to the Raspberry Pi GPIO pins. The AO (Analog Output) pin on the KY-025 is not used because the Raspberry Pi lacks analog input pins.

    Wiring Mapping:

    KY-025 PinWire ColorRaspberry Pi PinFunction
    GNDBlackPin 14GND
    DOBluePin 15GPIO22
    + (VCC)RedPin 173V3

    Once connected, the red LED on the KY-025 should light up. Use the provided test script to verify the sensor triggers when a magnet is nearby.

    python3 /opt/security-cam/setup/test_reed_switch.py
  12. Update and restart security camera software

    The dashboard checks for updates every 12 hours. A blue dot on the Settings icon indicates available updates.

    • Update & Restart: Applies new commits by running setup/update.sh, which pulls code, installs dependencies, and rebuilds the frontend. This restarts the security-cam service.
    • Restart Services: Restarts the Flask API and Astro dashboard without rebooting the Pi (equivalent to sudo systemctl restart security-cam).
    • Reboot Device: Performs a full Raspberry Pi reboot (equivalent to sudo systemctl reboot).