Reader small image

You're reading from  Mastering Internet of Things

Product typeBook
Published inMar 2018
PublisherPackt
ISBN-139781788397483
Edition1st Edition
Right arrow
Author (1)
Peter Waher
Peter Waher
author image
Peter Waher

Peter Waher is the founder of Little Sister®, a standards-based distributed social network, based on the principles of edge computing, privacy & information ownership, for humans and machines. Currently, Peter advises companies on topics such as privacy, the IoT and Smart Cities. He has worked for 24 years with computers and device communication, including low-level development in assembler for resource-constrained devices to high-level system design and architecture. His award-winning applications has attracted global attention, and he has been invited to speak at prestigious events.
Read more about Peter Waher

Right arrow

Chapter 13. Using an Internet of Things Service Platform

As we have seen throughout the chapters of this book, developing services for the Internet of Things may often include many repetitive tasks. These relate to the architecture of the application, infrastructure, data persistence, manageability, communication framework, hosting, inter-connectivity, user interfaces, and so on. In practical applications, you also need to consider managing devices. When on a tight schedule or having limited resources, many of these tasks are omitted, or receive little attention, to cut corners.

In this chapter, you will learn how an Internet of things (IoT) service platform can help you with many of the repetitive tasks required to create a successful IoT application. This chapter covers:

  • An introduction to the IoT Gateway project
  • An overview of its architecture
  • An introduction to its hardware abstraction layer
  • Management through its XMPP architecture
  • How to create services
  • How to interface things
  • Using its databases...

Understanding the IoT Gateway project


An IoT service platform can help you with many of the repetitive tasks required when creating an IoT service or device. It also provides you with an abstraction layer for devices and gives you support for many IoT-related protocols. By using such a platform as the base for your application, many of those repeated programming tasks can be eliminated, or wholly or partially automated and solved. This leaves you to focus on what you really want to do: develop functionality. This approach drastically increases productivity and shortens development cycles, which can be used to either increase functionality or quality, or to decrease development costs. Furthermore, it improves interoperability, increases security, and makes it simpler to manage massive amounts of things in large networks, since many of these aspects are already integrated into the platform.

For these reasons, this chapter is dedicated to the study of one such IoT platform: the WaherIoT Gateway...

Running the IoT Gateway


The IoT Gateway can be run as a standalone application, without any modification. There are different encapsulations of the IoT Gateway already prepared. They are built using the same code, but have different properties and are aimed at different operating systems. Since all libraries used are based on .NET Standard, they are portable across platforms and operating systems. The encapsulations are then compiled into .NET Core 2 applications. These are the ones being executed. Since both .NET Standard and .NET Core 2 are portable, the gateway can therefore be encapsulated for more operating systems than currently supported.

Note

Check out this link for a list of operating systems supported by .NET Core 2: https://github.com/dotnet/core/blob/master/release-notes/2.0/2.0-supported-os.md

Available encapsulations such as installers or app package bundles are listed in the following table. For each one is listed the start project that can be used if you build the project and...

Configuring the IoT Gateway


All application data files are separated from the executable files. Application data files are files that can be potentially changed by the user. Executable files are files potentially changed by installers. For the Console and Service applications, application data files are stored in the IoT Gateway subfolder to the operating system's Program Data folder. Example: C:ProgramDataIoT Gateway. For the UWP app, a link to the program data folder is provided at the top of the window. The application data folder contains files you might have to configure to get it to work as you want.

Configuring the XMPP interface

All IoT Gateways connect to the XMPP network. This connection is used to provide a secure and interoperable interface to your gateway and its underlying devices. You can also administer the gateway through this XMPP connection.

The XMPP connection is defined in different manners, depending on the encapsulation. The app lets the user configure the connection...

Providing web content


The IoT Gateway includes a web server. It allows service modules to publish dynamic content and web APIs. But it also allows you to publish file-based web content. The root folder of the web server resides in the Root subfolder to the application data folder. It contains the default start page Index.md, which is a Markdown file. Markdown is by default converted to HTML automatically by the web server, unless Markdown is explicitly requested by the client. Since browsers do not request Markdown by default, browsing to the resource will result in a HTML page. After starting the gateway, you can browse its domain (or IP address), and the default start page is displayed, as shown in the following screenshot:

Default first page

Note

Note that the localhost interface is not available in UWP apps. You must browse pages hosted by the gateway from another machine in the network.

Note

You should examine the contents of the Root folder and its subfolders. This will allow you to better...

Monitoring performance


There are various methods to monitor the performance of the IoT Gateway and its services. Apart from monitoring performance counters provided by the operating system, you can also monitor event logs and sniffer output, if enabled.

Monitoring event logs

In the application data folder, a subfolder called Events is created. In it, XML files will be output when events are logged from anywhere in the system. Old XML files will be deleted automatically. The XML files reference XSL transforms in the Transforms subfolder to the application data folder. This makes it possible to view finished XML files in browsers in a user-friendly manner.

Note

Events are also persisted in the object database. These events can be searched and accessed via the XMPP interface.

Note

You can output events from your code by accessing the static Log class defined in Waher.Events.

Monitoring communication sniffers

By default, sniffers are disabled. If you enable sniffers in the network configuration, the...

Developing services for the IoT Gateway


You can easily develop your own service modules for the IoT Gateway. You just create a .NET Standard 2.0 Class Library and add the code you want to include. You add references to the libraries you wish to use. If you want to access Gateway functionality, add a reference to the Waher.IoTGateway library.

Creating a service module

It is the Waher.Runtime.Inventory module that keeps track of all modules, classes, and types in the runtime environment. You don't have to initialize it yourself, as you did in the earlier chapters. The IoT Gateway makes sure to initialize it with all available assemblies. However, it defines an interface IModule that might be of importance to you. By implementing it, you will get notified when the Gateway starts and stops. This is done through calls to the Start() and Stop() methods defined by the interface. By implementing this interface, you can make sure to initialize and terminate your service module properly.

Note

Most of...

Summary


In this chapter, you've been shown the principles of how the IoT Gateway works, and what you can do with it. You've learned about the different execution models and how to configure and run the gateway. You've been shown how to provide and customize dynamic web content using the gateway, how to develop services for the gateway, and how to monitor gateway performance. You've also learned how to interface and manage things using the gateway abstraction layer, and how to package your finished service. In the next chapter, we start the third part of the book by looking at how to harmonize different IoT technologies.

 

lock icon
The rest of the chapter is locked
You have been reading a chapter from
Mastering Internet of Things
Published in: Mar 2018Publisher: PacktISBN-13: 9781788397483
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.
undefined
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

Author (1)

author image
Peter Waher

Peter Waher is the founder of Little Sister®, a standards-based distributed social network, based on the principles of edge computing, privacy & information ownership, for humans and machines. Currently, Peter advises companies on topics such as privacy, the IoT and Smart Cities. He has worked for 24 years with computers and device communication, including low-level development in assembler for resource-constrained devices to high-level system design and architecture. His award-winning applications has attracted global attention, and he has been invited to speak at prestigious events.
Read more about Peter Waher