Introduction to Azure IoT
Pierre Cauchois, Senior Software Engineer, Microsoft
h"p://sched.co/9n2a
Agenda
How is Microsoft making it easy for embedded systems
engineers to connect their “things” to “the cloud”?
What do you do once the devices are connected?
Part 1: Connecting Devices to the Cloud
Azure
IoT
Hub
IoT
Solu6on
&
Intelligence
Event
processing
&
Analy6cs
(hot
and
cold
path)
Storage
/
Big
Data
Business
logic,
Protocol
Gateway
Connec6vity
monitoring
Machine
Learning
Dashboards
Device
management,
provisioning
and
authoriza6on
Field
Gateway
Device-facing Endpoints
Device
Proper6es
Device
Twin
Methods
Device
D2C
C2D
Twin
Proper6es
Methods
Azure
IoT
Hub
Backend-Facing Endpoints
Azure
IoT
Hub
IoT
Hub
management
Telemetry
Commands
Command
Devices
Device
Opera6ons
(D2C)
receive
(C2D)
send
feedback
Twins
Methods
management
Monitoring
Event
Device
processing
Business
logic,
provisioning
(hot
and
cold
path)
Connec6vity
monitoring
and
authoriza6on
SDK Supported Platforms
• Android (Java or Xamarin) • STM32
• Arduino • TI
RTOS
• Debian Linux (v 7.5) • Ubilinux
(v3.0)
• ESP8266 • Ubuntu
Linux
(v
14.04)
• Fedora Linux (v 20) • Windows
Desktop
(7,
8,
10)
• FreeRTOS • Windows
IoT
Core
(v
10)
• iOS (Xamarin) • Windows
Server
(v
2012
R2)
• mbed OS (v 2.0) • Yocto
Linux
(v
2.1)
• OpenWRT • …
and
more
• Raspbian Linux (v 3.18)
SDK Languages
C library: Node.js library: Java library:
• Microcontrollers
• Node.js
(v
0.10+)
• Java
(v
1.7+)
• RTOS
• Node-‐RED
• Android
• Linux
• Windows
C# libraries supported: Python library:
• Windows
Desktop
(7,8,10)
• v
2.7.x
• Universal
Windows
Plaeorm
• v
3.5.x
• Windows
10
IoT
Core
• Xamarin
(iOS,
Android)
Getting an SDK
• Clone on Github
• Look for it on your favoring package manager (npm, maven,
nuget, apt…)
• Examples in this presentation will be node.js
• https://github.com/azure/azure-iot-sdk-node
Giving the device an identity
• Device Identity == Identifier + Secret
• Secret:
• Symmetric keys stored in the Device Registry + Token generated from
this key and used by the device (obviously, the key never travels on the
wire)
• x509 Certs/Keys on the Device + Certificate Thumbprints in the Device
Registry
• TPM Support to store secrets
h"ps://github.com/Azure/azure-‐iot-‐hub-‐vs-‐cs/wiki/Device-‐Provisioning-‐with-‐TPM
Managing Device Identities
• Each identity supports 2 keys or 2 cert thumbprints for easy roll-
over
• Single-device and Bulk APIs to create, update or delete device
identities
Giving the Device an Identity
Device Service
var Protocol = require('azure-iot-device-amqp').Amqp; var iothub = require('azure-iothub');
var Client = require('azure-iot-device').Client; var connectionString = '[IoT Connection String]';
var registry = iothub.Registry.fromConnectionString(connectionString);
var connectionString = 'HostName=<hub-name>.azure-
devices.net;DeviceId=<some-device-id>;SharedAccessKey=<base64-
key>'; var device = { /* device description */ };
registry.create(device, function(err, res) {
var client = Client.fromConnectionString(connectionString, Protocol);; /* do something with the result */
});
/* update and delete work the same way */
/* Bulk APIs also available */
Sending a Message (“Telemetry” scenario)
Device Service
var EventHubClient = require('azure-event-hubs').Client;
var client = EventHubClient.fromConnectionString(connectionString);
client.open()
var message = new Message("foo");
.then(client.getPartitionIds.bind(client))
client.sendEvent(message, function (err, res) {/* deal with result */} );
.then(function (partitionIds) {
return Promise.map(partitionIds, function (partitionId) {
return client.createReceiver('$Default', partitionId).then(function(receiver) {
receiver.on('message', printEvent);
});
});
});
h"ps://docs.microsog.com/en-‐us/azure/iot-‐hub/iot-‐hub-‐devguide-‐d2c-‐guidance
Receiving a Message (“Command” scenario)
Device Service
client.on('message', function (msg) { var Client = require('azure-iothub').Client;
/* do something with the command */
client.complete(msg, function (err, res) { var connectionString = '[IoT Hub Connection String]';
/* We could also “reject” or “abandon” the message */
/* do something with the result */ var client = Client.fromConnectionString(connectionString);
}); client.send(<deviceId>, <message>, function (err, res) {
}); /* do something with the result */
});
h"ps://docs.microsog.com/en-‐us/azure/iot-‐hub/iot-‐hub-‐node-‐node-‐c2d
Sending and Receiving Messages
• MQTTS (and over Websockets)
• AMQPS (and over Websockets)
• HTTPS
• Protocol Gateway:
• https://docs.microsoft.com/en-us/azure/iot-hub/iot-hub-protocol-gateway
• https://github.com/Azure/azure-iot-protocol-gateway
Routing messages (new!)
https://azure.microsoft.com/en-us/blog/azure-iot-hub-message-routing-
enhances-device-telemetry-and-optimizes-iot-infrastructure-resources/
Upload large amounts of data at once
Device Service
client.uploadToBlob(<blob_name>,<file_stream>, <file_size>, function client.getFileNotificationReceiver(function(err, receiver) {
(err, result) {
receiver.on('message', function(msg) {
/* do something with the result */
/* msg contains the file location and a token to access it */
});
receiver.complete(msg, function(err, res) { /* do something */ });
});
});
• https://azure.microsoft.com/en-us/blog/upload-files-from-devices-with-azure-iot-hub/
• https://docs.microsoft.com/en-us/azure/iot-hub/iot-hub-devguide-file-upload
Execute code on the device and return the
result (“Device Methods”)
Device Service
client.onDeviceMethod(<method_name>, function (request, response) { var methodParams = {
/* Do something with the content of the request */ methodName: '<Method Name>',
response.send(<status_code>, <payload>, function(err, res) { payload: '[Method Payload]',
/* do something with the result */ responseTimeoutInSeconds: 30 //default
}); };
}); client.invokeDeviceMethod(<device_id>, methodParams, function (err,
res) {
/* deal with result */
});
h"ps://docs.microsog.com/en-‐us/azure/iot-‐hub/iot-‐hub-‐node-‐node-‐direct-‐methods
Maintain a device state and metadata (“Device
Twin”)
Device Service
client.getTwin(function(err, twin) { registry.getTwin(deviceId, function(err, twin) {
twin.on('properties.desired', function(delta) { var twinPatch = {
/* Do something with the delta (new property values) */ tags: { city: "Redmond“ },
}); properties: { desired: { telemetryInterval: 1000 } }
twin.properties.reported.update(patch, function(err) { };
/* Do something if that failed */ twin.update(twinPatch, function(err, twin) {
}); /* Do something */
}); });
});
h"ps://docs.microsog.com/en-‐us/azure/iot-‐hub/iot-‐hub-‐node-‐node-‐twin-‐getstarted
Schedule tasks on devices
Device Service
/* Same as desired properties update or device method call */ var Protocol = require('azure-iot-device-amqp').Amqp;
var Client = require('azure-iot-device').Client;
var Message = require('azure-iot-device').Message;
var client = Client.fromConnectionString(connectionString, Protocol);
var message = new Message("foo");
client.sendEvent(message, function (err, res) {/* deal with result */} );
h"ps://docs.microsog.com/en-‐us/azure/iot-‐hub/iot-‐hub-‐node-‐node-‐schedule-‐jobs
Query device twins
var query = registry.createQuery('SELECT * FROM devices', 100);
var onResults = function(err, results) {
/* Do something with the results */
if (query.hasMoreResults) {
query.nextAsTwin(onResults);
}
};
query.nextAsTwin(onResults);
h"ps://docs.microsog.com/en-‐us/azure/iot-‐hub/iot-‐hub-‐devguide-‐query-‐language
Monitor Operations and Errors (Service)
var EventHubClient = require('azure-event-hubs').Client;
var client = EventHubClient.fromConnectionString(connectionString, '/messages/operationsMonitoringEvents/*');
client.open()
.then(client.getPartitionIds.bind(client))
.then(function (partitionIds) {
return Promise.map(partitionIds, function (partitionId) {
return client.createReceiver('$Default', partitionId).then(function(receiver) {
receiver.on('message', printEvent);
});
});
});
h"ps://docs.microsog.com/en-‐us/azure/iot-‐hub/iot-‐hub-‐opera6ons-‐monitoring
Summary: Azure IoT Hub enables you to:
• Use open source, cross-platform SDKs that lets you:
• Manage device identities
• Send and receive millions of messages using industry protocols
• Route these messages to various endpoints
• Upload large amounts of data that wouldn’t fit in messages
• Store and query device state and metadata
• Execute code or schedule tasks on devices
• Monitor operations in real time
• Connect devices to the rest of the Azure stack (stream analytics, storage, databases,
machine learning…)
• …
How to try and get started?
• Start for free
• Scale as you need
• Priced according to message processing capacity
• https://azure.microsoft.com/en-us/pricing/calculator/
No Internet Connectivity, No Problem:
The Gateway SDK
• https://github.com/azure/azure-iot-gateway-sdk
• Open-Source & Cross Platform (duh!)
• Modular, with connectors to mainstream programming
languages
• Easily add support for local communication protocols
• Supports OPC-UA
Earlier Breakout Session: Building Modular IoT Gateways with OSS: http://sched.co/9mAh
The Device Catalog
• https://catalog.azureiotsuite.com/
• Browse/Search using various criteria
and applications
• Hundreds of certified devices
• Fully-fledged certification program
Part 2: What to do with these connected devices?
Build your own IoT Solution
• Process Data in Realtime with Stream Analytics
• Build Dashboards with Power BI
• Get Smart with Azure Machine Learning
• Store into Azure Storage or Azure Data Lake
• Run Big Data Analytics with Azure Data Lake Analytics or
HDInsight
• Go serverless with Azure Functions
•…
Use a Preconfigured Solution: Azure IoT Suite
https://www.azureiotsuite.com
Remote Monitoring
Predictive Maintenance
h"ps://news.microsog.com/2016/04/24/microsog-‐and-‐rolls-‐royce-‐
collaborate-‐to-‐offer-‐advanced-‐opera6onal-‐intelligence-‐to-‐airlines/#sm.
007tm3e1554eba11kf2rd2sidaxf
There’s more: Connected Vehicle Platform
• Announced at CES 2017
• https://aka.ms/mcvp
Security Program for Azure IoT
https://blogs.microsoft.com/iot/2016/10/26/introducing-the-
security-program-for-azure-iot/
https://blogs.microsoft.com/iot/2016/12/07/azure-iot-hub-
awarded-9-industry-certifications-for-public-cloud-computing/
Questions?
Thank You!
• pierreca@microsoft.com • https://azure.com/iot
• @pierreca • https://azure.com/iotdev
• https://blogs.microsoft.com/iot