Book Image

Mastering Internet of Things

By : Peter Waher
Book Image

Mastering Internet of Things

By: Peter Waher

Overview of this book

The Internet of Things (IoT) is the fastest growing technology market. Industries are embracing IoT technologies to improve operational expenses, product life, and people's well-being. Mastering Internet of Things starts by presenting IoT fundamentals and the smart city. You will learn the important technologies and protocols that are used for the Internet of Things, their features, corresponding security implications, and practical examples on how to use them. This book focuses on creating applications and services for the Internet of Things. Further, you will learn to create applications and services for the Internet of Things. You will be discover various interesting projects and understand how to publish sensor data, control devices, and react to asynchronous events using the XMPP protocol. The book also introduces chat, to interact with your devices. You will learn how to automate your tasks by using Internet of Things Service Platforms as the base for an application. You will understand the subject of privacy, requirements they should be familiar with, and how to avoid violating any of the important new regulations being introduced. At the end of the book, you will have mastered creating open, interoperable and secure networks of things, protecting the privacy and integrity of your users and their information.
Table of Contents (24 chapters)
Title Page
Copyright and Credits
Dedication
Packt Upsell
Contributors
Preface
Index

Preface

Hello and welcome to Mastering Internet of Things. This book will guide you through the very fascinating subject of Internet of Things, and the emerging concept of Smart Cities. If you’re a novice to the subject, don’t worry, you’ll be introduced to it. You are assumed to know the basic principles of software development. Standard components such as Raspberry Pi, Arduino, and related peripherals will be used throughout the book. There is no need for knowledge of electronics, even though an understanding of the basic underlying principles will help. The book will guide you through many of the different problems each developer needs to face and master, using several practical projects. We’ve chosen to use C# in all the examples. It’s a modern language that will allow us to reuse code efficiently between PCs, embedded devices, smart phones, and tablets. You can choose between using free or commercial development tools. By the end, you’ll be an adept in the field, having mastered many of the fundamentals of Internet of Things and will be ready to join us in the effort in creating the next generation of Smart Cities and Smart Societies.

Defining the Internet of Things

The successful study of any subject begins with using good definitions. Without clear definitions, the boundaries become fuzzy and immediate consequences and implications become unclear. The term Internet of Things started as a visionary statement, a buzz word, rather than a definition. While the term has enjoyed exceptional media coverage, the visionary statement has been interpreted differently by different people.

The term is normally considered to be coined by Kevin Ashton in 1999 when he described a future where things such as barcode readers would be directly connected to the internet, without the interference of humans. Humans were likened to bad, slow, and error prone routers. While “things” had already been connected to the internet way before this statement, the term had not been coined yet. The utility sector, for instance, had long used connected meters to retrieve meting data automatically. This was first done using modems and the phone network already in the late 70s and 80s. When ISPs began providing internet access locally, switching to the internet became a way to reduce costs, since local phone calls could be used instead of long distance calls. Even the internet itself is a network of things. Computers and servers are naturally things that are connected. But here, thing has come to mean non-computer-thing, even though the thing must have a small computer inside, to be able to connect...confusing…

So, to avoid any further confusion, let’s provide a clear definition of what the Internet of Things is.

Note

The Internet of Things is what you get when you connect things that are not operated by humans to the internet.

This definition has four clear areas of study that we will introduce in this book:

  1. How to connect things; this is the study of communication protocols.
  2. The study of things; this includes concepts such as sensors, actuators, controllers, concentrators, bridges, and so on.
  3. Things are considered not operated by humans; do differentiate them from normal computers. This requires them to make their own decisions and act alone. This leads to the study of decision support, artificial intelligence, and so on.
  4. Being connected to the internet means the things become neighbors with all the world's criminals, hackers, and curious teenagers at once. Since things are supposedly not operated by humans, and work possibly for years unsupervised, the study of security becomes acute. IoT inherits all security issues related to building information systems on the internet.

While the Internet of Things has seen a lot of development in the first two areas mentioned previously, the last two are underdeveloped and often omitted. This has lead people such as James Clapper, former Director of National Intelligence in the USA, to state that America’s Greatest Threat is the Internet of Things (http://www.popsci.com/clapper-americas-greatest-threat-is-internet-things).

Competing terminology

As different companies and organizations strive to get attention, it’s not surprising to find a myriad of similar buzz words being used, each one highlighting different aspects of the same underlying problem, or to boast of one’s supposedly exceptional understanding of the subject. Web of Things (WoT), for instance, concerns itself with web-based technologies for the Internet of Things, such as the HTTP and Web Services. It forms a clear subset of the Internet of Things (IoT). A Connected Device is often used as a selling point. It normally refers to the internet connectivity of the device, and then falls under IoT or WoT. As an extension, the Connected Home, Connected Car, and so on, are specializations of this trend. Perhaps as an attempt to boast, Internet of Everything (IoE) was coined. But how do you connect something that is not a thing? Can you connect an emotion or a smell, without a thing in between doing the sensing? How do you connect space or water? How about abstract things, such as happiness, how do you connect that? Clearly, IoE comprises the same items and technologies as Internet of Things, but with a more bombastic title. The same can be said about Internet of People and Things. This term tries to include human interaction into the equation. But humans and their processes are already implicitly included in the original term “Internet”; it needs no further introduction. But there exists terminology that have clear differences in meaning, that are worth mentioning. Machine-to-Machine (M2M) communication relates to communication between machines, including devices and things. It doesn’t presuppose the use of the IP protocol, and the internet. Many different types of protocols and technologies can be used in M2M solutions, including the IP protocol. But solutions are typically sealed or closed. The internet, if used, is used as a carrier of signals and not a platform for interoperability. Cyber-Physical Systems (CPS) is like M2M in the sense that it doesn’t presuppose the use of the IP-protocol. In CPS, however, it’s the interaction between algorithms running on machines with the physical environment that is of interest.

Envisioning the Smart City

For our purposes, since we aim at being able to build smart interoperable cities and societies, the term Internet of Things fits best. Taking the full definition of IoT given earlier, we could even say that we try to build an Internet for Things, by providing the necessary infrastructure for things to be able to make good decisions during their connected life-times. But what is a Smart City, or a Smart Society?

In a Smart City, or a Smart Society, you have:

  • Ubiquitous access to interoperable sensors and things
  • Ubiquitous access to data and information from society’s authorities 

  • Access to smart services in all niches of society

When you’ve completed reading this book, you’ll know how to accomplish this goal.

What this book covers

Chapter 1,Preparing Our First Raspberry Pi Project, introduces you to development for Raspberry Pi. You’ll get an introduction to the Raspberry Pi and peripherals and how to prepare, start, and administer your device. You’ll learn how to develop, compile, run, deploy, and test your application on your device.

Chapter 2, Creating a Sensor to Measure Ambient Light, shows you how to create a basic sensor firmware application for your device. This includes sampling, error correction, management of physical quantities, basic statistics, and data persistence.

Chapter 3, Creating an Actuator for Controlling Illumination, focuses on how to create a basic actuator firmware application. You’ll learn how to define control parameters, use relays to control equipment, persist control states, and log important control events.

Chapter 4, Publishing Information Using MQTT, presents a simple way to publish your information on the internet. It introduces you to the MQTT protocol, the Publish/Subscribe communication pattern, how to connect to a broker, publish information, and subscribe to information. You’ll learn to test and troubleshoot your communication and consider basic security issues.

Chapter 5, Publishing Data Using HTTP, introduces you to the HTTP protocol and the Request/Response communication pattern. This includes locating resources on the internet and basic protocol semantics. You’ll also learn how to publish machine-readable web service interfaces and the fundamentals of encryption.

Chapter 6, Creating Web Pages for Your Devices, continues by focusing on human interfaces for your devices, and how they can be used to monitor and interact with them. You’ll learn how to publish file-based content how to use Markdown to publish human-readable web content, how to interact with backend web services from JavaScript. You will also learn how to perform basic authentication using login pages and Java Web Tokens (JWT).

Chapter 7, Communicating More Efficiently Using CoAP, shows you how to create interfaces for resource-constrained devices. You’ll get an introduction to the CoAP protocol, how security is performed, how content is encoded, how data is published, and how to respond to control actions. You’ll be introduced to a new Communication Pattern, the Event Subscription, and the Observe pattern. You’ll learn how to test your CoAP-enabled devices and how to secure them using encryption.

Chapter 8, Interoperability, introduces the concept of application-level interoperability and how standardized technologies can help us in our work. You’ll be introduced to Constrained RESTful Environments (CoRE), the Light-weight Machine-to-Machine(LWM2M) enabler , and a standardized object model for the management of devices based on CoAP and CoRE. IPSO Smart Objects, a set of standardized object interfaces for sensors and actuators, will also be presented.

Chapter 9, Social Interaction with Your Devices Using XMPP, begins a series of chapters introducing a more advanced paradigm of communication with devices that will allow us to do much more interesting things with them in a more secure and interoperable, yet flexible manner. This chapter introduces the XMPP protocol and the basics of XMPP extensions. It introduces a trust-based model for communication and security in a social context. The chapter shows how the Request/Response, Event Subscription, and Publish/Subscribe patterns can be used in XMPP. It also shows how to build human-to-machine chat interfaces.

Chapter 10, The Controller, introduces a new type of device, the controller. It presents a way to register and discover things on the internet using Thing Registries. It will subscribe to data from sensors it finds and accepts and send control operation commands to appropriate actuators it finds and accepts.

Chapter 11, Product Life Cycle, highlights that managing devices in an IoT infrastructure is more complicated than just installing devices, finding them, and starting to communicate with them. You need to manage the devices over their entire life cycle. You also need to consider operating costs, without compromising on the security and integrity of the data and people involved. This chapter introduces a method of provisioning that takes all these aspects into account. It defines the concept of ownership of data, and how owners can claim their devices. It presents a decision support extension to XMPP that helps devices determine who can be their friends and who can do what with them, based on the wishes of their owners.

Chapter 12, Concentrators and Bridges, presents a method to encapsulate virtual devices inside one communicating entity called a concentrator seamlessly, as if they were standalone devices on the network. The same technique used to model embedded devices can be used to bridge between protocol islands, either using the same or different types of communication protocols, or to integrate backend systems into the network. You’ll learn to create a concentrator embedding both your sensor and actuator functionality into one single physical device. You’ll also learn how you can interact with these embedded devices and how they can be provisioned just as if they were standalone devices.

Chapter 13, Using an Internet of Things Service Platform, shows how an IoT Service Platform can help you with many of the repetitive tasks required to create a successful IoT application. It introduces the IoT Gateway project, its architecture and hardware abstraction layer, security infrastructure, and its management interfaces. You’ll learn how to create services running on the IoT Gateway, how to use its databases for persistence, how to interface things, and use its hosting environment.

Chapter 14, IoT Harmonization, introduces a standardization effort to harmonize the wide range of technologies used in the field of Internet of Things, with the goal of creating an infrastructure for the Smart City. It reviews the vision of a Smart City and identifies the main driving forces and requirements for reaching the vision. The chapter gives an overview of the required new standards and new business roles.

Chapter 15, Security for the Internet of Things, motivates the reader to add security for the Internet of Things from the beginning, integrating it into the fabric of the design and architecture, and not adding it later, as an add-on, in case it is needed. It provides a general introduction to the problem, reviews common attack surfaces, and presents some common counter measures.

Chapter 16, Privacy, introduces privacy, and why it matters. It presents new modern privacy legislation, and how technology presented in this book can be used to protect the privacy.

What you need for this book

Apart from a computer running Windows, Linux, or Mac OS, you will need three Raspberry Pi 2 model B credit-card-sized computers or later, with 16 GB SD cards containing the Windows 10 IoT operating system installed. The first chapter lists the components used to build the circuits used in the examples presented in the book as well as the applications needed to build the projects. The source code for all the projects presented in this book is available for download from GitHub at https://github.com/PeterWaher/MIoT.

Who this book is for

This book is for students, developers, or electronics engineers who want an introduction to the Internet of Things, or for professionals who want to deepen their understanding and explore the possibilities of different technologies for the Internet of Things and the Smart City. With only a rudimentary understanding of electronics (high school level), Raspberry Pi or similar credit-card-sized computers, and some programming experience using managed code such as C# or Java or object-oriented languages such as C++, you will be taught to develop state-of-the-art solutions for the Internet of Things in an instant.

Conventions

In this book, you will find a number of text styles that distinguish between different kinds of information. Here are some examples of these styles and an explanation of their meaning.

Code words in text, database table names, folder names, filenames, file extensions, path names, dummy URLs, and user input are shown as follows: "Make sure the serialCommunication device capability is added."

A block of code is set as follows:

<Capabilities>
    <Capability Name="internetClient" />
    <DeviceCapability Name="serialcommunication">
        <Device Id="any">
            <Function Type="name:serialPort" />
        </Device>
    </DeviceCapability>
</Capabilities>

When we wish to draw your attention to a particular part of a code block, the relevant lines or items are set in bold:

<Capabilities>
    <Capability Name="internetClient" />
<DeviceCapability Name="serialcommunication">
        <Device Id="any">
            <Function Type="name:serialPort" />
        </Device>
    </DeviceCapability>
</Capabilities>

Any command-line input or output is written as follows:

$ sudo apt-get udpate 
$ sudo apt-get upgrade 
$ sudo apt-get install mono-complete

New terms and important words are shown in bold. Words that you see on the screen, for example, in menus or dialog boxes, appear in the text like this: "Clicking the Next button moves you to the next screen."

 

Note

Warnings or important notes appear like this.

Note

Tips and tricks appear like this.

Reader feedback

Feedback from our readers is always welcome. Let us know what you think about this book—what you liked or disliked. Reader feedback is important for us as it helps us develop titles that you will really get the most out of.

To send us general feedback, simply e-mail [email protected], and mention the book's title in the subject of your message.

If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, see our author guide at www.packtpub.com/authors.

Customer support

Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.

Downloading the color images of this book 

We also provide you with a PDF file that has color images of the screenshots/diagrams used in this book. The color images will help you better understand the changes in the output. You can download this file from http://www.packtpub.com/sites/default/files/downloads/MasteringInternetOfThings_ColorImages.pdf.

Download the example code files

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:

  1. Log in or register at www.packtpub.com.
  2. Select the SUPPORT tab.
  3. Click on Code Downloads & Errata.
  4. 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 at </span>https://github.com/PacktPublishing/Mastering-Internet-of-Things. 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 at https://github.com/PacktPublishing/. Check them out!

Errata

Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you find a mistake in one of our books—maybe a mistake in the text or the code—we would be grateful if you could report this to us. By doing so, you can save other readers from frustration and help us improve subsequent versions of this book. If you find any errata, please report them by visiting http://www.packtpub.com/submit-errata, selecting your book, clicking on the Errata Submission Form link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata will be uploaded to our website or added to any list of existing errata under the Errata section of that title.

To view the previously submitted errata, go to https://www.packtpub.com/books/content/support and enter the name of the book in the search field. The required information will appear under the Errata section.

Piracy

Piracy of copyrighted material on the Internet is an ongoing problem across all media. At Packt, we take the protection of our copyright and licenses very seriously. If you come across any illegal copies of our works in any form on the Internet, please provide us with the location address or website name immediately so that we can pursue a remedy.

Please contact us at [email protected] with a link to the suspected pirated material.

We appreciate your help in protecting our authors and our ability to bring you valuable content.

Questions

If you have a problem with any aspect of this book, you can contact us at [email protected], and we will do our best to address the problem.