Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletter Hub
Free Learning
Arrow right icon
timer SALE ENDS IN
0 Days
:
00 Hours
:
00 Minutes
:
00 Seconds
Arrow up icon
GO TO TOP
Building a Home Security System with Raspberry Pi

You're reading from   Building a Home Security System with Raspberry Pi Build your own sophisticated modular home security system using the popular Raspberry Pi board

Arrow left icon
Product type Paperback
Published in Dec 2015
Publisher
ISBN-13 9781782175278
Length 190 pages
Edition 1st Edition
Arrow right icon
Author (1):
Arrow left icon
 Poole Poole
Author Profile Icon Poole
Poole
Arrow right icon
View More author details
Toc

Table of Contents (16) Chapters Close

Building a Home Security System with Raspberry Pi
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
1. Setting Up Your Raspberry Pi FREE CHAPTER 2. Connecting Things to Your Pi with GPIO 3. Extending Your Pi to Connect More Things 4. Adding a Magnetic Contact Sensor 5. Adding a Passive Infrared Motion Sensor 6. Adding Cameras to Our Security System 7. Building a Web-Based Control Panel 8. A Miscellany of Things 9. Putting It All Together Index

Logging detection data


With any system, it's useful to be able to log data when something happens. We can do this with our detectors too by writing to a log file every time a detector in a zone is triggered. This way, you can keep a log of every time someone enters a room, which you can review at a later date even if the system isn't armed. You can also keep a log of when the system is armed and disarmed.

Here's a simple script that shows you how to do this whenever an event happens on our zones connected to the GPIO inputs:

#!/bin/bash

#set up the I2C expansion port
sudo i2cset –y 1 0x20 0x00 0xFF

#reset status
CURR_STATE="0x00"
LAST_STATE="0x00"

#path to the log file
LOG_FILE="/etc/pi-alarm/zones.log"

# loop forever
while true
do
  # read the gpio inputs
  CURR_STATE=$(sudo i2cget –y 1 0x20 0x12)
   
   #check if state has changed
   if [ "$CURR_STATE" != "$LAST_STATE" ]
  then
    #write change to log file
      TIMESTAMP=`date "+%Y-%m-%d %H:%M:%S"`
     echo "$TIMESTAMP Zone Status...
lock icon The rest of the chapter is locked
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.
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
Visually different images