Book Image

Learning Internet of Things

By : Peter Waher
Book Image

Learning Internet of Things

By: Peter Waher

Overview of this book

<p>This book starts by exploring the popular HTTP, UPnP, CoAP, MQTT, and XMPP protocols. You will learn how protocols and patterns can put limitations on network topology and how they affect the direction of communication and the use of firewalls. Thing registries and delegation of trust are introduced as important tools to secure the life cycle of Things on the Internet. Once the fundamentals have been mastered, your focus will move to the Internet of Things architecture. A secure architecture is proposed that will take full advantage of the power of Internet of Things and at the same time protect end user integrity and private personal data without losing flexibility and interoperability.</p> <p>This book provides you with a practical overview of the existing protocols, communication patterns, architectures, and security issues important to Internet of Things.</p>
Table of Contents (16 chapters)
Learning Internet of Things
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Preface

Internet of Things is one of the current top tech buzzwords. Large corporations value its market in tens of trillions of dollars for the upcoming years, investing billions into research and development. On top of this, there is the plan for the release of tens of billions of connected devices during the same period. So you can see why it is only natural that it causes a lot of buzz.

Despite this, nobody seems to agree on what Internet of Things (IoT) actually is. The only thing people agree on is that whatever it is, it is worth a lot of money. And where there is a lot of money, there is a lot of competition, which in reality means a lot of confusion. To be able to stand out as a superior player, companies invent new buzz words in an attempt to highlight their superior knowledge. In this battle of gaining the reader's attention, the world is now seeing a plethora of new definitions, one better than the other, such as "Internet of Everything," "Web of Things," "Internet of People and Things," and so on. To pour gasoline on fire, there is a constant overlap and confusion of ideas from related terms, such as "Big Data," "Machine-to-Machine," and "Cyber-Physical Systems" to mention a few.

This lack of consensus on what IoT actually is and what it means makes it somewhat difficult to write a book on the subject. Not because the technical aspects are difficult—they are not—but because you need to define what it is you are going to talk about and also what you are not going to talk about. You need to define IoT in a way that is simple, valid, and constructive, while at the same time it should minimize controversy.

A definition for Internet of Things

To be able to define IoT, let's first look at how the term was coined. Kevin Ashton noted that most data on the Internet was at the time originally entered or captured into the system by human beings. From a system point of view, a human is nothing more than a slow, error-prone, and inefficient router of data that puts limits on quality and quantity of data available and sometimes even dares to interpret data or correct it. As an alternative, it would be more efficient if these systems could connect to sensors that measure these real-world events or properties directly. So, in this vision, systems bypass human intermediaries and connect directly to sensors connected to the Internet to capture real-world data.

The problem with this definition is that it is not a definition at all but a vision, albeit with an important point. If systems can access data captured by sensors directly, of course, the data will be both more abundant and more correct. This was known decades ago and is a field of study in its own right, labeled "sensor networks". What is the real difference between these two? What is the difference between IoT and Big Data, where the efficient storage of huge volumes of data is handled? How does IoT differ from machine-to-machine (M2M) or device-to-device (D2D) communication, where communication between Things is discussed? Or, how does it differ from cyber-physical systems (CPS) that concerns itself with systems that interact with the real world through sensors and actuators? What is the real difference between IoT and the just mentioned fields of study?

Let's, therefore, have a very simple definition and see where it leads us:

Note

The IoT is what we get when we connect Things, which are not operated by humans, to the Internet.

Competing definitions

IoT is not the same as sensor networks since Things neither need to be sensors, nor do sensor networks need to be connected to the Internet. Also, IoT is not the same as big data since neither Things are required to capture or generate data, nor do applications need to store the data centrally (in the Cloud) in big data stores. IoT is not part M2M since being on the Internet implies humans can (and want to) access these Things directly too. Furthermore, the latter, as well as CPS, also concern themselves with non-Internet protocols, transport of messages between machines and/or devices in the network, as well as automation, often in closed and controlled environments.

Being connected to the Internet is much more than simple connectivity and message transport. The Internet is open, meaning anybody can add Things to it. It also means they will want Things to interoperate in a loosely coupled manner. The Internet is not only open, but it also is the largest network in the world. It is also the foulest cesspit in the world. Connect something to the Internet, and you can be rest assured that somebody will try to take advantage of it or destroy it if they can, just for the sheer fun of it. Comparing IoT to M2M communication is like assuming that an experiment in a controlled laboratory environment will continue to work even when you let a bunch of 3-year-old kids high on caffeinated beverages enter the laboratory, equipped with hammers and a playful attitude, and promised ice cream if they destroy everything they could see.

While some are concerned that IoT is too limited to include people in the equation, and it invents new terminologies such as Internet of People and Things, this is already included in the definition we just saw where we noted that people are already connected to the Internet via computers when we connect Things. Such a definition is therefore not necessary. Others discuss a Web of Things (WoT), which is a subset of IoT, where communication is limited to web technologies, such as HTTP, browsers, scripting, and so on. This view might stem from equaling the Internet with the World Wide Web (WWW), where access to the Internet is made through browsers and URLs. Even though we will discuss web technologies in this book, we consider web technologies alone too limiting.

There are also misleading definitions that act more like commercial buzz words rather than technological terminology, such as Internet of Everything, promoting the idea of being something more than IoT. But what is included in Internet of Everything that is not already included in IoT? All connectable Things are already included in IoT. Things that cannot be connected directly (air or water), or indirectly (vacuum or happiness) cannot be accessed in Internet of Everything either, just because the name says so. Everything needs a Thing or a Person to connect to the Internet. There are claims that the Internet of Everything includes processes, and such, and would differ in that sense. But, in the definition we just saw, such processes would be simple corollaries and require no new definition.

Direct consequences

Now that we have a clear definition of IoT, as something we get when we connect Things, not operated by humans, to the Internet, we are ready to begin our study of the subject. The definition includes four important components:

  • Connection, which relates to the study of communication protocols

  • Things, which relates to the study of sensors, actuators, and controllers, among other Things

  • Non-operation by humans relates to provisioning

  • The Internet relates to security, including identities, authentication, and authorization, but also to interoperability

This book will introduce all these concepts one at a time using simple and practical examples illustrating how these key concepts can be implemented using the Raspberry Pi platform.

What this book covers

Chapter 1, Preparing our IoT Projects, introduces the projects we will use throughout the book, their basic project structure, our development environment, how to prepare our Raspberry Pi, and how to perform basic input and output operations on it.

Chapter 2, The HTTP Protocol, presents the basics of the HTTP protocol and how it can be used in IoT applications. It also describes how it relates to the request/response and event subscription communication patterns.

Chapter 3, The UPnP Protocol, presents the basics of the UPnP protocol and how it can be used to discover devices in an ad hoc local area network. It also discusses how to call services on the devices and subscribe to events from them. Additionally, it describes how to build devices that publish such discoverable services and events.

Chapter 4, The CoAP Protocol, presents the basics of the CoAP protocol and how it can be used on devices that communicate over bandwidth-limited networks. It will show you how to publish content, how to subscribe to events, how to transport large content items using blocks, and how to discover existing resources on a device.

Chapter 5, The MQTT Protocol, introduces the MQTT protocol and shows how our IoT applications can bypass firewalls using the publish/subscribe communication pattern and message brokers.

Chapter 6, The XMPP Protocol, presents the XMPP protocol, and how it uses a federated set of message brokers to provide global identities and how it provides a richer set of communication patterns to the IoT developer. This chapter also introduces new communication patterns such as friendship authorization, presence subscription, asynchronous messaging, delegation of trust, and provisioning.

Chapter 7, Using an IoT Service Platform, presents reasons for using a service platform designed for IoT to facilitate rapid application development of IoT services and taking care of recurrent issues, such as security, interoperability, scalability, management, monitoring, and so on.

Chapter 8, Creating Protocol Gateways, shows you how to use good abstraction models to facilitate the creation of protocol bridges, allowing the interconnection of systems and services based on different technologies. This will enable you to design a secure and interoperable infrastructure for smart cities based on the IoT.

Chapter 9, Security and Interoperability, gives an overview of available threats and common modes of attack and how to build counter measures to protect your IoT solutions. It also shows the importance of interoperability in IoT and how to avoid limiting one to favor the other.

Appendix A, Console Applications, shows the basic structure of console applications, as used throughout the examples in this book.

Appendix B, Sampling and History, shows how sampling and historical record keeping of sensor values is done in the Sensor project published in this book.

Appendix C, Object Database, shows how to persist data in an object database, simply by using class definitions.

Appendix D, Control, shows how control operations are implemented in the Actuator project published in this book.

Appendix E, Fundamentals of HTTP, provides an overview of the fundamentals of the HTTP protocol.

Appendix F, Sensor Data Query Parameters, provides a set of query parameters we can use to limit readout requests from devices to data we are interested in.

Appendix G, Security in HTTP, discusses different ways to implement security into applications using the HTTP protocol.

Appendix H, Delayed Responses in HTTP, presents a method how to modify the request/response communication pattern used in HTTP to mimic the event subscription communication pattern.

Appendix I, Fundamentals of UPnP, provides an overview of the fundamentals of the UPnP protocol.

Appendix J, Data Types in UPnP, lists common data types used in UPnP.

Appendix K, Camera Web Interface, presents a simple web interface publishing pictures taken by the camera.

Appendix L, Text Encoding on the Web, discusses text encoding on the web, and possible encoding conflicts.

Appendix M, Sending Mail with Snapshots, shows how to send mail including embedded snapshots taken by the camera.

Appendix N, Tracking Cameras, shows how the controller application tracks available cameras in the network.

Appendix O, Certificates and Validation, gives a short description of how certificates work, and how to install certificates on the Raspberry Pi.

Appendix P, Chat Interfaces, shows how to add a chat interface to your devices, making it possible to chat with them using standard chat applications based on XMPP.

Appendix Q, QR Code, shows a simple way to generate and display QR code.

Appendix R, Bill of Materials, contains bills of materials containing the components used for the boards used in the examples in this book.

These Appendices are not present in the book but are available for download at the following link: https://www.packtpub.com/sites/default/files/downloads/3494_3532OT_Appendices.pdf

What you need for this book

Apart from a computer running Windows, Linux, or Mac OS, you will need four or five Raspberry Pi model B credit-card-sized computers, with SD cards containing the Raspbian operating system installed. Appendix R, Bill of Materials, which is available online, lists the components used to build the circuits used in the examples presented in the book.

The software used in this book is freely available on the Internet:

Who this book is for

This book is for developers or electronics engineers who are curious about IoT. 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 language, such as C++, you will be taught to develop state-of-the-art solutions for the IoT in an instant.

Conventions

In this book, you will find a number of styles of text 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, pathnames, dummy URLs, user input, and Twitter handles are shown as follows: "For instance, Digital outputs are handled using the DigitalOutput class."

A block of code is set as follows:

private static DigitalOutput executionLed = new DigitalOutput (23, true);
private static DigitalOutput measurementLed = new DigitalOutput (24, false);
private static DigitalOutput errorLed = new DigitalOutput (25, false);
private static DigitalOutput networkLed = new DigitalOutput (18, false);

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 such as "Internet of Things (IoT)" are shown in bold. Words that you see on the screen, in menus or dialog boxes for example, appear in the text like this: "To be able to configure the screen as we want, we enter the Settings menu, click on the Layout menu item, and select the No Menu 5x4 option ".

Note

Warnings or important notes appear in a box like this.

Tip

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 may have disliked. Reader feedback is important for us to develop titles that you really get the most out of.

To send us general feedback, simply send an e-mail to , and mention the book title via 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 on 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 example code

The code for the example projects presented in this book, are available for download from GitHub. The following table shows where each solution is published:

Viewing or downloading the online appendices

You can view or download appendices A to R for this Packt book from your account at http://www.packtpub.com. If you purchased this book elsewhere, you can visit https://www.packtpub.com/books/content/support and register to have the files e-mailed directly to you. Note that a URL is mentioned above, to download the appendices:

https://www.packtpub.com/sites/default/files/downloads/3494_3532OT_Appendices.pdf

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 would 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 on our website, or added to any list of existing errata, under the Errata section of that title. Any existing errata can be viewed by selecting your title from http://www.packtpub.com/support.

Piracy

Piracy of copyright 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 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

You can contact us at if you are having a problem with any aspect of the book, and we will do our best to address it.