Reader small image

You're reading from  Building a Home Security System with Raspberry Pi

Product typeBook
Published inDec 2015
Publisher
ISBN-139781782175278
Edition1st Edition
Right arrow
Author (1)
Matthew Poole
Matthew Poole
author image
Matthew Poole

Matthew Poole is a systems engineer based near Southampton on the south coast of England, with over 20 years of industry experience. After graduating in electronics and communications engineering, he went on to train as and become an air traffic engineer for Civil Aviation Authority, UK, working on microprocessor-based control and communications systems. Later, he became a software architect and mobile technology specialist, working for several consultancies and global organizations in both hands-on architecture and product-management roles . He is now a partner at Connecting Objects, a boutique systems consultancy focusing on the design of Bluetooth and other wireless-based IoT systems, taking ideas from concept to prototype. He is also the Director of Technology for Mobile Onboard, a leading UK-based transport technology company specializing in bus connectivity and mobile ticketing systems. He is also the author of Building a Home Security System with Raspberry Pi, Packt Publishing. You can find his blog at http://cubiksoundz.com and LinkedIn profile at https://www.linkedin.com/in/cubik, or you can reach him on Twitter at @cubiksoundz.
Read more about Matthew Poole

Right arrow

Chapter 7. Building a Web-Based Control Panel

We've now got all of our hardware elements together for us to create a complete home-security system featuring contact switches for our doors and windows, and motion detectors and cameras to take happy snaps of wannabe intruders! I've deliberately guided you through this in a modular fashion so that you can pick and choose and expand on the hardware sensor elements that suit your requirements. In Chapter 9, Putting It All Together we will be wiring all of this together to form the complete system based on zones that we looked at earlier.

One thing that all home security systems require is a control panel that allows us to arm and disarm the system and monitor the status of the zones within our system. We might also want to do things such as only arm certain zones, or have the system automatically arm and disarm at certain times of the day.

The hardware required for this, such as switches, LEDs, and LCD displays, can be quite expensive and time...

Installing the web server


There are several web servers readily available that we could install on our Raspberry Pi, and they would all be suitable for our system. But I like the lighttpd web server as it's easy to use and lightweight. lighttpd is often referred to, and affectionately known as, "Lighty"—which to be honest is less of a mouthful than lighttpd.

As well as the Web server itself, we're also going to install PHP support, which will allow us to write dynamic web pages to interact with the Linux system. Now, to be honest, I'm not a massive fan of PHP for commercial Web-based deployments for many reasons, but for a small embedded-Linux system such as our home security system, it's perfect and works really well. It's also quite straightforward to get into if you've never done server-side Web-scripting as well.

To perform the following steps, you'll need to be logged into your Raspberry Pi via the terminal console (for example, PuTTY):

  1. Update the package installer:

    $ sudo apt-get update...

Being in control


So that we know what controls we want on our alarm control panel, we need to map out our system with the number of zone inputs and control inputs and outputs. As you'll remember from Chapter 3, Extending Your Pi to Connect More Things we can essentially have up to 16 zones in our system using the two I/O ports on our port expander. We also have the eight GPIO pins at our disposal on the Raspberry Pi board itself. So, let's now allocate these outputs and document them in the table that follows.

I'm going to set up an 8-zone system for my alarm inputs using port A on the I/O expander board, using the native GPIO pins for things such as buttons and alert outputs. One reason for doing it in this configuration is that the system can always fail-safe—so if the expander board fails, the Raspberry Pi can still communicate alerts and buzzers connected to it.

The master configuration file


Our system will use a master configuration file that will tell it how everything is set up and connected. This configuration file will be used by both the web control panel and the main alarm control scripts so that the two sub-systems can "talk" to each other. Let's create the file with our initial settings.

The settings file will be stored in the same location as where we will create our control scripts in Chapter 9, Putting It All Together, which is in the folder. /etc/pi-alarm. So, let's create this folder, and give it execute rights so that our scripts can be run:

$ cd /etc
$ sudo mkdir pi-alarm
$ sudo chmod 777 pi-alarm

We'll now create the master configuration file, to be used by our system, in this folder:

$ cd pi-alarm
$ sudo nano alarm.cfg

Tip

As before, you don't have to create your files in Nano on the Raspberry Pi—you can create them on your desktop computer, and then transfer them to your Pi using SCP.

# ALARM MASTER CONFIG FILE #

#Number of zones...

Creating the web page


Our Web-based control panel is going to be a single PHP-driven HTML5 web page which will be mobile optimized. HTML5 is the latest mark-up standard for web pages and is supported by most modern smartphones and browsers. We will also create a cascading style-sheet (CSS) that will make our page look half reasonable on mobile devices.

To create the web files, I recommend that you use something like the excellent Notepad++ on your desktop computer, rather than doing it directly on the Raspberry Pi. Alternatively, if you are a seasoned web developer, you may already have your IDE of choice.

The control panel HTML template

The first thing we'll do is create an HTML file that we can use to test our layout before we put the HTML into a PHP file to make it interact with our system. This makes it easier to tweak the way we want it to look beforehand, without the PHP scripts getting in the way.

Note

This is not a tutorial on Web development—there is a plethora of books out there on...

Remote access to our control panel


While we can set up our system to receive email alerts when our system detects an intrusion, it would be really useful to be able to access our Web-based control panel wherever we are so that we can perhaps arm and disarm the system or switch off certain zones when we're not there.

However, in order to make this possible we need to do a few things:

Setting up a dynamic DNS account

Most of us won't have a fixed IP address for the Internet connection in our home; it is likely to change from time to time, especially when we reboot or unplug our router, whereby our Internet service provider assigns us a new one when we next connect to them. Because of this, we can't rely on using the IP address to get to our home network when we're out and about. To solve this, we need to set up a dynamic DNS account that will allow us to set up a domain name for our home network (for example, myhomenetwork.com).

It works by having a service that runs inside your network, such...

Summary


We've now started building the software that will control our home security system by determining the format of the main configuration file. We've also installed a Web server and built a basic single-page control panel with PHP, HTML5, and CSS3, which can be accessed nicely on our mobile phone, allowing us to configure our system and view the status.

In addition, we've learned how to configure our home network and Raspberry Pi so that we can access our control panel when we're away from home.

In Chapter 9, Putting It All Together, we'll put all of the electronic elements together and write the main scripts that will run the home security system. But before that, in the next chapter, we're going to look at a few other bits and pieces, such as adding other sensors, not necessarily related to intruder detection, to our home security system. We'll also look at how we can administer our entire Raspberry Pi system remotely using a Web browser, in addition to accessing our home security control...

lock icon
The rest of the chapter is locked
You have been reading a chapter from
Building a Home Security System with Raspberry Pi
Published in: Dec 2015Publisher: ISBN-13: 9781782175278
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
undefined
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime

Author (1)

author image
Matthew Poole

Matthew Poole is a systems engineer based near Southampton on the south coast of England, with over 20 years of industry experience. After graduating in electronics and communications engineering, he went on to train as and become an air traffic engineer for Civil Aviation Authority, UK, working on microprocessor-based control and communications systems. Later, he became a software architect and mobile technology specialist, working for several consultancies and global organizations in both hands-on architecture and product-management roles . He is now a partner at Connecting Objects, a boutique systems consultancy focusing on the design of Bluetooth and other wireless-based IoT systems, taking ideas from concept to prototype. He is also the Director of Technology for Mobile Onboard, a leading UK-based transport technology company specializing in bus connectivity and mobile ticketing systems. He is also the author of Building a Home Security System with Raspberry Pi, Packt Publishing. You can find his blog at http://cubiksoundz.com and LinkedIn profile at https://www.linkedin.com/in/cubik, or you can reach him on Twitter at @cubiksoundz.
Read more about Matthew Poole

Port

I/O Pin

Label/Purpose

Expander A

0 (A0)

Zone 1 Input (Entry/Exit Channel)

 

1 (A1)

Zone 2 Input

 

2 (A2)

Zone 3...