Skip to content

Instantly share code, notes, and snippets.

@gtxaspec
Last active November 27, 2025 11:32
Show Gist options
  • Select an option

  • Save gtxaspec/3dd8d4f8b64ac78f16195824f9732e8c to your computer and use it in GitHub Desktop.

Select an option

Save gtxaspec/3dd8d4f8b64ac78f16195824f9732e8c to your computer and use it in GitHub Desktop.
thingino-nfs.md

Automating Camera Behavior with Thingino and rc.local

In a Thingino-powered network setup, every camera can be configured to automatically register via MQTT and record video directly to an NFS share using a small script added to /etc/rc.local on each device. This approach centralizes control and customization, allowing you to modify behavior for all cameras from a single server.

This file can be included in each firmware build by including the modified rc.local file in thingino-firmware/overlay/upper/etc/rc.local


Setup Overview

  1. On Each Camera:

    • A simple script is added to /etc/rc.local to execute custom behavior at boot by fetching a script from the central server.
  2. On the Central Server:

    • A customizable script, rc-local-camera.sh, handles mounting NFS shares and starting camera-specific processes.

Camera /etc/rc.local

The /etc/rc.local file ensures the camera fetches and executes the server-provided script at boot:

#!/bin/sh
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.

curl -sSL http://router.lan/rc-local-camera.sh | sh

exit 0

Key Points:

  • curl Command: Downloads and executes the rc-local-camera.sh script from the central server.
  • Dynamic Behavior: Cameras automatically adopt updated scripts without requiring individual configuration changes.

Server Script: rc-local-camera.sh

This script defines camera behavior and is served from the central server:

#!/bin/sh

# Mount shared NFS directories
mkdir -p /mnt/nfs_root
mount -t nfs -o rw,async,noatime,nolock,rsize=1048576,wsize=1048576 \
router.lan:/mnt/backup/nfs_root /mnt/nfs_root

mkdir -p /mnt/nfs
mount -t nfs -o rw,async,noatime,nolock,rsize=1048576,wsize=1048576 \
router.lan:/mnt/HomeAssistant/media/record/$(hostname)/ /mnt/nfs

# Start recording and MQTT registration
/mnt/nfs_root/sbin/ffmpeg-record.sh &
/mnt/nfs_root/sbin/mqtt-full.sh $(hostname)

Key Points:

  1. NFS Mounts:

    • Mounts a shared root NFS directory (/mnt/nfs_root).
    • Mounts a camera-specific NFS directory (/mnt/nfs), dynamically named based on the camera’s hostname.
  2. Recording and MQTT Registration:

    • ffmpeg-record.sh: Starts video recording directly to the mounted NFS directory.
    • mqtt-full.sh: Registers the camera with the MQTT broker using the camera’s hostname.
  3. Custom Behavior via hostname:

    • Allows per-camera customization based on hostname, configured dynamically by the server script.

Benefits of This Approach

  1. Centralized Management:

    • Update camera behavior by modifying the server script without physically accessing each device.
    • Push custom configurations or updates instantly to all cameras.
  2. Dynamic Per-Camera Behavior:

    • Use the hostname to customize NFS paths, recording settings, or MQTT topics for individual cameras.
  3. Scalability:

    • Add new cameras by simply pointing their /etc/rc.local to the server’s script. No manual configuration required.
  4. Ease of Maintenance:

    • No need to log into each camera to make changes.
    • A single script update propagates to all devices.

Example Use Case

  • Home Automation Integration:
    • Cameras record to an NFS share accessed by Home Assistant for media storage.
    • MQTT messages from cameras trigger automations, such as motion alerts or snapshot processing.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment