azure iot workshop

109
Azure IoT Workshop– 13.10.2017 Azure IoT Workshop @marco_parenzan

Upload: marco-parenzan

Post on 22-Jan-2018

321 views

Category:

Technology


1 download

TRANSCRIPT

Page 1: Azure IoT Workshop

Azure IoT Workshop– 13.10.2017

Azure IoT Workshop@marco_parenzan

Page 2: Azure IoT Workshop

Azure IoT Workshop– 13.10.2017

@marco_parenzan

◇.NET, JavaScript,Azure ad IoT Developer, Trainer and Consultant

◇Microsoft MVP 2017 for Azure

◇Book Author @ Packt, LSWR

◇Community Lead per 1nn0va

Page 3: Azure IoT Workshop

Azure IoT Workshop– 13.10.2017

Page 4: Azure IoT Workshop

Azure IoT Workshop– 13.10.2017

Things

IoT Solutions Have a Common Pattern

Insights ActionsCloud

Gateway

Azure IoT Hub

Page 5: Azure IoT Workshop

Azure IoT Workshop– 13.10.2017

IoT Scenario

IoT Hub

(Events and Devices)

Function

(Process)

Function

(Alerts)

Storage

(Storage)

Page 6: Azure IoT Workshop

Azure IoT Workshop– 13.10.2017

Page 7: Azure IoT Workshop

Azure IoT Workshop– 13.10.2017

Page 8: Azure IoT Workshop

Azure IoT Workshop– 13.10.2017

Page 9: Azure IoT Workshop

Azure IoT Workshop– 13.10.2017

Page 10: Azure IoT Workshop

Azure IoT Workshop– 13.10.2017

Page 11: Azure IoT Workshop

Azure IoT Workshop– 13.10.2017

Page 12: Azure IoT Workshop

Azure IoT Workshop– 13.10.2017

Disclaimer

◇This is not an electronic course!

◇You are not an electronic geek!

◇I’m not an electronic geek!

◇You cannot avoid these skills in your team

Page 13: Azure IoT Workshop

Azure IoT Workshop– 13.10.2017

Warning! We cannot avoid…

Electronic engineers

Process engineers

Industrialization

process

Page 14: Azure IoT Workshop

Azure IoT Workshop– 13.10.2017

Warning! We are not saying…

Software engineers can create devices

Page 15: Azure IoT Workshop

Azure IoT Workshop– 13.10.2017

We are just saying…

Embedded world is no

more a niche

Software engineers can

contribute

Page 16: Azure IoT Workshop

Azure IoT Workshop– 13.10.2017

It is no more a niche

Proprietary Hardware and

toolsObsolete tools

No software rules and

quality

Page 17: Azure IoT Workshop

Azure IoT Workshop– 13.10.2017

Software engineers can contribute

Methodologies Patterns(Cloud)

Infrastructure

“Openness” Tools Languages

Page 18: Azure IoT Workshop

Azure IoT Workshop– 13.10.2017

Tools

Up to date compilers

Modern IDEsSDK (Libraries and Drivers)

Debuggers Simulators

Page 19: Azure IoT Workshop

Azure IoT Workshop– 13.10.2017

Languages

CProcessin

gNode.js

Python Java C#

Page 20: Azure IoT Workshop

Azure IoT Workshop– 13.10.2017

Software Developer Role

Develop and test the process and

the cloud infrastructure

Develop and test the device

software design

Cannot test sensors and

actuators

Work with fake/random data

Page 21: Azure IoT Workshop

Azure IoT Workshop– 13.10.2017

Page 22: Azure IoT Workshop

Azure IoT Workshop– 13.10.2017

Contesto

◇Azienda di Produzione Industriale■10-50M EURO

◇Presenza world-wide

◇Mercato Pro■Più sensibili al servizi

■E poi discutiamo del privato

◇Su commessa■Assorbe I costi iniziali

■E poi discutiamo della serie

10M€

Page 23: Azure IoT Workshop

Azure IoT Workshop– 13.10.2017

Industial Stainless Steel Kitchen Applications

Page 24: Azure IoT Workshop

Azure IoT Workshop– 13.10.2017

Scenario: resistor performance loss

◇Reference temperature is no more reachable

◇Example■fry-top: 400°C 300°C ■human cannot verify the temperature

■Mechanical thermostat shows only reference temperature, not current temperature

◇Effects■Longer cooking

■“Bad” cooking

■Customer impact

■Prelude to break

Page 25: Azure IoT Workshop

Azure IoT Workshop– 13.10.2017

Scenario: resistor break

◇Typically after a loose of performances, resistor elements break (days/weeks)

◇Effects■Appliance break

■Kitchen mainly slow down (few cooking appliances)

○Kitched typically don’t stop | Many elements in cooking blocks can supply loss of other elements

■Long time in assistance (no SLA discussed)

■Stop can vary from hours to days

■Final customer impact/reputation

Page 26: Azure IoT Workshop

Azure IoT Workshop– 13.10.2017

Required solution

◇Telemetry in industrial cooking plants

◇Intelligent appliances that sends status/operational data

◇Collect data world wide

◇Group by■Appliances

■Temperature range

■Daily/Seasonal data

■Kitchen/Plant

◇Apply data analysis algorithms■Final analysis (analyze costs)

■Forecast analysis (prevent uncontrolled failures, manage “planned” failures)

Page 27: Azure IoT Workshop

Azure IoT Workshop– 13.10.2017

Proposizione

◇Assolvere ad una esigenza «immediata»■Manutenzione predittiva

■Manutenzione preventiva

■Abbattere i costi della manutenzione

◇Assolvere ad una esigenza «a lungo termine»■Offrire nuovi servizi alle aziende

■Permettettere alle aziende di offrire nuovi servizi

■Nuovo modello di business (CAPEXOPEX)

Page 28: Azure IoT Workshop

Azure IoT Workshop– 13.10.2017

Industria 4.0

http://www.slideshare.net/alexcurti/piano-industria-40-68702177

Page 29: Azure IoT Workshop

Azure IoT Workshop– 13.10.2017

Benefici attesi dall’ Industria 4.0

Page 30: Azure IoT Workshop

Azure IoT Workshop– 13.10.2017

Tecnologie abilitanti Industria 4.0

Page 31: Azure IoT Workshop

Azure IoT Workshop– 13.10.2017

Page 32: Azure IoT Workshop

Azure IoT Workshop– 13.10.2017

Embedded

◇È la tecnologia che rende intelligente un elemento prodotto

◇Permette di creare azione ed interazione LOCALE

◇Usa microprocessori o microcontrollori

◇Microcrontrollori: I/O oriented, Atmel ATmeg328, ESP8266 ■I/O, realtime

■GPIO (5V, 3,3V)

◇Microprocessori: ARM Cortex, Intel Quark, Intel Atom■Gateway

◇Elementi tecnologici di riferimento■Consumo energetico

◇Si parla spesso di SOC: System On Chip■Integrazione cost effective

◇Può essere realtime

Page 33: Azure IoT Workshop

Azure IoT Workshop– 13.10.2017

I progetti Embedded IoT sono complessi

•conoscenzeIncompatibile con la infrastruttura

corrente

•conoscenzeTime consuming da avviare

•Infrastruttura complessa•Procedure

Difficile da mantenere

•Costi•Infrastruttura complessa

Difficile da scalare

Page 34: Azure IoT Workshop

Azure IoT Workshop– 13.10.2017

Makers

◇Board con microcontrolloreArduino

◇Board con microprocessoreRaspberry

◇Prototipazione■Verifichiamo che l’idea funzioni

◇Focus on:■Programming, Connecting

■…non sull’elettronica…

◇Non industrial-grade

◇Hanno cambiato il modo di interagire con il mondo embedded

◇Queste schede sono «naturalmente» connesse a Internet■Implementano sempre uno stack TCP/IP o almeno una connessione esterna evoluta (USB)

Page 35: Azure IoT Workshop

Azure IoT Workshop– 13.10.2017

Boards for makers

Arduino

Page 36: Azure IoT Workshop

Azure IoT Workshop– 13.10.2017

Industrial-grade Makers

Arduino

Raspberry

Olimex

Toradex

Page 37: Azure IoT Workshop

Azure IoT Workshop– 13.10.2017

Embedded Device

GPIO

Sensors

Actuators

Board

Edge/Local

Processing

State

Page 38: Azure IoT Workshop

Azure IoT Workshop– 13.10.2017

IoT Device=Embedded Device + Communication

GPIO Communication

Sensors

Actuators

Board

Edge/Local

Processing

State

Page 39: Azure IoT Workshop

Azure IoT Workshop– 13.10.2017

Non solo Raspberry…Industruino

Page 40: Azure IoT Workshop

Azure IoT Workshop– 13.10.2017

Energy ManagementVertical Cloud

MA DI CHI SONO I DATI?

Page 41: Azure IoT Workshop

Azure IoT Workshop– 13.10.2017

Page 42: Azure IoT Workshop

Azure IoT Workshop– 13.10.2017

Alternatives

Costs

Performances

Page 43: Azure IoT Workshop

Azure IoT Workshop– 13.10.2017

Performance of Arduino class devices

◇- The absolute performance power of Arduino device is low■Arduino is a microcontroller-based architecture

■Raspberry Pi is a microprocessor-based architecture

◇+ Pro: Arduino has a light set of running services, light OS

Page 44: Azure IoT Workshop

Azure IoT Workshop– 13.10.2017

Cost of Arduino class devices

• +Pro: Arduino cost LESS that Raspberry Pi devices

• - You have less resources and services

Page 45: Azure IoT Workshop

Azure IoT Workshop– 13.10.2017

Arduino language

◇Processing (the IDE - https://processing.org/)

◇JavaScript (inspiration of the language and for Processing)

◇C++ (object syntax, usage, not creation)

◇C (raw performance and binary)

Page 46: Azure IoT Workshop

Azure IoT Workshop– 13.10.2017

Arduino and Azure IoT Hub

◇Arduino can speak Http, MQTT and AMQP protocols

◇Porting of Azure IoTHub SDK for C

Page 47: Azure IoT Workshop

Azure IoT Workshop– 13.10.2017

Starting with Arduino

◇https://github.com/arduino/Arduino/

◇https://www.arduino.cc/en/main/software

◇https://azure.microsoft.com/en-us/develop/iot/starter-kits/

◇https://www.adafruit.com/azure

◇https://www.adafruit.com/product/3032

Page 48: Azure IoT Workshop

Azure IoT Workshop– 13.10.2017

Connecting the sensor

10K Ω

P2

+

-

+

-

Page 49: Azure IoT Workshop

Azure IoT Workshop– 13.10.2017

+

-

+

-

Connecting the leds

15

Anode (+

, longer)

56

56

13

Anode (+

, longer)

Page 50: Azure IoT Workshop

Azure IoT Workshop– 13.10.2017

The result

Page 51: Azure IoT Workshop

Azure IoT Workshop– 13.10.2017

Setup software per lo sviluppo in Azure

◇Git

◇Visual Studio Code

◇Python

◇Node.js

◇nom

Page 52: Azure IoT Workshop

Azure IoT Workshop– 13.10.2017

Setup software per Azure

◇Azure CLI 2.0[.19] (https://aka.ms/InstallAzureCliWindows)

◇npm install -g iothub-explorer [1.1.16]

Page 53: Azure IoT Workshop

Azure IoT Workshop– 13.10.2017

Setup software per Arduino

◇Arduino 1.8.x (1.8.5) da arduino.cc

◇CP210x USB to UART Bridge (COMx)https://www.silabs.com/products/development-tools/software/usb-to-uart-bridge-vcp-drivers

Page 54: Azure IoT Workshop

Azure IoT Workshop– 13.10.2017

Setup Azure

◇Dashboard (Azure IoT Workshop)

◇Resource Group (AzureIoTWorkshop)

◇IoT Hub (AzureIoTWorkshop0000xy)

◇Azure Storage (azureiotworkshop00xy) in minuscolo!!!!

◇Function (azureiotworkshop00xy)

Page 55: Azure IoT Workshop

Azure IoT Workshop– 13.10.2017

Set current subscription

◇az login■https://aka.ms/devicelogin

■E incolla il codice

◇az account set --subscription “<subscription name>“

◇az show

Page 56: Azure IoT Workshop

Azure IoT Workshop– 13.10.2017

Create device from command line

◇Az iot hub list

◇az iot device create --hub-name azureiotworkshop00xy --device-id dev1

◇az iot device show-connection-string --hub-name azureiotworkshopproto --device-id dev1

Page 57: Azure IoT Workshop

Azure IoT Workshop– 13.10.2017

Una MCU programmabile Arduino con ESP8266

http://www.instructables.com/id/Programming-ESP8266-ESP-12E-NodeMCU-Using-Arduino-/

https://github.com/esp8266/Arduino/issues/584

Page 58: Azure IoT Workshop

Azure IoT Workshop– 13.10.2017

Resistenze, tanto per ricordarsi

Page 59: Azure IoT Workshop

Azure IoT Workshop– 13.10.2017

Rilevare la temperatura con un DHT 11

◇https://learn.adafruit.com/dht

Page 60: Azure IoT Workshop

Azure IoT Workshop– 13.10.2017

Page 61: Azure IoT Workshop

Azure IoT Workshop– 13.10.2017

IoT Scenario

IoT Hub

(Events and Devices)

Function

(Process)

Function

(Alerts)

Storage

(Storage)

Page 62: Azure IoT Workshop

Azure IoT Workshop– 13.10.2017

Configuring Azure Services

◇Three functional services■Azure Blob Storage

■Azure Function App

■Azure IoT Hub

◇One non functional service■Azure Resource Group

Page 63: Azure IoT Workshop

Azure IoT Workshop– 13.10.2017

Why IoT Hub?

◇Devices registration

◇Notification abstraction from implementation (web sockets/polling)

◇Eterogeneus devices implementation simplified by SDK support

◇Cons■External tool to manage device registration

Page 64: Azure IoT Workshop

Azure IoT Workshop– 13.10.2017

Alternatives to IoT Hub

◇API Apps (App Services)

◇Why not■Manual registry implementation

■Manual two way communication implementation (with web sockets)

■Manual scaling (at large)

Page 65: Azure IoT Workshop

Azure IoT Workshop– 13.10.2017

Why Azure Storage?

◇Persisted data handled as a blob in the storage■No query requirement

◇Native integration with Functions■Trigger

Page 66: Azure IoT Workshop

Azure IoT Workshop– 13.10.2017

Alternatives to Azure Storage

◇DocumentDb for Json support

◇Why yes■Native querying support

◇Why not■Blob support

Page 67: Azure IoT Workshop

Azure IoT Workshop– 13.10.2017

Why Azure Function?

◇Unfrequent access to the function■Subsecond billing

◇Event based solution■Http Request

■Blob storage

◇Better code organization■Simple Responsibility Principle: 1 function, 1 responsibility

Page 68: Azure IoT Workshop

Azure IoT Workshop– 13.10.2017

Alternatives to Azure Function

◇API Apps (App Services)

◇Why yes■Mature patterns on class-based development

■Mature ALM with API Apps (Visual Studio experience)

◇Why not■Classic hosting plan only

■Risk on responsibility coupling (too many responsibilities)

Page 69: Azure IoT Workshop

Azure IoT Workshop– 13.10.2017

Azure Resource Group

◇Mandatory service organization

◇Deployment opportunities■Agile deployment

■Transactional deployment

◇Cons■Not simple to learn (but full of advantages)

Page 70: Azure IoT Workshop

Azure IoT Workshop– 13.10.2017

Page 71: Azure IoT Workshop

Azure IoT Workshop– 13.10.2017

IP capable devices

Devices Data processing and analyticsMonitoring

Control

IT solution backend

Pre

se

nta

tion

an

dbu

sin

ess

co

nn

ectivity

Existing IoTdevices

Low power devices

Generic IoT RequirementsIp

C

ap

ab

leD

evic

es

Le

ga

cy,

Non

Ip

Cap

ab

leD

evic

es

??????

??????

??????

Page 72: Azure IoT Workshop

Azure IoT Workshop– 13.10.2017

IoTHub messaging protocols

Legacy Protocol

Low resource devices

Intermittent connection

Device location

Page 73: Azure IoT Workshop

Azure IoT Workshop– 13.10.2017

IP capable devices

FieldGatewa

y

Device connectivity Data processing and analytics

IT solution backend

Clo

ud

ga

tew

ay

Pre

se

nta

tion

an

dbu

sin

ess

co

nn

ectivity

Existing IoTdevices

Low power devices

Generic IoT Solution

DevicesMonitoring

Control

Page 74: Azure IoT Workshop

Azure IoT Workshop– 13.10.2017

IoT Hub

Device id

What is Azure IoTHub

Device

C2D queue

endpoint

D2C send

endpoint

Device …

Device …

Device…

IoT Hub management

Device identity management

D2C receive endpoint

Methods

endpoint

Twin

endpoint

Twins endpoint

Devices Methods endpoint

Custom endpoints

C2D send and feedback endpoints

Event processing(hot and cold path)

Event processing(hot path)

Device management, device business logic,Connectivity monitoring

Device provisioning and authorization

Field GW /Cloud GW

Page 75: Azure IoT Workshop

Azure IoT Workshop– 13.10.2017

IoT Hub features

Page 76: Azure IoT Workshop

Azure IoT Workshop– 13.10.2017

Page 77: Azure IoT Workshop

Azure IoT Workshop– 13.10.2017

Telemetry

sending, acquiring and measuring

data

Event

State (or state event) Message

Page 78: Azure IoT Workshop

Azure IoT Workshop– 13.10.2017

IoT Hub

Device id

Send/receive data

C2D queue

endpoint

D2C send

endpoint D2C receive endpoint

C2D send and feedback endpoints

Event processing(hot path)

Device

Client SDKs

• C

• Java

• C# (.Net

Standard

1.3)

• Python

Device management, device business logic,Connectivity monitoring

Client SDKs

• .Net

• Node

• Java

• Python

Page 79: Azure IoT Workshop

Azure IoT Workshop– 13.10.2017

Message

Opaque body Application Properties

System Properties

Page 80: Azure IoT Workshop

Azure IoT Workshop– 13.10.2017

IoT Hub Device Management

Device Twin Queries

Methods Jobs

Page 81: Azure IoT Workshop

Azure IoT Workshop– 13.10.2017

Page 82: Azure IoT Workshop

Azure IoT Workshop– 13.10.2017

Structured data

◇Device Twins■Last known state of device

■Desired state configuration

■Group devices

◇Device Direct Methods■Invoke method on device from Cloud

■“Immediate” response

Page 83: Azure IoT Workshop

Azure IoT Workshop– 13.10.2017

Page 84: Azure IoT Workshop

Azure IoT Workshop– 13.10.2017

Page 85: Azure IoT Workshop

Azure IoT Workshop– 13.10.2017

Page 86: Azure IoT Workshop

Azure IoT Workshop– 13.10.2017

Querying Device Twins

FROM WHERE

SELECT GROUP BY

Page 87: Azure IoT Workshop

Azure IoT Workshop– 13.10.2017

Sample queries

◇Devices located in the US configured to send telemetry less often that every minute

◇Devices which have wifi o wired connectivity

◇Devices where reported and desired properties do not match

Page 88: Azure IoT Workshop

Azure IoT Workshop– 13.10.2017

IoT Hub

Structured data

Device

Device management, device business logic,Connectivity monitoring

Device Twin

Properties

Tags

Desired

Reported

Properties

Desired

Reported

Method

Page 89: Azure IoT Workshop

Azure IoT Workshop– 13.10.2017

Page 90: Azure IoT Workshop

Azure IoT Workshop– 13.10.2017

Where does IoT Hub fit in?

Page 91: Azure IoT Workshop

Azure IoT Workshop– 13.10.2017

Functions «lifestyle»

◇Per event handling

◇Stateless processing

◇Binding approach

Page 92: Azure IoT Workshop

Azure IoT Workshop– 13.10.2017

IoTHub’s EventHub compatible endpoint

Namespace

Page 93: Azure IoT Workshop

Azure IoT Workshop– 13.10.2017

IoTHub’s Security Policies

Security Info

SharedAccessKeyName SharedAccessKey

Page 94: Azure IoT Workshop

Azure IoT Workshop– 13.10.2017

EventHub-like connection string

◇Endpoint=<EventHubNamespace>;SharedAccessKeyName=< SharedAccessKeyName>;SharedAccessKey=< SharedAccessKey>■Add EntityPath=<EventHub name> in case of EventHub Security Policy

Page 95: Azure IoT Workshop

Azure IoT Workshop– 13.10.2017

EventHub binding

ConnectionStringEventHub name

Page 96: Azure IoT Workshop

Azure IoT Workshop– 13.10.2017

Page 97: Azure IoT Workshop

Azure IoT Workshop– 13.10.2017

Page 98: Azure IoT Workshop

Azure IoT Workshop– 13.10.2017

Where storing a message

Azure Storage

Azure DocumentDb

Azure EventHub

Azure Queue

Azure Service Bus

Azure SQL Database

Page 99: Azure IoT Workshop

Azure IoT Workshop– 13.10.2017

Then?

◇The message is stored

◇Storage can be the end of the process

◇Or the beginning of the next step■Intermediate processing (a microservices approach)

■Control/Feedback

◇And you process again in the same way:■EventProcessor

■Azure Stream Analytics

■Azure Function

Page 100: Azure IoT Workshop

Azure IoT Workshop– 13.10.2017

Control the devices

◇Cloud-to-device messaging■As needed (twin, message, device method)

◇You need to invoke IoT Hub API■REST APIC# API

■Node.js API

◇Low frequency

◇Function is well suited for this

Page 101: Azure IoT Workshop

Azure IoT Workshop– 13.10.2017

Page 102: Azure IoT Workshop

Azure IoT Workshop– 13.10.2017

What I choose for my devices?

Page 103: Azure IoT Workshop

Azure IoT Workshop– 13.10.2017

Page 104: Azure IoT Workshop

Azure IoT Workshop– 13.10.2017

Generate the symmetric key

DEVICE IOT HUB

C:\>az iot device create –hub-name <hubname> --device-id <deviceId>

Page 105: Azure IoT Workshop

Azure IoT Workshop– 13.10.2017

All devices have different keys

Device Registry

Page 106: Azure IoT Workshop

Azure IoT Workshop– 13.10.2017

Authorization with encryption

Encrypt( , , )=

Page 107: Azure IoT Workshop

Azure IoT Workshop– 13.10.2017

Authenticated communication

◇Token based authentication

DEVICE IOT HUB

(TCP endpoint)

TCP Connection

Page 108: Azure IoT Workshop

Azure IoT Workshop– 13.10.2017

Key invalidation

DEVICE IOT HUB

Page 109: Azure IoT Workshop

Azure IoT Workshop– 13.10.2017

Wrap Up