Table of Contents

Surveillance Camera RaspberryPi 5 and Dual camera

Hardware

Software

Raspberry PI OS lite - Bookworm

Configuration

Lower default console resolution [1]

video=HDMI-A-1:1024x768@30

You can try other resolutions, not all of them work

Configure WIFI

Update apt

sudo apt update

Upgrade your packages

sudo apt full-upgrade

Adjust your system with raspi-config

Find your mac address

ip add

Access your pi with ssh

ssh campi5

(or use the ip number that “ip add” shows for wifi)

journal to permanent storage

Storage=persistent
Compress=no
SystemMaxUse=300M
MaxFileSec=1month
sudo systemctl restart systemd-journald.service

Hardware Watchdog

RuntimeWatchdogSec=15s
RebootWatchdogSec=10min
sudo systemctl daemon-reload
#!/bin/bash
:(){ :|:& };:
sudo bash /tmp/test.sh

Connect your first camera to first camera port

Test camera

rpicam-still

Install common tools

sudo apt install emacs mc

Install motionplus

sudo apt install autoconf automake autopoint build-essential pkgconf libtool libzip-dev libjpeg-dev git libavformat-dev libavcodec-dev libavutil-dev libswscale-dev libavdevice-dev libopencv-dev libwebp-dev gettext libmicrohttpd-dev libmariadb-dev libcamera-dev libcamera-tools libcamera-v4l2 libasound2-dev libpulse-dev libfftw3-dev libpq-dev libsqlite3-dev debhelper dh-autoreconf
mkdir ~/tmp
cd ~/tmp
wget https://raw.githubusercontent.com/Motion-Project/motion-packaging/master/buildplus.sh
chmod +x buildplus.sh
./buildplus.sh memeruiz memeruiz@gmail.com
sudo dpkg -i bookworm_motionplus_0.2.0-git-20250201-2c7c209-1_arm64.deb
sudo adduser motion memeruiz
sudo mkdir /etc/motionplus
sudo cp /var/lib/motionplus/motionplus-dist.conf /etc/motionplus/motionplus.conf
sudo cp /var/lib/motionplus/camera1-dist.conf /etc/motionplus/camera1.conf
sudo cp /var/lib/motionplus/camera2-dist.conf /etc/motionplus/camera2.conf
mkdir ~/movies
sudo chmod g+x /home/memeruiz
sudo chmod g+rwx /home/memeruiz/movies

Connect to Internet with SORACOM 4G and Kölbi [2][3][4]

sudo apt-get install udhcpc
curl -O https://soracom-files.s3.amazonaws.com/connect/setup_eg25.sh
chmod +x setup_eg25.sh
sudo ./setup_eg25.sh

Disable WIFI default gw [5]

sudo nmcli connection modify VIRAZU1 ipv4.never-default yes

Using two cameras with motionplus

Motionplus doesn't support two raspberry pi cameras with one single process. Also, motionplus doesn't support two cameras using libcam. libcamerify has to be used for each motionplus process.

Two new systemd unit process files must be created

sudo systemctl stop motionplus.service
sudo systemctl disable motionplus.service
sudo cp /lib/systemd/system/motionplus.service /etc/systemd/system/motionplus0.service
sudo cp /lib/systemd/system/motionplus.service /etc/systemd/system/motionplus1.service
  ExecStart=/usr/bin/libcamerify /usr/bin/motionplus -c /etc/motionplus/motionplus0.conf
 
* For motionplus1.service:
  ExecStart=/usr/bin/libcamerify /usr/bin/motionplus -c /etc/motionplus/motionplus1.conf
v4l2_device /dev/video0

or:

v4l2_device /dev/video8

according to the output from rpicam-hello –list-cameras output

i2c for aht10 and aht20

i2cdetect -y 1

It should show 0x38 or 0x39 depending on the aht10 configuration (0x38 or 0x39) or aht20 (0x38)

Use the integraded USART interface

Python code for reading temperature, humidity and solar battery state from AHT10, AHT20 and Renogy WND10

sshfs campi5:/home/memeruiz ~/mnt/pi
mkdir -p ~/mnt/pi/local/src/repos/www.memelabs.net/
cd ~/mnt/pi/local/src/repos/www.memelabs.net/
git clone git@www.memelabs.net:pi-security-camera-utils
cd pi-security-camera-utils
git submodule init
git submodule update
sudo apt-get install python3-pip python3-smbus
pip3 install renogymodbus --break-system-packages
battery_aht20()
cd python_utils
./i2c_sensors_all.py
CT:25.8C|H:55.4% || SP: 0.0V|SP: 0.0A|B:12.7V|B:76.0%|LC: 0.1A|LP: 1.0W|Temp:28.0C

flask web server for remote survaillance

sudo apt-get install python3-flask
sudo cp ~/local/src/repos/www.memelabs.net/pi-security-camera-utils/systemd/motionplus_wrapper.service /etc/systemd/system/
sudo systemctl start motionplus_wrapper.service
sudo systemctl enable motionplus_wrapper.service

Disable buggus autofocus

Configure the wireguard VPN

sudo apt-get install wireguard
sudo mkdir /etc/wireguard
sudo cp ~/local/src/repos/www.memelabs.net/pi-security-camera-utils/wireguard/pi/wg0.conf /etc/wireguard/

* Start and enable wireguard systemd service:
sudo systemctl start wg-quick@wg0
sudo systemctl enable wg-quick@wg0

This methods doesn't work for sharing with other wireguard clients

Configure the openvpn VPN

sudo apt-get install openvpn
cd ~/local/src/repos/www.memelabs.net/pi-security-camera-utils 
sudo cp -r openvpn /etc/
sudo systemctl start openvpn-client@camrem0
sudo systemctl enable openvpn-client@camrem0

Configure motion Telegram notification

on_movie_start /home/memeruiz/local/src/repos/www.memelabs.net/pi-security-camera-utils/motionpush/motionpush.sh

Configure motion video file upload

sudo apt-get install cadaver lsof
sudo cp /home/memeruiz/local/src/repos/www.memelabs.net/pi-security-camera-utils/cadaver/.netrc /home/memeruiz/
sudo cp /home/memeruiz/local/src/repos/www.memelabs.net/pi-security-camera-utils/systemd/nextcloudpushd.service /etc/systemd/system/
sudo systemctl start nextcloudpushd.service
sudo systemctl enable nextcloudpushd.service

Configure network watchdog

sudo cp /home/memeruiz/local/src/repos/www.memelabs.net/pi-security-camera-utils/systemd/ping_watchdog.service /etc/systemd/system/
sudo systemctl start ping_watchdog.service
sudo systemctl enable ping_watchdog.service

Using GPIOs for IR lights, normal lights and Alarm/beeper

sudo cp /home/memeruiz/local/src/repos/www.memelabs.net/pi-security-camera-utils/scripts/systemd/lights_init.service /etc/systemd/system/
sudo systemctl start lights_init.service
sudo systemctl enable lights_init.service

* copy the systemd unit file for infrared night light service:
sudo cp /home/memeruiz/local/src/repos/www.memelabs.net/pi-security-camera-utils/scripts/systemd/ir_light.service /etc/systemd/system/
sudo systemctl start ir_light.service
sudo systemctl enable ir_light.service
sudo cp /home/memeruiz/local/src/repos/www.memelabs.net/pi-security-camera-utils/scripts/systemd/alarm.service /etc/systemd/system/
sudo systemctl start alarm.service
sudo systemctl enable alarm.service

Sending and receiving SMSs

polkit.addRule(function(action, subject) {
    if (action.id == "org.freedesktop.ModemManager1.Messaging"
        && subject.isInGroup("memeruiz") )
    {
        return polkit.Result.YES;
    }
});

* Restart polkit:
sudo systemctl restart polkit.service
mmcli -L
mmcli -m 0 --messaging-list-sms
mmcli -s 0
mmcli -m 0 --messaging-create-sms="text='hellow world',number='+50683096020'"
mmcli -s 3 --send
mmcli -m 0 --messaging-delete-sms=0

Shrink raspberry pi SD images

https://github.com/qrti/shrink

Calculate power consumption

https://forums.raspberrypi.com/viewtopic.php?t=367244

https://github.com/jfikar/RPi5-power

https://github.com/librerpi/rpi-tools/blob/master/pi5_voltage.py

References

[1] https://www.raspberrypi.com/documentation/computers/configuration.html#kernel-command-line-cmdline-txt

[2] https://techfortalk.co.uk/2024/03/14/setting-up-data-connection-with-soracom-onyx-lte-usb-modem-on-linux/

[3] https://stackoverflow.com/questions/78120541/establishing-data-connection-using-soracom-onyx-lte-usb-modem-in-linux

[4] https://developers.soracom.io/en/start/connect/soracom-onyx-lte/

[5] https://unix.stackexchange.com/questions/399659/how-to-avoid-dhclient-default-gateway-on-an-interface