Internet of Things is not a fad. You may consider it a phenomenon, but nowadays it is a reality that is consolidating day after day. If you think it's not true, maybe it's because in our territory we have not arrived yet. But it would be even now.
In this workshop, you will be able to experiment with the creation of a Cloud in Azure infrastructure to connect devices to gather data, analyze them, and possibly perform actions on the device itself.
In the workshop, we will use sensors and actuators to connect to an Arduino. During the workshop we will understand what it means to use Arduino, Raspberry Pi and then a real device.
We'll make an overview of the Azure services needed to collect data from IoT devices, an introduction to the tools and programming languages that are needed.
Target
The ultimate goal is to bring home a simple but functional solution, so that you can continue to experiment and then understand how the IoT can enter your business.
Contents
• Introduction to the Internet of Things
o What it means device
o What Cloud means
o What it means to connect a device to the cloud
• Azure as Cloud Platform for the Internet of Things
or Azure IoT Hub
or Azure Functions and C #
or Azure SQL Database
or Azure Storage
or Azure App Service
• Arduino as a platform to prototype an IoT device
o ESP8266 microcontroller
o Arduino's development environment
o Connect sensors and actuators
o Write a program
12. 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
13. Azure IoT Workshop– 13.10.2017
Warning! We cannot avoid…
Electronic
engineers
Process
engineers
Industrialization
process
14. Azure IoT Workshop– 13.10.2017
Warning! We are not saying…
Software engineers
can create devices
15. Azure IoT Workshop– 13.10.2017
We are just saying…
Embedded
world is no
more a niche
Software
engineers can
contribute
16. Azure IoT Workshop– 13.10.2017
It is no more a niche
Proprietary
Hardware and
tools
Obsolete tools
No software
rules and
quality
17. Azure IoT Workshop– 13.10.2017
Software engineers can contribute
Methodologies Patterns
(Cloud)
Infrastructure
“Openness” Tools Languages
18. Azure IoT Workshop– 13.10.2017
Tools
Up to date
compilers
Modern IDEs
SDK (Libraries
and Drivers)
Debuggers Simulators
19. Azure IoT Workshop– 13.10.2017
Languages
C
Processin
g
Node.js
Python Java C#
20. 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
22. 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€
24. 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
25. 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
26. 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)
27. 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)
28. Azure IoT Workshop– 13.10.2017
Industria 4.0
http://www.slideshare.net/alexcurti/piano-industria-40-68702177
32. 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
33. Azure IoT Workshop– 13.10.2017
I progetti Embedded IoT sono complessi
•conoscenze
Incompatibile con
la infrastruttura
corrente
•conoscenzeTime consuming da
avviare
•Infrastruttura complessa
•Procedure
Difficile da
mantenere
•Costi
•Infrastruttura complessa
Difficile da
scalare
34. 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)
43. 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
44. 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
45. 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)
46. 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
55. 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
56. 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
57. 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
61. Azure IoT Workshop– 13.10.2017
IoT Scenario
IoT Hub
(Events and Devices)
Function
(Process)
Function
(Alerts)
Storage
(Storage)
62. 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
63. 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
64. 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)
65. 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
66. Azure IoT Workshop– 13.10.2017
Alternatives to Azure Storage
◇DocumentDb for Json support
◇Why yes
■Native querying support
◇Why not
■Blob support
67. 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
68. 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)
69. 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)
73. Azure IoT Workshop– 13.10.2017
IP capable devices
Field
Gatewa
y
Device connectivity Data processing and analytics
IT solution backend
Cloudgateway
Presentationandbusiness
connectivity
Existing IoT
devices
Low power devices
Generic IoT Solution
Devices
Monitoring
Control
74. 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
82. 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
86. Azure IoT Workshop– 13.10.2017
Querying Device Twins
FROM WHERE
SELECT
GROUP
BY
87. 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
98. Azure IoT Workshop– 13.10.2017
Where storing a message
Azure
Storage
Azure
DocumentDb
Azure
EventHub
Azure
Queue
Azure
Service
Bus
Azure SQL
Database
99. 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
100. 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 API
C# API
■Node.js API
◇Low frequency
◇Function is well suited for this