Amazon Dash Controlled Motion Sensing Camera (Part 2)

My Raspberry Pi camera finally arrived, so I can finally start setting up the camera. First, we need to enable it.

$> sudo nano /boot/config.txt
start_x=1  
gpu_mem=128  
$> sudo reboot now

We also need to load the drivers.

$> sudo modprobe bcm2835-v4l2
$> echo bcm2835-v4l2 >> /etc/modules

Then we install motion. The version available on apt is horribly outdated, so let's install the latest stable release from GitHub (4.0 as of writing).

$> cd /opt
$> git clone https://github.com/Motion-Project/motion.git
$> cd motion
$> git checkout -b 4.0 origin/4.0
$> apt install autoconf automake pkgconf libtool libjpeg8-dev build-essential libzip-dev
$> apt install ffmpeg libavutil-dev libavformat-dev libavcodec-dev libswscale-dev
$> autoreconf -fiv
$> ./configure --without-mmal
$> make
$> make install

The motion binary gets installed in /usr/local/bin/motion and the configuration file is in /usr/local/etc/motion and needs to be renamed to motion.conf. Change the following lines as suited.

$> nano /usr/local/etc/motion/motion.conf
daemon off  
width 1024  
height 768  
framerate 25  
target_dir /tmp/motion  
ipv6_enabled on  
stream_motion on  
stream_maxrate 25  
stream_localhost off  
stream_auth_method 2  
stream_authentication idontlikethis:method  
webcontrol_localhost off  
webcontrol_authentication idontlikethis:method  

The eventual next step would be to change the target_dir to something else, for instance the mount point of a remote file server. Now create a service to start/stop motion:

$> nano /etc/systemd/system/motion.service
[Unit]
Description=Motion daemon  
After=local-fs.target network.target

[Service]
PIDFile=/var/run/motion.pid  
ExecStart=/usr/local/bin/motion  
Type=simple  
StandardError=null

[Install]
WantedBy=multi-user.target  

In part 1 I created a service that monitors an Amazon Dash button to start/stop motion, so we can now enable it.