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

Adding dynamic asynchronous resources


The actuator project (ActuatorHttp in the GitHub repository) also needs a /Momentary resource that returns the current state of the output in XML or JSON. The implementation is similar to that of the sensor, so it's straightforward to do. But we also need a way to control the output. We do that by adding a /Set resource. Since we will call asynchronous methods, we take this opportunity to add this resource as an asynchronous POST resource. This means we must explicitly handle errors and exceptions, as well as explicitly sending the response when it is ready:

this.httpServer.Register("/Set", null, async (req, resp) => 
{ 
   try 
   { 
         // Process resource here 
 
         resp.SendResponse();    // Sends response. 
   } 
   catch (Exception ex) 
   { 
         resp.SendResponse(ex);  // Sends error response. 
   } 
}, false); 

The first parameter defines the relative URL of the resource. The second is null, which means the resource does not...