Setting up Raspberry Pi Security CAM on Model A or B with minimal armhf image

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)
apt-get update
dpkg-reconfigure locales (select your locale)
apt-get upgrade
apt-get autoremove
apt-get autoclean
  • 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)
./enable_camera.sh
  • 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:

wget https://www.dropbox.com/s/xdfcxm5hu71s97d/motion-mmal.tar.gz
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:

/etc/init.d/motion start
/etc/init.d/motion stop

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.

    • /opt/vc/bin/vcgencmd version
    • uname -a

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
/etc/init.d/ssh stop
sed -i 's/NO_START=1/NO_START=0/g' /etc/default/dropbear
/etc/init.d/dropbear start
exit
ssh root@xxx.xxx.x.xxx
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
reboot

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.

Advertisements

14 thoughts on “Setting up Raspberry Pi Security CAM on Model A or B with minimal armhf image

  1. Was this actually done using a model A? Since model A is without a LAN port, your instruction will stall at the first apt-get command! And there is nothing on the setting up of a wifi connection.

    • The focus of the article was not to setup a network connection. As mentioned in the end, you can use a USB-ethernet network dongle or as I later pointed out, can get the WiFi setup but you would still need to be able to install the wpasupplicant package as it is not in MINIBAN at the moment by default.

      • Thanks for your super-fast response.
        I am still struggling to set up my model A with a wifi dongle. I think the necessary drivers are not included in the stripped down os.

      • Obviously the wifi drivers are stripped from this minimal os. I managed to find the driver and install successfully, using a model B. Using model A alone is too much of a hassle.
        Thanks for your kind assistance.

      • Yes, agreed the Model A with this minimal build has an extra step or two, but I looked at it that this will be a security camera and not used for anything else so the model A would be a fine choice to just setup and leave out there. The command to install the wifi is:

        apt-get install wpasupplicant

        But, again, this is assuming you have a usb-ethernet method to get on the network (or mount the sd card and install the package files manually on a desktop/laptop) and also a supported wifi adapter like the one I mentioned. Other wifi adapters with different chipsets may not be compatible without additional drivers.

  2. I use TP-Link TL-WN725N v2 which requires an additional driver, but there are kind souls out there who have these drivers for sharing.
    Cheers!

  3. So just to be clear – you don’t actually install motion from the repository as mentioned in the CodeProject article?

    • At the time, motion from the repository didn’t support this camera module. Codeproject install from repository to get the dependencies and then over-wrote it with the same code I used. Now, I think the repository motion has the support built in so no need to use the alternative one.

  4. Pingback: Setting up Raspberry Pi Security CAM on Model A or B with minimal armhf image | Just Another World Wide Independent Geek | DiFuscoFrancesco.it

  5. Pingback: Raspberry Pi as low-cost HD surveillance camera | Raspberry PI Blog

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s