~krystianch/home

This page covers setting up self-hosted multicamera backyard surveillance system.

The system consists of multiple Raspberry Pi devices connected to a common local network. One device called the hub receives video streams and produces seekable HLS streams and at the same time saves video segments to disk. Other devices called camera devices transmit video streams from a camera to the hub device. The idea is that the hub device is installed inside and camera devices are mounted outside in electrical boxes with Ethernet and PoE.

Note: The following builds on configuration from the Provisioning a New Device page.

#Camera devices

Repeat the following steps for every camera device.

#Hardware

Parts:

  • a Raspberry Pi board, any generation, model B (with Ethernet)
  • a microSD memory card
  • mini radiators (optional)
  • a Raspberry Pi Camera Module (possibly NoIR) with ribbon
  • a RPi Camera mount (or standard ball mount and custom rig for the camera)
  • M5 standoffs and screws
  • a passive PoE injector/switch
  • a 5V-3A-capable step-down converter board (e.g. LM2596)
  • a bit of stranded copper wire with a 1x2 goldpin receptacle
  • a fuse holder and a fuse (current rating depends on PoE voltage)
  • an outdoor-rated RJ-45 receptacle
  • a lot of network cable and plugs (cat. 5 unshielded is probably enough)
  • an electrical box

Tools:

  • drill
  • small phillips head screwdriver
  • small flathead screwdriver
  • soldering iron and solder
  • multimeter
  • needle-nose pliers
  • RJ-45 terminator
  • tools for mounting the elecrical box in desired place

Wiring: TODO

[camera box example v1]

[camera box example v2]

#Software

We will use the firmware interface for communication with the Raspberry Pi camera. It's because the new blob-free libcamera interface is still experimental and I wasn't able to get it to work on Alpine Linux.

Download files with firmware blobs that contain camera drivers and codecs. But first, to edit OS files, the partition needs to be remounted read-write.

mount /media/mmcblk0p1 -o rw,remount
apk add curl
curl 'https://raw.githubusercontent.com/raspberrypi/firmware/master/boot/start_x.elf' > /media/mmcblk0p1/start_x.elf
curl 'https://raw.githubusercontent.com/raspberrypi/firmware/master/boot/fixup_x.dat' > /media/mmcblk0p1/fixup_x.dat

Instruct to load firmware to the VideoCore GPU before boot.

echo "start_file=start_x.elf" >> /media/mmcblk0p1/config.txt
echo "fixup_file=fixup_x.dat" >> /media/mmcblk0p1/config.txt

If your camera is already connected, just reboot. Of not, poweroff, disconnect power, connect camera and connect power.

#Verification

After reboot, verify if you are able to obtain images from the camera.

apk add raspberrypi
/opt/vc/bin/raspivid -t 0

You should be able to see a video feed via Pi's HDMI.

#Raspivid service

We will use raspivid's tcp output to send live video to the camera hub device.

Create /etc/init.d/raspivid with the following contents.

#!/sbin/openrc-run

name=raspivid
command="/opt/vc/bin/$name"
command_args="$raspivid_opts"
command_user="raspivid:raspivid"
supervisor=supervise-daemon
respawn_delay=1
respawn_max=0

depend() {
	need net
	after firewall
}

start_pre() {
	[ -n "$output_log" ] && checkpath -f "$output_log" \
		-m 644 -o raspivid:raspivid
	[ -n "$error_log" ] && checkpath -f "$error_log" \
		-m 644 -o raspivid:raspivid
}

Make it executable and add this file to LBU.

chmod +x /etc/init.d/raspivid
lbu add /etc/init.d/raspivid

Create /etc/conf.d/raspivid with the following contents. These parameters can be tuned. Set the --output to the address of your hub device and adjust the --annotate option to reflect the name of the camera.

Notice: The H264 encoder that raspivid uses is limited to 1920x1080 px resolution. In order to use higher resolutions one needs to use MJPEG instead.
raspivid_opts=" \
	--nopreview \
	--output tcp://192.168.1.10:8083 \
	--timeout 0 \
	--flush \
	--codec H264 \
	--rotation 180 \
	--mode 4 \
	--annotate $(( 1024 | 8 | 4 )) \
	--annotate '%Y-%m-%d %X ROAD' \
	--bitrate 0 \
	--width 1640 \
	--height 1232 \
	--qp 25 \
	--framerate 15 \
"

output_log=/var/log/raspivid.log
error_log=/var/log/raspivid.log

Add required raspivid user and add it to video group.

addgroup -S raspivid
adduser -SDh/dev/null -s/sbin/nologin -Graspivid -graspivid raspivid raspivid
adduser raspivid video

Start the service, enable starting it on boot and save changes.

rc-service raspivid start
rc-update add raspivid
lbu commit -d

#Hub devices

TODO

About this wiki

commit 8bdf3a5d5e337a801660bceb0913cbcd427596ba
Author: Krystian ChachuĊ‚a <krystian@krystianch.com>
Date:   2023-11-22T20:13:32+01:00

Add chrony makestep
Clone this wiki ("wiki" branch)
https://git.sr.ht/~krystianch/home-docs (read-only)
git@git.sr.ht:~krystianch/home-docs (read/write)