Search icon
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Raspberry Pi for Secret Agents - Third Edition

You're reading from  Raspberry Pi for Secret Agents - Third Edition

Product type Book
Published in Jul 2016
Publisher
ISBN-13 9781786463548
Pages 316 pages
Edition 3rd Edition
Languages

Table of Contents (7) Chapters

Preface 1. Getting up to No Good 2. Audio Antics 3. Webcam and Video Wizardry 4. Wi-Fi Pranks – Exploring Your Network 5. Taking Your Pi Off-Road 6. Detecting and Protecting Against Your Enemies

Chapter 6. Detecting and Protecting Against Your Enemies

In our final masterclass, we're going to look at ways to detect infiltrations and protect ourselves against other would-be spies. To help us do this, we will be plugging sensors and other gadgets into our Raspberry Pi so we can be alerted when people stray into our territories.

The Raspberry Pi has lots of ways of connecting things to it, such as plugging things into the USB ports, connecting devices to the onboard camera and display ports, and to the various interfaces that make up the GPIO (General Purpos Input/Output) connector. As part of our detection and protection regime, we'll be focusing mainly on connecting things to the GPIO connector.

During this chapter we will:

  • Explore the GPIO and how to connect things safely to it
  • Build a laser trip wire to protect corridors and entrances
  • Protect areas of space using a passive infrared detector
  • Send messages to our phone using SMS rather than e-mail
  • Gain access...

Say hello to the GPIO


The GPIO connector is the large group of pins on the edge of your Raspberry Pi board. On earlier models, there were 26 pins that made up this connector. Since the Model B+ there are now 40 pins, although the first 26 pins are identical to the previous models, and it's these 26 pins we'll be working with. You won't need to worry about the rest of the pins.

Essentially, the GPIO connector provides access to:

  • Power supplies

  • Digital I/O pins

  • I2C bus

  • SPI bus

  • UART Serial bus

Some of the pins on the GPIO have more than one purpose, depending on how they are programmed. The following diagram is a reference guide to all of the pins on the GPIO. The GPIO numbers on the yellow labels relate directly to those on the Broadcom chip, and are numbers generally used within the scripts:

GPIO connector pin-out

Power connections

The GPIO connector also provides access to the onboard power supplies. The +5V connection (pins 2 and 4) is essentially the +5V input from the external power supply connected...

Building a laser trip wire


You may have seen Wallace and Gromit's short film, The Wrong Trousers, where the penguin uses a contraption to control Wallace in his sleep, making him break into a museum to steal the big shiny diamond. The diamond is surrounded by laser beams, but when one of the beams is broken, the alarms go off and the diamond is protected with a cage!

In this project, I'm going to show you how to set up a laser beam and have our Raspberry Pi alert us when the beam is broken— aka a laser trip wire. For this, we're going to need to use a Waveshare Laser Sensor module (www.waveshare.com), which is readily available to buy on Amazon for around £10 / $15.

The module comes complete with jumper wires, that allow us to easily connect it to the GPIO connector in the Pi:

The Waveshare laser sensor module contains both the transmitter and receiver

How it works

The module contains both a laser transmitter and receiver. The laser beam is transmitted from the gold tube on the module at a...

Sending alerts to your phone using SMS

We saw in Chapter 5, Taking Your Pi Off-road, how to send e-mails from the Raspberry Pi so that we can pick them up on our smartphone. But what if we're in an area where we can't get a good mobile Internet signal? All of our elaborate work to protect our things or get status updates from the field goes to waste because we don't get alerted in time.

SMS (Simple Messaging Service)—or text messaging—actually uses the mobile voice channel to deliver the message to your handset rather than the mobile Internet channel, so you're likely to receive your message in areas of poor reception and where there is no data service.

SMS gateway

Fortunately, sending a text message from our Pi can be as easy as making a URL request to a server if we choose an SMS gateway provider with a good API, such as BulkSMS. You can sign up for a UK account at http://www.bulksms.com/countries/u/united-kingdom, and just about any other country athttp...

Sending alerts to your phone using SMS


We saw in Chapter 5, Taking Your Pi Off-road, how to send e-mails from the Raspberry Pi so that we can pick them up on our smartphone. But what if we're in an area where we can't get a good mobile Internet signal? All of our elaborate work to protect our things or get status updates from the field goes to waste because we don't get alerted in time.

SMS (Simple Messaging Service)—or text messaging—actually uses the mobile voice channel to deliver the message to your handset rather than the mobile Internet channel, so you're likely to receive your message in areas of poor reception and where there is no data service.

SMS gateway

Fortunately, sending a text message from our Pi can be as easy as making a URL request to a server if we choose an SMS gateway provider with a good API, such as BulkSMS. You can sign up for a UK account at http://www.bulksms.com/countries/u/united-kingdom, and just about any other country athttp://www.bulksms.com. They have good...

Use your phone as an access control device


We saw in Chapter 4, Wi-Fi Pranks-Exploring Your Network, how we could use our Raspberry Pi to scan the wireless networks to see what devices are around. Most smartphones come with either Wi-Fi or Bluetooth, or both, on them nowadays, which transmits an identifier unique to that device.

We can take advantage of that by using our phone as an access control device, so our Pi can know when we're nearby and act accordingly. For example, let's say if each time you were near your Pi with your smartphone, it could automatically unlock the encrypted container you set up in Chapter 5, Taking Our Pi Off-Road, and then lock it again when we're not nearby. By constantly scanning for our phone's broadcast packets, we can do this.

Probe Requests

When a smartphone is searching for nearby routers to connect to, it will periodically broadcast packets of data called Probe Requests. The Probe Requests contain the unique MAC address of the device and often the name of...

Displaying secret codes and messages


Let's say that you need to leave your fellow agents a message in a particular location, but you don't want anyone else to know what it contains. You could write the encoded message on a piece of paper so it could be decoded by hand, but it would be much more convenient to show the encoded message electronically on a display, so it can easily be changed—even from a remote location.

For this project, we're going to use Ciseco's Pi-Lite board, which sits on top of the Raspberry Pi, plugged into the GPIO connector. It features a matrix of 126 LEDs combined with a small microcontroller enabling the device to be easily programmed using the Pi's serial port:

Ciseco Pi-Lite board contains 126 LEDs

Enabling the serial port

Before we can access the serial port we need to enable it for our own use on the Pi, as by default, it's used for the terminal console. Fortunately, this is now straightforward on the latest Raspbian releases:

  1. Launch the Raspberry Pi configuration...

Better security with a true random number generator


We looked at encryption in the section Keeping your conversations secret with encryption in Chapter 4, Wi-Fi Pranks - Exploring Your Network; however, the key to secure cryptography is entropy—a high-quality source of randomness.

Most random numbers used in computer programs are pseudo-random, which means they are generated in a predictable manner using mathematics. In many circumstances this is fine, but for strong cryptography, this is may not be suitable, even with a good random seed, so we need a True Random Number Generator (TRNG).

Usually, this requires expensive hardware, or weird physical events such as noise analysis to generate random number using a high level of entropy. But did you know that your Raspberry Pi—including the Pi Zero—also contains a hardware-based TRNG?

Kernel entropy pool

In the Linux environment, the root of all randomness is something called the kernel entropy pool. This is a 4,096-bit secret number stored in...

Summary


We kicked off our final chapter with a guide to the Raspberry Pi's GPIO connector and how to safely connect peripherals to it. We followed that up by connecting a laser sensor module to our Pi to create a rather cool laser trip wire that could alert you when the laser beam is broken.

Following along the same theme, we also connected a passive infrared motion detector to our Raspberry Pi, which observed an area of space and detected when our space had been infiltrated.

Because we may not always have an Internet connection to our smartphone when out in the field, we extended our methods of being remotely alerted to include SMS, using a few simple lines of script which connected to the API of an SMS gateway service.

Moving away from protecting our space to protecting our digital assets, we looked at a way for our Pi to know when we're in the vicinity, with a script that scanned for the Wi-Fi address of our personal phone, which if found, could then do something, such as unlocking our encrypted...

lock icon The rest of the chapter is locked
arrow left Previous Chapter
You have been reading a chapter from
Raspberry Pi for Secret Agents - Third Edition
Published in: Jul 2016 Publisher: ISBN-13: 9781786463548
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}