Tuesday 16 October 2018

Making a cheap and flexible trailcam with Raspberry Pi



I know there are quite a few versions of this around, but after seeing the short item on Springwatch about a DIY Raspberry Pi based I thought it would be good project for any at the local U3A who still fancied a play with technology, but wanted some help / backup.

So I started at the recommended web site, ordered a kit, nicked a powerbank from another project and set off.

The I made case is distinctly Blue Peter, but functional and I used a glue gun for the first time in my life (only somewhat messilly!) I used a recycled carry out box, some cardboard and the top of an old bottle as a lens shield.

After a couple of hiccups due to not setting up the config files properly on the memory card (so the wifi didn't hook up), I just used the supplied config and it was up and running.

The powerbank (Anker Powercore 10000) works a treat and will run the setup for much more than 24 hours.

BUT

The software is pretty limited and limited to pi zero W and pi B 3 and the only network option is to setup as a wifi hotspot - so to use the camera you need to change the wifi  setup on whatever device you use (phone, tablet, laptop etc) to the camera (and of course loose all acess to the rest of the world in the meantime). Clearly the bunch of folks who wrote this software have such large gardens their home wifi doesn't reach the edges.

For me, I'd rather be able to use any sensible network option - including a private hotspot if appropriate, but also using any existing wifi, or even wired LAN (allowing the use of power over ethernet so there is not battery problem).

A bit of digging suggested that this motion software would work well even on a Pi Zero. It works well, and does seem to do everything necessary pretty well. It also enables multiple cameras (even on multiple Raspberry Pis) to be managed through a single interface. This package however, loads a Pi Zero quite heavily and this means that video frame size has to be scaled back to avoid overloading the a Pi Zero.

I'm also looking at RPi-Cam-Web-Interface, which is written to exploit the Raspberry Pi Camera with its built in GPU support. Although not quite as sophisticated as motion, this may be a better option overall for a Pi Zero in particular. I'll post more about this later.

The gory details of the entire Raspberry Pi build process for motioneye on raspbian lite are below (elapsed time on pi Zero in brackets):

This starts with my standard pi build:

(Download) stretch lite  (2018-06-27)

use etcher to load it onto cf card (

add wpa_supplicant.conf file to boot partition:
country=GB
update_config=1
ctrl_interface=/var/run/wpa_supplicant

network={
 scan_ssid=1
 ssid="MyNetworkSSID"
 psk="mypassword"
} 

add ( empty) ssh file to boot partition

(4 mins)

place in pi and power on. Get IP address from dhcp server

log in and use raspi-config to change password and hostname, enable camera, set timezone

(9 mins)
sudo apt-get update
sudo apt-get upgrade
(18 mins, but time will vary depending on how many updates....)

The rest of the build uses the motioneye Raspberry pi build with one fix and a tweak. Here's a consolidated list:
sudo apt-get install ffmpeg v4l-utils libmariadbclient18 libpq5 python-pip python-dev libssl-dev libcurl4-openssl-dev libjpeg-dev libz-dev
 (24 mins)

This fix may be needed

Check the folder /dev and if video0 not present, edit /etc/modules and add line at the end:
bcm2835-v4l2
then:
wget https://github.com/Motion-Project/motion/releases/download/release-4.1.1/pi_stretch_motion_4.1.1-1_armhf.deb

sudo dpkg -i pi_stretch_motion_4.1.1-1_armhf.deb

sudo pip install motioneye
(37 mins)
and finally:
sudo mkdir -p /etc/motioneye
sudo cp /usr/local/share/motioneye/extra/motioneye.conf.sample /etc/motioneye/motioneye.conf
sudo mkdir -p /var/lib/motioneye
sudo cp /usr/local/share/motioneye/extra/motioneye.systemd-unit-local /etc/systemd/system/motioneye.service
sudo systemctl daemon-reload
sudo systemctl enable motioneye
sudo systemctl start motioneye

Enable reboot / shutdown from web page (for admin only)

Edit /etc/motioneye/motioneye.conf:

find the line with enable_reboot and change it to:
enable_reboot true

Goto the motion website

In a web browser enter the ip address of your raspberry pi followed by :8765
(something like http://192.168.1.2:8765)

Login as admin with no password.

click on the message about "no cameras" to add the camera.

If it then says there are no cameras check the bit above about "This fix may be needed".

That is it basically working in around 45 minutes.

No comments:

Post a Comment