Introduction to Azure IoT Hubs

Connected things have been around for decades in the manufacturing, utilities, and resources industries and have solved the very real requirement of needing to know and understand how large-scale systems are operating; they have provided the Operational Technology (OT) to the more commonly talked about Information Technology (IT).

An example of such a system is supervisory control and data acquisition (SCADA). Typically, a SCADA system consists of a large number of networked sensors reporting their data over proprietary protocols to a central resource that displays information and allow the decisions to be made. The data is stored in a large database known as a historian for ongoing analysis. These industrial control systems have existed for many years and are largely secure by default as they isolate the sensors and controls in a private network, for example, a process control network.

Because SCADA systems are largely proprietary or at least based on a few protocols with a low number of hardware and software providers, they are expensive to install and maintain.

With the invention of cloud computing and the dropping prices of microprocessors and sensors, it has become possible for everyone to be a device maker. The proliferation of things connected via the Internet has led to a true revolution where everything can communicate and real value can be derived for much lower cost. With devices such as the Raspberry Pi and a whole range of microprocessors, the development of Internet-connected solutions, more commonly named the Internet of Things, are in the hands of everyone.

However, with such opportunity comes inherent danger as companies develop and deliver solutions that are not secure by default and can lead to large scale compromise. There have been a number of cases where devices that are deployed as part of home automation have been used as bot networks to launch distributed denial of service (DDoS) attacks.

Given this, security in the Internet of Things has become a key battleground for future systems.

Microsoft Azure IoT Hub provides a cloud-based service for connected things. The background to the service and the way it has been developed can be found in a post by Clemens Vasters of Microsoft.

In the post, Clemens makes the case for strong security and trusted communication that is initiated by the device itself. This security is built in to the very fabric of the service to provide confidence and trust.

Before considering how to secure an IoT Hub, it is important to understand the basics and how to create one.

Getting started with IoT Hub

Azure IoT Hub is part of the Internet of Things set of platform services along with Event Hub, Notification Hub, Stream Analytics, and Machine Learning. It provides a mechanism for securely communicating from and to devices at scale using a range of open source protocols.

When you create an IoT Hub through the portal, the following items are important to understand:

  • Name: This must be globally unique
  • Pricing and scaling tier: This determines how many units you have available and the number of messages per day that the IoT Hub instance can scale to; you are allowed one free IoT Hub per subscription
  • IoT Hub units: This is determined from the number of messages and devices that the IoT Hub is required to support
  • Device-to-cloud partitions: These are similar to, but not fully functionally identical to Event Hub partitions
  • Enable Device Management: At the time of writing this feature is still in PREVIEW

Getting started with IoT Hub

Once all information has been validated, clicking on Create creates the IoT Hub. Each Azure subscription can have a maximum of 10 IoT Hubs.

The pricing tier and IoT Hub units are used to determine the throughput and scale of IoT Hub, and it means that if not chosen correctly, your IoT Hub will throttle the messages being transmitted.

Note

For the pricing tier, the published throughput at the time of writing is as follows (see: https://azure.microsoft.com/en-us/documentation/articles/iot-hub-scaling/).

Tier

Sustained throughput

Sustained send rate

S1

Up to 1111 KB/minute per unit (1.5 GB/day/unit)

Average of 278 messages/minute per unit (400,000 messages/day per unit)

S2

Up to 16 MB/minute per unit (22.8 GB/day/unit)

Average of 4167 messages/minute per unit (6 million messages/day per unit)

S3

Up to 814 MB/minute per unit (1144.4 GB/day/unit)

Average of 208,333 messages/minute per unit (300 million messages/day per unit)

Note

For IoT Hub units, the throttling rules apply as follows (see: https://azure.microsoft.com/en-us/documentation/articles/iot-hub-devguide-quotas-throttling/).

Throttle

Per-hub value

Identity registry operations (create, retrieve, list, update, delete)

5000/min/unit (for S3)

100/min/unit (for S1 and S2).

Device connections

6000/sec/unit (for S3), 120/sec/unit (for S2), 12/sec/unit (for S1). Minimum of 100/sec.

For example, two S1 units are 2*12 = 24/sec, but you have at least 100/sec across your units. With nine S1 units, you have 108/sec (9*12) across your units.

Device-to-cloud sends

6000/sec/unit (for S3), 120/sec/unit (for S2), 12/sec/unit (for S1). Minimum of 100/sec.

For example, two S1 units are 2*12 = 24/sec, but you have at least 100/sec across your units. With nine S1 units, you have 108/sec (9*12) across your units.

Cloud-to-device sends

5000/min/unit (for S3), 100/min/unit (for S1 and S2).

Cloud-to-device receives

50000/min/unit (for S3), 1000/min/unit (for S1 and S2).

File upload operations

5000 file upload notifications/min/unit (for S3), 100 file upload notifications/min/unit (for S1 and S2).

10000 SAS URIs can be out for a storage account at one time. 10 SAS URIs/device can be out at one time.

After the creation of an IoT Hub, it can be scaled like a number of other platform services to ensure that it meets the need of the application.

Note

There is no autoscale facility so monitoring and alerts should be used to help understand the ongoing throughput and characteristics of the deployed solution.

To scale, you can either choose a new pricing tier or increase the number of IoT Hub units. Moving between the free tier and any of the paid tiers is not allowed.

Getting started with IoT Hub

After making the necessary changes to either the pricing tier or the IoT Hub units, clicking on Save updates the configuration. IoT Hub units can either be increased or decreased to allow better tuning and cost management of the solution.

Communication mechanisms in a typical IoT solution need to support the following:

  • Telemetry: Data ingestion from device to cloud at large scale
  • Query: Device query to service backend for updates for example to configuration
  • Notification: Cloud-to-device messaging to inform the device of environmental updates
  • Command: control messages from service backend to device requiring confirmation

IoT Hub supports full bidirectional messaging between devices and cloud services, and this is reflected throughout the IoT Hub configuration.

When a device is registered with IoT Hub (see later in the chapter for details), message stores for both messages from devices and messages to devices are created; these message stores act like a mailbox to which messages are delivered and retrieved. To understand these processes, it is important to understand the following terms used within the portal and documentation that refer to this communication:

  • Cloud-to-device: This is also referred to as C2D; this represents messages that are sent from backend services that are bound for a specific device. This service could be any compute resource
  • Device-to-cloud: This is also referred to as D2C; this represents messages that are sent from an individual device that need to be processed by a backend service

IoT Hub has its roots in Event Hub, and this can be seen when looking at the Messaging configuration for an instance. The Messaging configuration is split across Cloud-to-device and Device-to-cloud settings.

Getting started with IoT Hub

In the Cloud-to-device setting section, you can configure the following:

  • Default TTL: This defines how long to retain messages for devices to consume before they are expired.
  • Feedback retention time: When a message is sent to a device, an acknowledgement should be sent. This setting defines how long to retain these feedback messages in IoT Hub.
  • Maximum delivery count: This defines how many times IoT Hub will attempt to deliver a message to a device.
  • Partitions: This is read only and is set when the IoT Hub is created. This is similar in concept to partitions in Event Hub except for messages in IoT Hub you cannot set a partition key, so messages are distributed evenly across the partitions.
  • Event Hub-compatible name: This shows the name of the Event Hub endpoint that can be used to consume device-to-cloud messages using, for example, Azure Functions.
  • Event Hub-compatible endpoint: This shows the endpoint connection string for the Event Hub that is part of the instance.
  • Retention time: This defines how long to retain device-to-cloud messages before they are expired.
  • Consumer groups: Like Event Hub, this shows all consumer groups that are configured for the IoT Hub for message consumption; consumer groups in IoT Hub are functionally equivalent to those in Event Hub.

To support the rapid development of IoT Hub solution, there are SDKs for several languages.

Note

All the SDKs are open source and available for downloading; see: https://github.com/Azure/azure-iot-sdks.

At the time of writing, there are managed SDKs for C#, Java, JavaScript (that is, Node.JS), Python, and C. The SDKs are built on top of cross-platform C code that can be compiled and built on many other systems, such as microprocessors or simple devices, giving the broadest range of potential devices able to communicate with IoT Hub.

In addition to the managed SDKs, it is also possible to interact with IoT Hub through a set of HTTP APIs. These APIs allow control of many aspects of IoT Hub and devices and are available for:

  • Device identities: These allow interaction with the device identity registry to create, delete, and manage devices in the IoT Hub
  • Resource provider: This allows interaction with the resource management provider for an IoT Hub to allow creation, deletion, and the general management of the IoT Hub
  • Device messaging: This allows messages to be sent to and received from the IoT Hub such as cloud-to-device or device-to-cloud

Note

For more information on the HTTP APIs and their use, see: https://msdn.microsoft.com/library/mt548492.aspx.

By providing programmatic access via HTTP/HTTPS, most aspects of both IoT Hub and device management and IoT Hub messaging can be handled over the Internet or by devices or services capable enough to support an HTTP protocol stack. See Endpoints later in this chapter.

Differences between Event Hub and IoT Hub

Event Hub and IoT Hub share a lot of similarities, and indeed the underlying infrastructure for IoT Hub is based on Event Hub.

However, it is important to understand the differences, so the correct choice can be made when required.

Area

IoT Hubs

Event Hubs

Communication patterns

Enables device-to-cloud and cloud-to-device messaging.

Only enables event ingress (usually considered for device-to-cloud scenarios).

Device protocol support

Supports MQTT, AMQP, AMQP over WebSockets, and HTTP/1. Additionally, IoT Hub works with the Azure IoT Protocol Gateway, a customizable protocol gateway implementation to support custom protocols.

Supports AMQP, AMQP over WebSockets, and HTTP/1.

Security

Provides per-device identity and revocable access control. See the Security section of the IoT Hub developer guide.

Provides Event Hubs-wide shared access policies, with limited revocation support through publisher's policies.

Operations monitoring

Enables IoT solutions to subscribe to a rich set of device identity management and connectivity events such as individual device authentication errors, throttling, and bad format exceptions.

Exposes only aggregate metrics.

Scale

Is optimized to support millions of simultaneously connected devices.

Can support a more limited number of simultaneous connections-up to 5,000 AMQP connections, as per Azure Service Bus quotas. On the other hand, Event Hubs enable you to specify the partition for each message sent.

Device SDKs

Provides device SDKs for a large variety of platforms and languages.

Is supported on .NET and C. Also, provides AMQP and HTTP send interfaces.

File upload

Enables IoT solutions to upload files from devices to the cloud. Includes a file notification endpoint for workflow integration and an operations monitoring category for debugging support.

Uses a claim check pattern to manually request files from devices and provide devices with a storage key for the transaction.

From the table, it can be seen that one of the key reasons to choose between the two hubs is whether or not your devices are capable of bidirectional communication. However, even if your devices are only able to transmit telemetry data, IoT Hub is still useful when protocol support and greater security are required.

Security in IoT Hub

The most important thing to consider when creating an IoT solution is security. If a solution is not secure and gets compromised, the consequences could be potentially fatal.

Azure IoT Hub has security built in from the ground up and provides several mechanisms to ensure that any data transmission is safe, and full device life cycle management can be implemented to ensure that quick action can be taken in the event of a compromise of a device.

The device identity registry

IoT Hub uses a device identity registry to provide per device authentication and access control. Using device-initiated access control, per-device security, and trusted peer-to-peer communication between the device and IoT Hub, the attack vector to compromise devices is reduced.

Of course, devices themselves can still be physically compromised, but having a device identity registry allows quick remedial action to be taken to remove access to the IoT Hub and any backend services in the event of a compromise taking place.

It is not possible to create devices through the Azure portal directly; they need to be created either in a tool or via code. We discuss two tools for the simple management of devices and IoT Hub later in the chapter, but to create via code, you can use the RegistryManager class in the SDK:

static RegistryManager registryManager; 
static string connectionString = "[IOT-HUB-CONNECTION-STRING]"; 
 
static void Main(string[] args) 
{ 
   registryManager = 
   RegistryManager.CreateFromConnectionString(connectionString); 
   AddDeviceAsync().Wait(); 
   Console.ReadLine(); 
} 

static async Task AddDeviceAsync(string deviceId) 
{ 
    Device device; 
    try

    { 
        device = await registryManager.AddDeviceAsync(new Device(deviceId)); 
    } 
    catch (DeviceAlreadyExistsException) 
    { 
        device = await registryManager.GetDeviceAsync(deviceId); 
    } 
    Console.WriteLine("Generated device key: {0}", device.Authentication.SymmetricKey.PrimaryKey); 
}

To provision large volumes of devices at once, it is possible to import information in bulk.

Once created or imported, devices and their basic configuration can be viewed through the portal by clicking on Devices on the main IoT Hub blade.

In the resulting blade, information can be added to the view by clicking on Columns and choosing which information you wish to display.

Choosing a device opens a new blade that contains information such as shared access keys used to create shared access signatures and a connection string defined for the shared access key. It is possible to enable or disable a device from this blade.

The device identity registry

While the device information in the identity registry is important for the functionality of IoT Hub, in a real-world scenario, it is likely that further information is required to help define and administer a device, such as firmware version and commands that a device accepts. For this purpose, IoT Hub supports the concept of a Device Twin.

A device twin is a JSON document, stored, for example, in Azure DocumentDB, that contains additional metadata about a device that allows devices and backend services to synchronize device configurations, or it can be used to understand the state of any long-running operations that a device is reporting on. This metadata can include the following:

  • Manufacturer information
  • Firmware version
  • Capabilities
  • Valid commands

Device twins provide a mechanism to maintain the configuration state of a device using reported properties and desired properties:

  • Reported properties: These are sent by devices to allow a service backend to query the current state of the device
  • Desired properties: These are set by the service backend to allow configuration state change with the devices and can be used to notify a device of a state change in real time

Using device twins is an optimal way to manage device configuration, especially when physical access to the device is either limited or unavailable. By having a device call home to update itself either on a frequency or on restart ensures the state of the device is correct for the current operating scenario.

Shared access policies

IoT Hub supports the concept of shared access policies that are similar to the security within Event Hub. These policies can be used to create a azure (SASshared access signature (SAS) that can be used for device-to-cloud and cloud-to-device communication.

When an SAS token is created, the time for which it is valid has to be provided. Creating timebound tokens for secure access reduces the attack vector for compromised devices and enhance the overall security of the solution.

When created, an IoT Hub has the following default policies:

  • iothubowner: This has full permission to the IoT Hub
  • service: This has permission for backend service components to send cloud-to-device messages
  • device: This has permission for device to send device-to-cloud messages
  • registryRead: This has permission to read the device identity registry
  • registryReadWrite: This has permission to read and write to the device identity registry

These policies cover the operations that are possible in an instance, but it is possible to create new policies by clicking on the Add button on the Shared access policies page and choosing which permissions apply.

With this approach, it is possible to create boundaries between operations and between different parts of a more complex solution.

In the event of a compromise, it is important to maintain a strict security protocol.

Shared access policies

It is possible to regenerate the keys that are used for each policy, by clicking on More and then Regen key, to ensure that any device currently using it to sign SAS tokens can no longer connect without an update to the key. The connection string for a policy can be copied from the appropriate connection string text.

Shared access signatures

Shared access policies define the operations that are allowed by parts of an IoT solution, but shared access signatures should normally be used to perform the required operation.

Using SAS tokens adds an additional level of abstraction to the security protocol and ensures that keys are not sent across the wire.

SAS tokens are generated based on the device URI information, an expiry time, a cryptographic signature based on the device URI and expiry time, and a shared access policy name.

Because the token is based on an expiry time and shared access policy that defines the scope of access to IoT Hub, if a device connection string is obtained, the token can only be used for the time-period for which it is valid.

When using the managed SDKs, the creation of the SAS token is handled automatically at the time of the client connection.

X.509 certificates

If devices are capable of supporting full cryptographic certificate exchange, the security can be further enhanced through the use of X.509 certificates.

For IoT Hub, certificates can be obtained from a trusted certificate authority or self-signed. To create a self-signed certificate, you can use the New-SelfSignedCertificate PowerShell command.

IP filtering

The final part of the security that is supported by IoT Hub is the use of IP filtering.

IP filtering allows the creation of white lists (allowed devices or services) and black lists (denied devices or service) to further lock down and enhance the security.

IP filtering is applied by clicking on the Add button.

IP filtering

An IP address range is defined in CIDR format and the range is either allowed or rejected.

Note

For more information on this key part of IoT Hub, see: https://azure.microsoft.com/en-us/documentation/articles/iot-hub-devguide-security/.

Monitoring your IoT Hub

A key part of any robust enterprise solution is the ability to look inside and understand the state of the running solution at any time. Monitoring provides this mechanism, and IoT Hub supports monitoring of many different parts of the solution.

Monitoring your IoT Hub

Monitoring events are generated for many operations in IoT Hub and should be configured to allow a fuller understanding of the health of a solution; error conditions should be monitored for communications including uploads, and further operational monitoring of connections could provide insight in to potential solution compromise.

Communicating with IoT Hub

Device communications in an Internet of Things solution needs to support more than just a telemetry channel as supported by Event Hubs. As mentioned previously, IoT solutions need to support four modes of communication: telemetry, query, notification, and command.

To facilitate this communication, it is important to understand how to build solutions that provide device-to-cloud and cloud-to-device messaging.

D2C messaging

Messages are sent from devices to IoT Hub to provide telemetry or to query a service backend or device twin. Sending messages can be done in several languages, including NodeJS, Python, C#, and C.

To send a message using the managed SDK for C#, a Nuget package needs to be installed, which contains the code for the SDK along with dependencies required for transport and security.

D2C messaging

Once installed, using the SDK to send a message is simple. First, you need to create a DeviceClient object and provide a connection string. The SDK takes care of generating a SAS token and uses the device connect shared access policy; the connection string should be the string for the specific device:

static DeviceClient deviceClient; 
static string connectionString = "[DEVICE-CONNECTION-STRING]"; 
 
static void Main(string[] args) 
{ 
   deviceClient = 
   DeviceClient.CreateFromConnectionString(connectionString); 
   while (true)

   {

      SendToIoTHub();

      Thread.Sleep(2000);
   
   } 
} 
 
static async void SendToIoTHub() 
{ 
   Var myObject = new MyObject(); 
   var messageString = JsonConvert.SerializeObject(myObject); 
   var message = new Message(Encoding.UTF8.GetBytes(messageString)); 
   await client.SendEventAsync(message); 
   Console.WriteLine($"Sent message: {messageString}"); 
} 

This code can be used to create a simulated device that sends messages every 2 seconds based on an object of type MyObject().

Only a few lines of code are required to start sending messages to IoT Hub, and this makes it simple to start creating the infrastructure required for an entire solution while development and build of a device is ongoing.

C2D messaging

Once messages have been sent to IoT Hub, they can be processed using several services. However, once processed, it may be necessary to send messages back to the device. These messages could be notifications that the device wishes to know about or commands that instruct the device to perform a function or update configuration.

If using the managed SDK for C#, there is a NuGet package that needs to be installed in to a Visual Studio project to start interacting with the ServiceClient class. It is this class that allows communication with the service endpoint of the IoT Hub.

C2D messaging

Once installed, interacting with the service endpoint is as simple as D2C messaging:

static async void SendToIoTHub(object data) 
{ 
   var messageString = JsonConvert.SerializeObject(data); 
   var message = new Message(Encoding.UTF8.GetBytes(messageString)); 
   message.Ack = DeliveryAcknowledgement.Full; 
   message.MessageId = Guid.NewGuid().ToString(); 
 
   var serviceClient = ServiceClient.CreateFromConnectionString("[IOT-HUB-
   SERVICE-POLICY-CONN-STRING"); 
   await serviceClient.SendAsync("[DeviceId]", message); 
   await serviceClient.CloseAsync(); 
} 

In this case, the ServiceClient class is created from a connection string that has the service connect policy associated with it. The outbound message has properties set for a MessageId and type of acknowledgement required from the device. In this case, DeliveryAcknowledgement.Full requests that the device sends an acknowledgement in the event of both success and failure of processing the message.

Receiving C2D messages

Once a message has been sent to IoT Hub from a service, it remains available for the device to pick up to account for scenarios when a device may only be occasionally connected.

To receive messages on a device, the DeviceClient class is used once again, and this requires installation of the NuGet package for the managed SDK for C#. Unlike the method for sending messages, which creates the shared access signature as part of the call, when receiving messages the shared access signature must be supplied:

static DeviceClient deviceClient; 
 
static void Main(string[] args) 
{ 
   deviceClient = 
   DeviceClient.CreateFromConnectionString("[DEVICE-CONN-STRING-INCLUDING-
   SAS-TOKEN]"); 
 
   ReceiveIoTHub(); 
   Console.ReadLine(); 
} 
private static async void ReceiveIoTHub() 
{ 
   while (true) 
   { 
       Message receivedMessage = await deviceClient.ReceiveAsync(); 
          
       if (receivedMessage == null) continue; 
 
      Console.WriteLine("
Receiving message"); 
            var message = 
            Encoding.UTF8.GetString(receivedMessage.GetBytes()); 
      Console.WriteLine("Message: {0}", message); 
 
      await deviceClient.CompleteAsync(receivedMessage); 
   } 
} 

In this code, there is a loop that keeps polling the IoT Hub device endpoint for messages. Upon receiving a message, it can be processed as appropriate. Once it has been processed, CompleteAsync is called, which delivers the notification back to IoT Hub.

Again, the amount of code required to receive messages in IoT Hub when using one of the managed SDKs is very low and provides a quick route to build out a solution.

Processing D2C messages

There are several Azure platform services capable of processing a stream of data from IoT Hub, for example, Stream Analytics, Azure Functions, and HDInsight. Some of the decisions required when processing telemetry data is about the immediacy of insight.

Capturing data delivers no intrinsic value, but processing the data either in real time, sometimes named the Hot Path, or in batch processing, sometimes named the Cold Path, can deliver deep insight into a process or the potential outcome of a set of separate events. This data can be combined with data from other sources to build models and derive deep learning through services such as Azure Machine Learning.

Using Azure platform services allows a solution to be built out of building block services that are designed to be stitched together. This provides a mechanism to quickly build and prototype and solution to find out early if it can deliver real business value.

Note

For more information on cold and hot path processing of data, look at Lambda Architecture at: https://www.mapr.com/developercentral/lambda-architecture.

Uploading files

Messaging in the connected world can consist of large volumes of small messages or equally a large batch of messages or information stored within an external file.

To facilitate this latter use case, IoT Hub supports uploading of files in a way that is fully managed by the service.

Configuring the file upload process is performed through the File upload blade in the IoT Hub settings. Uploading files requires a storage account that acts as the landing place for files that are uploaded by the device. When configuring the process, the storage account is chosen along with whether you wish to receive notifications. Notifications can be consumed from the operational monitoring endpoint of the IoT Hub by Azure Stream Analytics in the same way as other operational monitoring information.

The file upload consists of three steps:

  • Obtain a file URL that contains an SAS token valid for the time specified; the Azure Storage SDK uses this as the security authentication for the upload process
  • Upload a file to the URI specified in the first step using the Azure Storage SDK
  • Send a notification back to IoT Hub indicating success or failure of the file upload

Uploading files

There are several other settings that relate to how long an SAS token is valid for and how long to keep notifications, along with the maximum number of times a notification is attempted to be delivered.

When using the managed SDK for C#, the process for uploading a file is simple and it consists of a single call as the SDK manages the three processes as an atomic unit of work:

using (var fs = new FileStream("MyFile.csv", FileMode.Open)) 
{ 
   await client.UploadToBlobAsync("MyFile.csv", fs); 
} 

Using the file upload process is a great way for a field gateway to gather incoming messages from many devices and then bulk upload on a schedule for further processing. The further processing can be performed by several other Azure services, for example, Azure Functions has a blob trigger that executes when new files arrive in blob storage.

IoT Hub tools

Like most Azure platform services, a lot of tasks can be performed within the Azure portal, such as changing scale and updating messaging information, but many tasks need to be performed outside the portal, such as device registration and shared access signature generation.

Device Explorer

One of the most useful tools for those starting with IoT Hub is Device Explorer. This provides an easy tool to use to interact directly with device and service endpoints as well as the device identity registry.

Once the IoT connection string has been entered on the Configuration tab and Update clicked, the application provides a mechanism to create, update, or delete devices, and to generate SAS tokens based on a configurable TTL. For devices in the Management tab, right-clicking opens a context menu that allows you to copy the device connection string.

Device Explorer

The Data and Messages To Device tabs allows the application to act as a message consumer service backend and a service backend sending messages to a device.

Device Explorer

The Data tab is useful when checking the content of the data being sent by the chosen device and provides a mechanism to check the connectivity of the device to the IoT Hub. Likewise, the Messages To Device tab provides a mechanism to check the connectivity between the outbound message communication between an IoT Hub backend service and a device.

Note

For more information on Device Explorer, see: https://github.com/Azure/azure-iot-sdks/tree/master/tools/DeviceExplorer.

iothub-explorer

For cross-platform support, there is a Node.js application that allows some management of IoT Hub and device identities.

With Node.js installed, iothub-explorer can be installed from the command prompt or terminal window with the following command:

npm install -g iothub-explorer@latest 

Once installed, calling the application with the --help command switch shows all the commands and their functionality.

iothub-explorer

Using a PowerShell command prompt is convenient as it allows variables to be assigned for use within commands. For example, issuing the following command assigns the connection string to a variable that can then be used during a session:

$conn = [YOUR CONNECTION STRING] 

Once stored, commands can be issued as necessary. Before performing any functions, a connection must be established with the IoT Hub instance:

iothub-explorer login $conn 

Once logged in, commands can then be issued as normal without the need to pass in a connection string. For example, to list the deviceId and connectionState of all devices, you would issue the following:

iothub-explorer list --display="deviceId, connectionState" 

The one exception to the rule for not having to supply a connection string once logged in is if you wish to monitor events for a specific device:

iothub-explorer $conn monitor-events [deviceId] 

The iothub-explorer is a good tool if you are used to using a command line when working with resources. Although it is not capable of doing everything, it is a handy tool to have available.

Note

For more information on iothub-explorer and to contribute to its development, see: https://github.com/azure/iothub-explorer.

IoT gateways

In the Internet of Things, devices range in capability from simple sensors through to fully capable computers and from using proprietary protocols through to open standards.

Due to this, it is often necessary to deploy a gateway in the field to either do the actual communication to IoT Hub or to provide local compute resources.

IoT Hub protocol gateway

To overcome the issue when a device is unable to communicate using one of the IoT Hub-supported protocols, a protocol gateway must be used to act as a bridge between a device and IoT Hub.

Azure IoT Hub provides a sample protocol gateway that is open source. This gateway acts as a protocol translator and can run on capable devices that sit between deployed devices and IoT Hub or in a cloud service that is running in Microsoft Azure that can communicate with the devices.

The sample shows how to translate from MQTT. However, because MQTT is fully supported within IoT Hub, the sample is there as a means to show how to translate from a protocol that is available on low-powered and low capability devices.

A scenario would be simple sensors that are deployed and can communicate via protocols such as CoAP, which is a popular protocol on constrained devices, but for which no support currently exists within IoT Hub. In this case, a gateway could be deployed on a device in the field that can communicate with the devices via CoAP, and it could translate these messages to AMQP for delivery to IoT Hub.

Note

For more information on the IoT Hub Protocol Gateway, see https://github.com/Azure/azure-iot-protocol-gateway/blob/master/README.md.

IoT Hub gateway SDK

Another scenario where it is important to consider the deployment of a field gateway is when local computing resources are required to process messages before they are transmitted. This could include protocol translation, as possible with the IoT Hub protocol gateway, or could include more complex stream processing computing such as translation or data enrichment.

Having local compute resources also ensures that action can be taken by the gateway in the event of the Internet connection being unavailable.

Consider a scenario where a valve is reporting inlet pressure for a gas pipeline. In this scenario, imagine what the consequence would be if the only analysis of this data was performed in the cloud. It may be important to understand if the data is showing a trend that indicates the inlet pressure is increasing. In this case, it may be necessary to close the valve to protect equipment and life downstream of the valve. If the only analysis is done in the cloud and the connection is not available, damage to equipment or loss of life could occur. Having a gateway that is capable of making decision based on the streaming data becomes important in this case.

Fog Computing is the name given to local computing resources in this example and is increasingly important in the industrial and manufacturing sectors.

Note

For more information on the IoT Hub Gateway SDK, see:  https://github.com/azure/azure-iot-gateway-sdk .

IoT suite

IoT Hub and the mechanism to create a system backend through analysis, processing, and decision making is a complex topic.

Microsoft Azure IoT suite (https://azure.microsoft.com/en-us/suites/iot-suite/) provides some sample solutions that can be used to gain an understanding of how the parts of the Microsoft IoT ecosystem can be used together.

They are full solutions that can be deployed in an Azure subscription for the purpose of testing, learning, and even if required production.

At the time of writing, there are two fully configured solutions.

  • Remote monitoring: The solution provides a dashboard and can be used to provide the end-to-end monitoring of an IoT solution. With the solution, it is possible to provision devices that have a range of capabilities that then post their data to the dashboard. Devices can be simulated or real, and the solution allows the creation of rules and alerts, as well as the ability to send messages to the devices to update their configuration. It uses the concept of a Device Twin to store additional information about the devices in Azure DocumentDB. It is the IoT Suite solution with the widest level of service use within Azure and a good starting place to understand how to build out a full solution.
  • Predictive maintenance: The solution uses Azure Machine Learning to predict the potential failure of aircraft engines based on a set of sample data. It is a good example of a truly large-scale industrial solution that uses and leverages an advanced analytics pipeline to predict an outcome.

Note

The solutions provision a lot of Azure resources using large-scale instances and therefore do incur a high cost when they are running. However, they can be downloaded from GitHub and tailored as required, both for provisioning and functionality.

For more information, see: https://azure.microsoft.com/en-us/documentation/articles/iot-suite-guidance-on-customizing-preconfigured-solutions/.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset