20,39 €
This book is designed to introduce you to IoT and Raspberry Pi 3. It will help you create interesting projects, such as setting up a weather station and measuring temperature and humidity using sensors; it will also show you how to send sensor data to cloud for visualization in real-time. Then we shift our focus to leveraging IoT for accomplishing complex tasks, such as facial recognition using the Raspberry Pi camera module, AWS Rekognition, and the AWS S3 service. Furthermore, you will master security aspects by building a security surveillance system to protect your premises from intruders using Raspberry Pi, a camera, motion sensors, and AWS Cloud. We'll also create a real-world project by building a Wi-Fi – controlled robot car with Raspberry Pi using a motor driver circuit, DC motor, and a web application.
This book is a must-have as it provides a practical overview of IoT’s existing architectures, communication protocols, and security threats at the software and hardware levels—security being the most important aspect of IoT.
Das E-Book können Sie in Legimi-Apps oder einer beliebigen App lesen, die das folgende Format unterstützen:
Seitenzahl: 189
Veröffentlichungsjahr: 2018
Copyright © 2018 Packt Publishing
All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews.
Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the author, nor Packt Publishing or its dealers and distributors, will be held liable for any damages caused or alleged to have been caused directly or indirectly by this book.
Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information.
Commissioning Editor: Gebin GeorgeAcquisition Editor: Prachi BishtContent Development Editor: Dattatraya MoreTechnical Editor: Varsha ShivhareCopy Editors: Safis Editing, Laxmi SubramanianProject Coordinator: Shweta H BirwatkarProofreader: Safis EditingIndexer: Tejal Daruwale SoniGraphics: Jisha ChirayilProduction Coordinator: Aparna Bhagat
First published: April 2018
Production reference: 1260418
Published by Packt Publishing Ltd. Livery Place 35 Livery Street Birmingham B3 2PB, UK.
ISBN 978-1-78862-740-5
www.packtpub.com
Mapt is an online digital library that gives you full access to over 5,000 books and videos, as well as industry leading tools to help you plan your personal development and advance your career. For more information, please visit our website.
Spend less time learning and more time coding with practical eBooks and Videos from over 4,000 industry professionals
Improve your learning with Skill Plans built especially for you
Get a free eBook or video every month
Mapt is fully searchable
Copy and paste, print, and bookmark content
Did you know that Packt offers eBook versions of every book published, with PDF and ePub files available? You can upgrade to the eBook version at www.PacktPub.com and as a print book customer, you are entitled to a discount on the eBook copy. Get in touch with us at [email protected] for more details.
At www.PacktPub.com, you can also read a collection of free technical articles, sign up for a range of free newsletters, and receive exclusive discounts and offers on Packt books and eBooks.
Maneesh Rao holds over 7 years of experience in software development, primarily in IoT. He has been a part of Thingworx IoT team. Thingworx is one of the most sought after IoT platforms. Furthermore, he has worked for one of the biggest consumer electronics company in India and developed IoT products for smart homes, smart factories, connected vehicles, and smart consumer appliances. He also assists start-ups in developing IoT products.
Thushara Jayawardena, who is driven by curiosity, persistence, and engagement, has explored and acquired many skills and experiences in the computer software and micro electronics domains. He has embedded related ranges from Raspberry Pi to Arduino projects. His software-related projects span across Android, JavaScript frame works(NodeJS and Leaflet), and pass technologies(Heroku and Mongo). His day job is at a leading multinational Swedish ERP vendor in Gothenburg. He’s been at IFS world operations for over 16 years, working with various aspects of software development.
If you're interested in becoming an author for Packt, please visit authors.packtpub.com and apply today. We have worked with thousands of developers and tech professionals, just like you, to help them share their insight with the global tech community. You can make a general application, apply for a specific hot topic that we are recruiting an author for, or submit your own idea.
Title Page
Copyright and Credits
Internet of Things with Raspberry Pi 3
Packt Upsell
Why subscribe?
PacktPub.com
Contributors
About the author
About the reviewer
Packt is searching for authors like you
Preface
Who this book is for
What this book covers
To get the most out of this book
Download the example code files
Download the color images
Conventions used
Get in touch
Reviews
Introduction to IoT
Understanding IoT
Defining IoT
Architecture of an IoT ecosystem
History and evolution
IoT–applications and future prospects
Summary
Know Your Raspberry Pi
Understanding Raspberry Pi 3
Important features of Raspberry Pi 3 Model B
Setting up Raspberry Pi
Connecting to the internet
Setting up headless Raspberry Pi
Summary
Let's Communicate
The internet
The rise of JavaScript and Node.js
Node.js
Advantages of using Node.js for IoT
HTTP
Implementing HTTP
HTTP server
HTTP client
MQTT
MQTT architecture
MQTT message types
MQTT topics
QoS levels
Last will and testament
Retained messages
Persistent sessions
Keep alive message
MQTT brokers
MQTT implementation
MQTT broker
MQTT client
Summary
Weather Station
Sensors
Temperature sensor DS18B20
DHT11 humidity sensor
Weather API
Google sheets
Summary
Controlling the Pi
L293D
DC motor
Light-emitting diode
Summary
Security Surveillance
Infrared sensors
Types of IR sensors
Ultrasonic sensors
Buzzer
Raspberry Pi camera module
Wiring up
Interfacing PIR sensor module HC-SR501
Interfacing an active IR sensor
Interfacing an ultrasonic sensor HC-SR04
Interfacing an LED
The code
Camera module code
Email module code
Sensor module code
Summary
Image Recognition
Understanding image recognition
Deep learning
How image recognition works
Gathering data
Organizing data
Building a predictive model
Recognizing an image
Amazon Web Services
AWS S3
AWS Rekognition
Identity and access management
Command line interface
Implementation
Create collection
Upload reference image
Face comparison
Wiring up
Interfacing IR sensor
Interfacing LEDs
Interfacing the Pi camera module
The code
Index face module code
Search face by image module code
S3 bucket module code
Camera module code
Upload reference image module code
Compare image module code
Summary
Bot Building
Car chassis
Pulse-width modulation
Analog signal
Digital signal
Wiring up the bot
Wiring L293D with motor
Wiring L293D with Raspberry Pi
Forward movement
Reverse movement
Right turn
Left turn
Stop
Speed control
Executing the commands
Summary
Security in IoT
The challenges in providing IoT security
Security in endpoint devices – constrained devices
Authorization and authentication
Device firmware upgrade
Secure communication
Data security
High availability
Identifying cyber attacks
Absence of standards
Ignorance from customers and manufactures
Trends and challenges in specific industries
Automotive industries
Smart homes and buildings
Securing Raspberry Pi
Changing the default password
Changing the username
Making sudo require a password
Improving SSH security
Username and password security
Key-based authentication
Setting up a firewall
Fail2Ban
Summary
Other Books You May Enjoy
Leave a review - let other readers know what you think
The Internet of Things (IoT) is about connecting physical devices over the internet to each other, and making them talk to us. Applications of IoT are smart homes, buildings, connected vehicles, and when scaled up they drives smart cities and manufacturing automation. IoT is currently a growing trend in the technology space, and Raspberry Pi is the perfect board to get started with for building IoT projects. This book covers many of the powerful features of Raspberry Pi and projects, such as weather station, a facial recognition system, a security surveillance system, and learning it the practical way of using Raspberry Pi, sensors, and the cloud.
This book is for all the technology enthusiasts who want to understand what IoT is all about. The readers require just elementary knowledge of computers, programming, and Raspberry Pi. This book helps the readers to resolve the most challenging part that is interfacing hardware with software and sending data to cloud for visualization and analysis with the hands-on DIY projects. In the end, readers will be able to build state-of-the-art solutions for IoT.
Chapter 1, Introduction to IoT, provides an introduction to Internet of Things, a little background, the current scenario, the future of IoT, as well as its impact on our life. Here, you will also learn about the architecture of an IoT ecosystem and its application and benefits in different fields.
Chapter 2, Know Your Raspberry Pi, introduces you to Raspberry Pi. Why is this one of the most popular boards for learning and building IoT projects? Here, we will learn about the anatomy of Raspberry Pi, GPIO, and other functionalities. Setting it up includes installing an OS, getting comfortable with Shell commands and its UI, and connecting it to a network/Wi-Fi.
Chapter 3, Let's Communicate, makes Raspberry Pi communicate with the cloud/server using protocols such as HTTP and MQTT. We will demonstrate how data transfers between Pi and the cloud.
Chapter 4, Weather Station, sets up Raspberry Pi as a weather station, which will measure weather conditions and send the data to a Google spreadsheet for analysis. We will measure the temperature and humidity using sensors connected to GPIO programmatically.
Chapter 5, Controlling the Pi, explains how to control actuators, LEDs, and other devices connected to Pi remotely using web apps.
Chapter 6, Security Surveillance, explains how to build your own security surveillance system to protect your home/premises from intruders. We will use Raspberry Pi, a camera module, a motion sensor, and cloud to complete this project.
Chapter 7, Image Recognition, explains how we can leverage IoT to accomplish complex tasks such as face recognition using Raspberry Pi, camera module, AWS Rekognition, and AWS S3 service.
Chapter 8, Bot Building, shows how to build a Wi-Fi-controlled robot car using Raspberry Pi. We will use a motor-driver circuit, a DC motor, and a web application to complete the task.
Chapter 9, Security in IoT, talks about why security is the most important aspect of IoT, what the existing threats at the software and hardware level are, and how we can ensure security in our IoT using various practices.
You need to have a basic understanding of how electronics and circuit and systems work in alliance with different hardware components along with some programming experience.
The installation instructions are presented in a quite detailed fashion. However, if you need more insight, you can proceed to the relevant instructional manuals available in the support sections of the hardware's documentation.
You can download the example code files for this book from your account at www.packtpub.com. If you purchased this book elsewhere, you can visit www.packtpub.com/support and register to have the files emailed directly to you.
You can download the code files by following these steps:
Log in or register at
www.packtpub.com
.
Select the
SUPPORT
tab.
Click on
Code Downloads & Errata
.
Enter the name of the book in the
Search
box and follow the onscreen instructions.
Once the file is downloaded, please make sure that you unzip or extract the folder using the latest version of:
WinRAR/7-Zip for Windows
Zipeg/iZip/UnRarX for Mac
7-Zip/PeaZip for Linux
The code bundle for the book is also hosted on GitHub athttps://github.com/PacktPublishing/Internet-of-Things-with-Raspberry-Pi-3. In case there's an update to the code, it will be updated on the existing GitHub repository.
We also have other code bundles from our rich catalog of books and videos available athttps://github.com/PacktPublishing/. Check them out!
We also provide a PDF file that has color images of the screenshots/diagrams used in this book. You can download it here: https://www.packtpub.com/sites/default/files/downloads/InternetofThingswithRaspberryPi3_ColorImages.pdf.
Feedback from our readers is always welcome.
General feedback: Email [email protected] and mention the book title in the subject of your message. If you have questions about any aspect of this book, please email us at [email protected].
Errata: Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you have found a mistake in this book, we would be grateful if you would report this to us. Please visit www.packtpub.com/submit-errata, selecting your book, clicking on the Errata Submission Form link, and entering the details.
Piracy: If you come across any illegal copies of our works in any form on the Internet, we would be grateful if you would provide us with the location address or website name. Please contact us at [email protected] with a link to the material.
If you are interested in becoming an author: If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, please visit authors.packtpub.com.
Please leave a review. Once you have read and used this book, why not leave a review on the site that you purchased it from? Potential readers can then see and use your unbiased opinion to make purchase decisions, we at Packt can understand what you think about our products, and our authors can see your feedback on their book. Thank you!
For more information about Packt, please visit packtpub.com.
In this chapter, we will understand what the Internet of Things (IoT) is all about. Also, we will learn about the architecture of an IoT ecosystem, its application and benefits in different fields, its background, the current scenario, and its future.
The topics that we're going to cover are:
Understanding IoT
Architecture of an IoT ecosystem
History and evolution
IoT applications and future prospects
Looking back at the last few years, it can be observed that the Internet of Things (hereafter IoT) has become one of the most revolutionary technologies for research and development. It has opened the floodgates for numerous upcoming business models and assists in reinventing existing businesses.
But what is IoT, anyway? Why has it been called a new technological revolution? Who invented it, and when? What are its applications? Does it really hold the potential to change our lives? We will answer all such questions in this book, not just theoretically but in a DIY way. Yes, that's the best way to learn IoT.
IoT is not just technology; it is the concept of a whole new world where physical things such as cars, homes, buildings, and other components of cities have the ability to connect to the internet and interact among themselves and with humans as well. In short, it is a smart and connected world.
IoT is a phenomenon that can only be described and not defined as it is an inclusive technology that has unlimited boundaries.
A physical device in an IoT ecosystem is also called a thing or smart thing. A thing can be any device with one or more of the following features:
Sensors (temperature, humidity, motion detector)
Communication (wired or wireless)
Actuators (motor, relay, display)
Controller or processor (for computations, running software)
A few examples of things are:
Tags such as NFC, RFID, and QR code, which are computer-readable and used to identify objects
Devices such as iBeacon, Arduino, and Raspberry Pi, which have built in controllers/processors and communication channels such as Bluetooth, Wi-Fi, Ethernet, and so on
Machines such as cars, bikes, AC units, and washing machines that can work autonomously
Infrastructure such as smart-connected factories, smart-connected buildings, and smart cities
Let's understand how an IoT ecosystem works with the help of an example.
Mr. Ghanshyam is the owner of a Cargo company that has a large number of trucks as part of its fleet. They provide transportation services to various other businesses across the country. Lately, he has been incurring losses in his business due to various reasons that he has not been able to identify and rectify.
His son Shyam, who works as an IoT engineer, gets to know about his father's business condition and decides to come down and assist him. He works with him over the next few months and observes a few major issues that are incurring losses. A few of the issues are listed here:
High fuel consumption
High maintenance costs
Delivery delays
High accident rates
Shyam, being an IoT engineer, knew what needed to be done to make the business profitable and easy to manage. Let's see what steps were carried out.
Shyam converted all the trucks of fleet into smart and connected one by fitting them with various sensors to measure vital stats such as fuel level, tyre pressure, engine condition, temperature, and others. Controllers were used to perform actions as per requirements, such as turning on lights when the sun set, turning on wipers when it rained, alerting drivers, and sending important information to the cloud with the help of Wi-Fi/GPRS/GPS modules over the internet. Cameras and other such devices were used to keep an eye on driver performance to get real-time data from a truck, as shown in the following figure:
A mobile application was developed to help drivers monitor the truck's condition in real time, navigate via the best route, and receive alert notifications and job/task assignments.
An admin/control panel application was also developed and was used at the command center by managers and operators to monitor all moving trucks, which were sending real-time data over the internet. This facilitated better fleet management in the following ways:
Monitoring a truck's route to its destination; if the driver is going to a suspicious location, the engine can be turned off remotely.
Monitoring the driver's conduct with the help of a camera inside his cabin. This avoids incidents of sleeping or talking over the phone while driving and sends an alert immediately.
Navigating to nearby service stations in the case of a breakdown:
After taking all of the above measures the old fleet had now been converted into smart and connected fleet. The following figure helps us understand the architecture of the IoT solution deployed by Shyam:
Let's see how smart and connected fleets made Mr. Ghanshyam's business profitable:
Fuel efficiency
: Data received regarding braking, shifting gears, and speed helped to establish and improve the driving style of each driver, which in turn improved fuel efficiency. Also, checking on fuel levels periodically helped to curb incidents of fuel theft, which in turn reduced overall fuel cost.
Maintenance costs and delivery delays
: The sensors installed in each truck send vital information about engine health, brakes, electrical systems, and oil levels. This helps the operator to maintain the overall health of the vehicle through timely and preventive maintenance, hence reducing frequent breakdowns and delays, leading to substantial cost savings.
Improved safety
: Monitoring the driver's conduct using cameras and other sensor data helped detect aggressive, careless, and improper driving, which is always a threat to driver and vehicle safety. This data could be used to alert the driver, hold him accountable, and provide proper training for future improvement.
Route optimization
: By tracking a vehicle's current location and traffic condition using GPS, the shortest and best route could be suggested , resulting in the vehicle reaching its destination in the minimum time, reducing fuel cost, and saving time so more deliveries can be made and in turn increasing profits.
Environmental impact
: With improved vehicle conditions and taking an optimized route, lesser fuel is used, leading to less emissions of harmful gases.
Let's now look at the generalized architecture of an IoT ecosystem in the following figure. Here, we also explain the components of this architecture, such as what each component is, what role it plays, and how it is integrated with other components in the whole architecture:
The following is a brief explanation of the general IoT architecture:
Sensors, tags, and microchips are end devices in the system that observe the environment and provide information about it.
Connection management takes care of maintaining connectivity between end devices and the user/platform through various protocols such as HTTP, MQTT, and AQMP over the internet, and using Bluetooth and radio frequencies as well.
Real-time data management helps collect and store data received from end devices in the database, which may be relational or NoSQL based on the type of data.
