Setting up a headless Raspberry Pi Zero (W) with Camera

I received my Raspberry Pi Zero W a couple of weeks ago and finally had the chance to set it up. My goal is to to setup some cameras in my basement and garage.

Prerequisites

Here are links to the products and prices I purchased on Amazon and CanaKit at the time. The prices might vary slightly if you purchase them.

Bringing the total cost of this setup to: $69.35 (including shipping). If you’re looking for something with more features, you can purchase indoor wireless IP camera’s online. Some of them even have 2-way audio which I use to keep tabs on my dogs and general security. For my purposes, and where they’ll be placed, I don’t need that type of functionality. Also, you get the reward of building something yourself with greater control.

Setup

I decided to use the Raspbian Jessie Lite distribution for my setup since it’s a smaller SD card and there won’t be any GUI. You can download it here from the Raspberry Pi website by selecting “Download ZIP”. Alright, here we go:

  1. Connect the SD card to your computer. Note that it must be formatted as FAT32. The one I purchased above was already formatted in FAT32.
  2. Open “Disk Utility”. To do this, click on the magnifying glass in the top-right corner of your computer screen. Type “disk utility” in the search box that opens, then click on the “Disk Utility” Application that comes up and click on “APPLE SD Card Reader Media”.
  3. Note the “Device:”; it will look something like disk(n) where (n) is a number (for example, disk1). Make sure you take a note of this number. Mine was disk1.
  4. Now, right click on “NO NAME” or “Untitled” on the left and select “Unmount” from the menu. This will unmount the partition so that you can write to the disk.
  5. Now open terminal and run the following command:

    Remember to replace (n) with the number that you noted before and (PATH_OF_THE_IMAGE_YOU_DOWNLOADED.img) to the path of the Raspbian Jessie Lite image you downloaded. for example: my command was:

    The image file will be copied to the SD Card. You won’t get any feedback while it copies, and it can take several minutes. Leave terminal open and let it do its thing.

Headless setup on the Raspberry Pi Zero (W)

Once it’s completed,

  1. Open the boot volume on your Mac (should auto mount after the disk image is finished writing).
  2. Create an ssh file to tell the Pi to enable SSH when it boots up by default:
  3. Next, create a wpa_supplicant.conf file in the boot volume to tell the Pi to connect to your WiFi network on boot:
  4. Insert the contents below into this new file:
  5. Eject the SD Card and insert it into your Raspberry Pi.

Connecting the Camera to the Pi

Connecting the camera to the pi is fairly easy. Use the supplied mini cable provided with the camera case.

Insert the Pi into the case

Finished Product

Booting Raspbian Jessie Lite

Ok, now it’s time to insert the power cord and boot up the Pi. For this step, you’re going to find the IP Address of your Pi to SSH into it. Most routers have a network map that displays connected devices. I was easily able to find mine. If you can’t find yours, try using a tool like nmap.

  1. SSH into your Pi:
  2. Once, you’ve logged in, update the OS:
  3. Now we’re going to configure the OS using the raspi-config tool.

    Below are the options I configured for my Pi:
    1. Set a new password.
    2. Set a hostname (e.g. kitchen-camera).
    4. I configured “Localisation Options” for my locale
    5. For ‘Interfacing Options’, select ‘P1 Camera’, then choose ‘Yes’ to enable the camera interface.
  4. Test it out by running:

Installing software for the camera

There are a couple of software options for using your Pi as a security camera. I opted for Motion. Adafruit has an excellent tutorial for setting it up with Dropbox. Follow that tutorial and become familiar with the Motion config options.

Clear the terminal’s command history

Sometimes you just need to clear your history in Terminal. It’s actually pretty easy to do.

If you’d rather not have your history saved to a file at all, add the following line to your ~/.bash_profile:

This way, your command history is limited to only those commands you used during the current session. More information and options can be found on the bash man page

Ubuntu Package Management

Chances are good that you’re already familiar with apt-get, a command which uses the “advanced package tool” to interact with the operating system’s underlying package system. The most relevant and useful commands are, (to be run as root):

This command installs the package(s) specified, along with any dependencies.

This command removes the package(s) specified, but does not remove dependencies.

This command removes any “orphaned” dependencies which remain installed but are not used by any applications.

Removes downloaded package files (.deb) for software that are already installed.

Combines the functions of remove and clean for a specific package. Also removes configuration files for the given package.

Reads the /etc/apt/sources.list file and updates the system’s database of packages available for installation. Run this after changing sources.list.

Upgrades all packages if there are updates available. Run this after running apt-get update.
While apt-get likely provides the most often used functionality of the package management, apt provides additional information that you may find useful in the apt-cache command.

If you know the name of a piece of software but apt-get install fails or points to the wrong software, use search to look for other possible names, if you need to find out the name of a package that you know is in the system.

The search interface only provides package names. If you need to learn more about a package, including dependency information, version numbers and a basic description, run this.

Lists the packages that the specified packages depends upon in a tree. These are the packages that will be installed with the apt-get install command.

Generates and outputs a list of packages that that depend upon the specified package. This list can often be rather long.

Generates a list of the currently installed packages on your system. This list is often rather long, so it is best to pipe its output through a command like less.

Getting MySQL and PHP running on Terminal with XAMPP

I have XAMPP setup on my Mac. Getting MySQL and PHP to run in terminal didn’t work after installation. To be able to run mysql and php you have to add the xampp application to the .bash_profile file in your users home directory.

To check that it has worked, open a new terminal session and type in:

Both should point to /Applications/xampp/xamppfiles

Recursively remove .svn folders on Windows

I’m not an SVN guy; I love my GIT but, sometimes you inherit projects where SVN was the choice used for version control. There are many ways to do this of course but my preferred method is creating a Batch (.bat) file in the root of the target folder, add this line and run it.

Drupal – How to install Drush

What is Drush?

It’s a command line shell and scripting interface for Drupal. The Drush Package Manager allows you to download, enable, disable, uninstall, update modules/themes/profiles/translations from the command line in a very simple way (apt-get style) – just type,

and

in a Drupal directory to install the Views project! Additionally, the Drush Package Manager also allows you to update all your modules and even Drupal core with just one command,

How to install Drush

  1. Download the current version of the Drush Package from the Drupal website.
  2. Upload the folder to the root directory of your server. I did this on a shared environment.
  3. Login to your server via shell.
  4. Make the ‘drush’ command executable:
  5. create an alias to drush:
  6. Now, you must log out and then log back in again or re-load your bash configuration file to apply your changes to your current session:
  7. Start using drush by running “drush” from your Drupal root directory.

Magento – Add Static Block to CMS Page

Static blocks are a great way to add sections of HTML to your CMS or Catalog pages. I’m going to show you how to add a static block to a CMS page.

It’s a 2 step process and a very simple one. First, create your static block by going to CMS->Static Blocks. You will use the identifier of your static block to reference it on the CMS page. Edit the CMS page you would like this block to appear in, and add this code in the location where you would like it to show up:

MySQL – Using a Column Name Inside the LIKE Keyword

When using the LIKE keyword in a MySQL query, I use it the most typical way, LIKE ‘%STRING%’. One day, I was in need to use a column name instead and could not figure out how to do it! At first, I tried to just replace the string value with the column name like this, LIKE (%t.column%). The end-result was not good as the LIKE keyword expects a string.

So, I thought of trying the CONCAT() function since that returns a string. And it worked!

Hope this helps someone!

MySQL – How to Export and Import tables with the Command Line

2 commands I use often throughout the day is importing and exporting large databases into MySQL VIA the command line. Here is how I do it where “USERNAME” is your username, “PASSWORD” is your password and “DATABASE” is your database name.

To Export:

To Import:

Also, you may have a large database that may give you errors while importing. You can use this command to force the import without warnings or errors: