This is just my notes on getting this setup of which I was inspired by this article. The Model A has 256MB of memory. Apparently the GPU needs a minimum of 128MB to work so it is important to get the CPU as much memory as possible by having non-required things stopped or uninstalled altogether. There is nothing here specific to the Model A, so this will all work with a Model B.
I looked at mainly two minimal images (this and this). I ended up using MINIBIAN as I struggled to get the camera working on the former although I believe the information futher down on making the enable_camera.sh script would have solved it. Alright, lets get to it.
- I used the dcfldd command to prepare the SD card, but you can use plain dd also:
dcfldd bs=1M if=/tmp/2013-10-13-wheezy-minibian.img of=/dev/mmcblk0
- I then used gParted to grow the ext4 partition to 2 GB (as updating the firmware takes up a lot of space).
- For the remainder of the 8GB SD card, I made a xfs partition called storage (UPDATE: I will need to use ext4 as adding another type of filesystem adds tools and processes to manage them which takes a lot of memory relative to the little available)
- You will need to have a network connection, I used a USB-Ethernet dongle on a Model A as it does not have an ethernet port and WiFi is not enabled on MINIBAN (wpasupplicant not installed – will be done later)
- Next step was to put the SD card in the Pi and boot up
- ssh to the Pi and log in with user root (default password: raspberry)
- Issue the following commands:
dpkg-reconfigure tzdata (select your closest timezone)
dpkg-reconfigure locales (select your locale)
- Now, we need to enable the camera. I used this information and created a script as raspi-config doesn’t seem to work on these minimal images.
nano enable_camera.sh (paste the contents from the link)
chmod 755 enable_camera.sh
apt-get install lua5.2 (needed as it is used in the script)
- We can now test the camera by taking an image:
raspistill -o image.jpg
The camera should light up it’s RED light and take a photo. If we are successful here, we will now try to get motion to work. Go ahead and reboot in the meantime.
First we start by installing the dependencies required by motion (referenced here):
apt-get install -y libjpeg62 libjpeg62-dev libavformat53 libavformat-dev libavcodec53 libavcodec-dev libavutil51 libavutil-dev libc6-dev zlib1g-dev libmysqlclient18 libmysqlclient-dev libpq5 libpq-dev
Since motion does not yet support the Pi, we need to keep following the above referenced location and get the special build of motion from the Dropbox link, un-compress it and put it in the executable path:
tar zxvf motion-mmal.tar.gz
mv motion /usr/bin/.
You can probably use the settings in the file from Dropbox above, however I used the config file and init script from this location.
cp motion.conf /etc/.
cp motion /etc/init.d/.
chmod 755 /etc/init.d/motion
The above conf file has a video location (if you search for CAM1 you will find it) you will need to modify to determine where to store the images and videos the camera captures.
The above motion init file has a sleep 30 for start option for the CAM1 location to be mounted. You can comment this out if you are storing images on the card or somewhere else that does not require this delay.
The init script will do a chuid to run this as user motion, therefore we need to create that user. I created it as a system user with no shell and added it to the video group so it is able to access the camera module.
useradd motion -rs /bin/false
usermod -a -G video motion
You should now be able to start and stop motion:
To set it up so that it autostarts at boot up, execute this command:
update-rc.d motion defaults
Next up, I will attempt to reduce unnecessary usage of RAM on this Model A to give motion as much as possible following this guide. Currently I get about 20MB free when motion is running, which by subtraction means motion uses 40MB to run. Remember also that the GPU takes half (128MB) of the total RAM when you need to use the camera. I will do the following changes from the referenced guide above to get back about 13.5MB RAM:
- Replacing OpenSSH with Dropbear | Save: +10MB RAM
- Remove the extra tty / getty’s | Save: +3.5 MB RAM
- Disable IPv6
- Replace Deadline Scheduler with NOOP Scheduler
BTW, you can check the current version of the firmware etc using the following two commands. Not sure how you would compare if you have the latest or not. If you need to update it, you can use the instructions from the previous referenced guide.
This gives me the following:
Sep 1 2013 23:27:46
Copyright (c) 2012 Broadcom
version 4f9d19896166f46a3255801bc1834561bf092732 (clean) (release)
Linux raspberrypi 3.6.11+ #538 PREEMPT Fri Aug 30 20:42:08 BST 2013 armv6l GNU/Linux
Here are the commands for the changes I made in the order I did them (explanations can be found from the referenced link):
apt-get install dropbear openssh-client
sed -i 's/NO_START=1/NO_START=0/g' /etc/default/dropbear
apt-get purge openssh-server
sed -i '/[2-6]:23:respawn:\/sbin\/getty 38400 tty[2-6]/s%^%#%g' /etc/inittab
sed -i '/T0:23:respawn:\/sbin\/getty -L ttyAMA0 115200 vt100/s%^%#%g' /etc/inittab
echo "net.ipv6.conf.all.disable_ipv6=1" > /etc/sysctl.d/disableipv6.conf
echo 'blacklist ipv6' >> /etc/modprobe.d/blacklist
sed -i '/::/s%^%#%g' /etc/hosts
sed -i 's/deadline/noop/g' /boot/cmdline.txt
The next step I will do is set this up to work with WiFi (with a hidden SSID). If you have a Pi with Ethernet port or will use a USB-Ethernet dongle, then you may not require this. The Linksys USB10T works out of the box. I will however be using a Edimax nano WiFi adapter. My setup is from this reference.
I will also set this up to store images on my Synology NAS and try to get the Surveillance Station app on the NAS to work as described here. (DONE – works like a charm)
Finally, it goes without saying that without the hard work of all the folks referenced here (and many more), this would have been a whole lot tougher if not impossible for me to get going.