create the internet of your things - programmez.com the internet of your things laurent ellerbach...

66
Create The Internet of Your Things Laurent Ellerbach [email protected] Technical Evangelist Lead Microsoft Central and Eastern Europe http://blogs.msdn.com/laurelle A developer introduction to Microsoft’s approach to the Internet of Things

Upload: doancong

Post on 03-Apr-2018

218 views

Category:

Documents


3 download

TRANSCRIPT

Page 1: Create The Internet of Your Things - programmez.com The Internet of Your Things Laurent Ellerbach ... Pay as you go, scale as you need ... Netduino running .NET Microframework

Create The Internet

of Your Things

Laurent Ellerbach

[email protected]

Technical Evangelist Lead

Microsoft Central and Eastern Europe

http://blogs.msdn.com/laurelle

A developer introduction to Microsoft’s

approach to the Internet of Things

Page 2: Create The Internet of Your Things - programmez.com The Internet of Your Things Laurent Ellerbach ... Pay as you go, scale as you need ... Netduino running .NET Microframework

“ ”

What is the Internet of Things?

The network of physical

objects that contain

embedded technology to

communicate and interact

with their internal states or

the external environment.

Source: Gartner

Page 3: Create The Internet of Your Things - programmez.com The Internet of Your Things Laurent Ellerbach ... Pay as you go, scale as you need ... Netduino running .NET Microframework

Comprehensive IoT platform for developers

InsightsData AnalyticsCloud & Infrastructure

Devices & Assets

10101010011000110101010111010011010101010100110111011110111001010100001101010101110100110101010111010011101010101011010011010101010101001101100010101111010011101010101011011110100111

10101010011000110101010111010011010101010100110111011110111001010100001101010101110100110101010111010011101010101011010011010101010101001101100010101111010011101010101011011110100111

Internet of Your Things Development

Page 4: Create The Internet of Your Things - programmez.com The Internet of Your Things Laurent Ellerbach ... Pay as you go, scale as you need ... Netduino running .NET Microframework

Microsoft IoTComprehensive solutions from device to cloud

IoT Editions Power a Broad Range of Devices

20 years of history in embedded devices

One Windows platform for all devices

Enterprise-ready, Maker-friendly

Designed for today’s IoT environments

Free IoT Core edition!

Cloud-Based IoT Services & Solutions

Easy to provision, use and manage

Pay as you go, scale as you need

Global reach, hyper scale

End-to-end security & privacy

Windows, Mbed, Linux, iOS, Android, RTOS

support

Azure IoT

Page 5: Create The Internet of Your Things - programmez.com The Internet of Your Things Laurent Ellerbach ... Pay as you go, scale as you need ... Netduino running .NET Microframework

Microsoft Azure IoT services

Producers Connect Devices Storage Analytics Take Action

Event Hubs SQL DatabaseMachine

LearningAzure Websites

Service BusTable/Blob

Storage

Stream

AnalyticsPower BI

External Data

SourcesDocumentDB HDInsight

Notification

Hubs

External Data

SourcesData Factory Mobile Services

BizTalk Services

{ }

Producers

Page 6: Create The Internet of Your Things - programmez.com The Internet of Your Things Laurent Ellerbach ... Pay as you go, scale as you need ... Netduino running .NET Microframework

Azure support any kind of devices, Linux and more

Microsoft Azure

Certified for IoT:

http://www.azure.co

m/iotdev tests and

certifies IoT-

enabled platform,

device and

operating system

combinations

Page 7: Create The Internet of Your Things - programmez.com The Internet of Your Things Laurent Ellerbach ... Pay as you go, scale as you need ... Netduino running .NET Microframework

A concrete example: my house

Page 8: Create The Internet of Your Things - programmez.com The Internet of Your Things Laurent Ellerbach ... Pay as you go, scale as you need ... Netduino running .NET Microframework

What I haveFew indoor/outdoor

temperature and humidity

Oregon Scientific sensors

Few ATmega328

(used in Arduino

boards)

Few Netduino using

.NET Microframework

Water arrivals in the

garden A great cloud

infrastructure, database,

website and more!

The best developer tools in

the world

Page 9: Create The Internet of Your Things - programmez.com The Internet of Your Things Laurent Ellerbach ... Pay as you go, scale as you need ... Netduino running .NET Microframework

Example IoT solution

Page 10: Create The Internet of Your Things - programmez.com The Internet of Your Things Laurent Ellerbach ... Pay as you go, scale as you need ... Netduino running .NET Microframework

Overall architecture of what I’ve build – v1 (Jun 2014)

433MHz

receiver

Spark.io

433MHz

emitter

ATmega328

sensors

SQL

Azure

Azure

Mobile

Services

HTTP REST

Azure Web

site (Web

App)

ASP.NET +

MVC +

Entity

Framework

+ jqueryBrowser

sprinkler

Netduino running .NET Microframework

HTTP Gateway

Page 11: Create The Internet of Your Things - programmez.com The Internet of Your Things Laurent Ellerbach ... Pay as you go, scale as you need ... Netduino running .NET Microframework

Overall architecture – v2 (in progress)

433MHz

receiver

ATmega328

sensors

SQL

Azure

Azure

Event

Hub +

Stream

Analytics Web App

+

Javascript

Browser

sprinkler

Netduino running .NET Microframework

Gateway

App

IaC – Azure Resource Manager json

deployment

Recommen-

dation

workflow

Automation and

Machine Learning

APIs

HTTPS REST

HTTP REST

Page 12: Create The Internet of Your Things - programmez.com The Internet of Your Things Laurent Ellerbach ... Pay as you go, scale as you need ... Netduino running .NET Microframework

Existing sensors New sensors

433MHz receiver

Spark.io

433MHz emitter

ATmega328

433MHz emitter

ATmega328

Rain, wind speed and direction

Soil humidity, temperature, air

humidity, luminosity

Azure Mobile Services

SQL Azure

Sensors architecture – v1

Gateway

Page 13: Create The Internet of Your Things - programmez.com The Internet of Your Things Laurent Ellerbach ... Pay as you go, scale as you need ... Netduino running .NET Microframework

Creating my own wind and rain sensor - v1

600

1µF

antena

DTS

Pull up internes

Page 14: Create The Internet of Your Things - programmez.com The Internet of Your Things Laurent Ellerbach ... Pay as you go, scale as you need ... Netduino running .NET Microframework

Prototype - v1

Page 15: Create The Internet of Your Things - programmez.com The Internet of Your Things Laurent Ellerbach ... Pay as you go, scale as you need ... Netduino running .NET Microframework

Beta version - v1

Page 16: Create The Internet of Your Things - programmez.com The Internet of Your Things Laurent Ellerbach ... Pay as you go, scale as you need ... Netduino running .NET Microframework

Tools for Arduino development

+• Visual Micro is free for

basic usage

• Great integration with

Visual Studio, support

projects type, template,

libraries

• Debugging thru serial and

USB

• Support bootloader flash

and more!

Page 17: Create The Internet of Your Things - programmez.com The Internet of Your Things Laurent Ellerbach ... Pay as you go, scale as you need ... Netduino running .NET Microframework

Prototype for decoding and posting to Azure mobile services - v1

Page 18: Create The Internet of Your Things - programmez.com The Internet of Your Things Laurent Ellerbach ... Pay as you go, scale as you need ... Netduino running .NET Microframework

New challenge: a greenhouse to manage!

Page 19: Create The Internet of Your Things - programmez.com The Internet of Your Things Laurent Ellerbach ... Pay as you go, scale as you need ... Netduino running .NET Microframework

Prototype - v2

Page 20: Create The Internet of Your Things - programmez.com The Internet of Your Things Laurent Ellerbach ... Pay as you go, scale as you need ... Netduino running .NET Microframework

v2

Page 21: Create The Internet of Your Things - programmez.com The Internet of Your Things Laurent Ellerbach ... Pay as you go, scale as you need ... Netduino running .NET Microframework

What to do with the generated data?

101010100110001101010101110100110101010101001101011101001110101010101101001101010101010100

Page 22: Create The Internet of Your Things - programmez.com The Internet of Your Things Laurent Ellerbach ... Pay as you go, scale as you need ... Netduino running .NET Microframework

Let insert a record in a table!

POST /tables/nomdelatable/ HTTP/1.1

X-ZUMO-APPLICATION: 123456789abcdef123456789abcdef12

Host: nomduservice.azure-mobile.net

Content-Length: 88

Connection: close

{"sensorID":22, "channel":5,

"instSpeed":12,"averSpeed":5,"direction":2,"batterylife

":90}

HTTP/1.1 201 Created

Cache-Control: no-cache

Content-Length: 133

Content-Type: application/json

Location: https://nomduservice.azure-

mobile.net/tables/weather//931CFDDE-AB7F-

4480-BA28-F1D5C611398B

Server: Microsoft-IIS/8.0

x-zumo-version:

Zumo.master.0.1.6.3803.Runtime

X-Powered-By: ASP.NET

Set-Cookie:

ARRAffinity=da4a9f7437a690e3c1a799d3a6c3ddf3e

e0cbb9f5a67008d3c919f0149f34ee3;Path=/;Domain

= nomduservice.azure-mobile.net

Date: Sun, 31 Aug 2014 15:40:12 GMT

Connection: close

{"sensorID":22,"channel":5,"instSpeed":12,"av

erSpeed":5,"direction":2,"batterylife":90,"id

":"931CFDDE-AB7F-4480-BA28-F1D5C611398B"}

Sent using POST on socket port 80

Received from the server

Page 23: Create The Internet of Your Things - programmez.com The Internet of Your Things Laurent Ellerbach ... Pay as you go, scale as you need ... Netduino running .NET Microframework

Arduino code to post in Azure Mobile Servicesyes, it’s that simple!

TCPClient client;

byte AzureServer[] = { 12, 34, 56, 78 };

String writeJsonWind(struct wind wd) {

// Create a simple JSON;

String datastring = "{\"sensorID\":";

datastring += String(wd.ID);

datastring += ",\"channel\":";

datastring += String(wd.channel);

datastring += ",\"instSpeed\":";

datastring += String(wd.instantSpeed);

datastring += ",\"averSpeed\":";

datastring += String(wd.averageSpeed);

datastring += ",\"direction\":";

datastring += String(wd.direction);

datastring += ",\"batterylife\":";

datastring += String(wd.bat);

datastring += "}";

return (datastring);

}

// Sending data is simple, create a JSON, and send it on port 80!

String dataString = writeJsonWind(myWind);

sendData(dataString);

void sendData(String thisData) {

// create a connection to port 80 on the server

// IP is your Mobile Services address

if (client.connect(AzureServer, 80))

{

//Serial.println("Connected to Azure Server");

// create the REST request using POST

// Nomdelatable is name of the table

client.print("POST /tables/nomdelatable/");

client.println(" HTTP/1.1");

// use the application key

client.println("X-ZUMO-APPLICATION:

123456789abcdef123456789abcdef12");

// host name is name of your Azure Mobile Service

client.println("Host: nomdumobileservice.azure-

mobile.net");

client.print("Content-Length: ");

client.println(thisData.length());

client.println("Connection: close");

client.println();

// and finally data!

client.println(thisData);

}

else { // in case of error, stop connection

client.stop();

} }

Page 24: Create The Internet of Your Things - programmez.com The Internet of Your Things Laurent Ellerbach ... Pay as you go, scale as you need ... Netduino running .NET Microframework

What about security?

Page 25: Create The Internet of Your Things - programmez.com The Internet of Your Things Laurent Ellerbach ... Pay as you go, scale as you need ... Netduino running .NET Microframework

Using Azure Event Hubs - v2

http://azure.microsoft.com/en-us/services/event-hubs/

Page 26: Create The Internet of Your Things - programmez.com The Internet of Your Things Laurent Ellerbach ... Pay as you go, scale as you need ... Netduino running .NET Microframework

New: Azure IoT Hub

Page 27: Create The Internet of Your Things - programmez.com The Internet of Your Things Laurent Ellerbach ... Pay as you go, scale as you need ... Netduino running .NET Microframework

V2: RPI upgraded to v2

Page 28: Create The Internet of Your Things - programmez.com The Internet of Your Things Laurent Ellerbach ... Pay as you go, scale as you need ... Netduino running .NET Microframework

RPI taking picture from greenhouse to Azure

Azure IoT Hub

• Device need to be

registered

• Node.js running on

RPI

• Azure IoT SDK

available on Github:

https://github.com/Az

ure/azure-iot-sdks

• C, C#, Java, node.js

• Azure IoT Hub can

receive data as well

from devices

• Manage devices key,

allow access…Sending message

HTTPSmessage

Sending

message

HTTPS

1. Node.js app

processing the

message

2. taking picture

3. Uploading into Azure

blob

4. Sending acknowledge

Can send as

well data

stora

ge

Event

hub…

SQL Azure

Blob storage

Page 29: Create The Internet of Your Things - programmez.com The Internet of Your Things Laurent Ellerbach ... Pay as you go, scale as you need ... Netduino running .NET Microframework

Inside the greenhouse

https://portalvhdskb2vtjmyg3mg.blob.core.windows.net/webcam/picture

Code available on https://github.com/Ellerbach/nodejs-webcam-azure-iot

Page 30: Create The Internet of Your Things - programmez.com The Internet of Your Things Laurent Ellerbach ... Pay as you go, scale as you need ... Netduino running .NET Microframework

What to do with the data?

101010100110001101010101110100110101010101001101110111101110010101000011010101011101001110101010101101001101010101010100110110001010111101001110101010

Page 31: Create The Internet of Your Things - programmez.com The Internet of Your Things Laurent Ellerbach ... Pay as you go, scale as you need ... Netduino running .NET Microframework

Overall architecture of what I’ve build – v1

433MHz

receiver

Spark.io

433MHz

emitter

ATmega328

sensors

SQL

Azure

Azure

Mobile

Services

HTTP REST

Azure Web

site (Web

App)

ASP.NET +

MVC +

Entity

Framework

+ jqueryBrowser

sprinkler

Netduino running .NET Microframework

HTTP Gateway

Page 32: Create The Internet of Your Things - programmez.com The Internet of Your Things Laurent Ellerbach ... Pay as you go, scale as you need ... Netduino running .NET Microframework

Overall architecture – v2 (in progress)

433MHz

receiver

ATmega328

sensors

SQL

Azure

Azure

Event

Hub +

Stream

Analytics Web App

+

Javascript

Browser

sprinkler

Netduino running .NET Microframework

Gateway

App

IaC – Azure Resource Manager json

deployment

Recommen-

dation

workflow

Automation and

Machine Learning

APIs

Page 33: Create The Internet of Your Things - programmez.com The Internet of Your Things Laurent Ellerbach ... Pay as you go, scale as you need ... Netduino running .NET Microframework

Accessing data thru Excel

Page 34: Create The Internet of Your Things - programmez.com The Internet of Your Things Laurent Ellerbach ... Pay as you go, scale as you need ... Netduino running .NET Microframework

Website v1: http://arrosage.azurewebsites.net/

Page 35: Create The Internet of Your Things - programmez.com The Internet of Your Things Laurent Ellerbach ... Pay as you go, scale as you need ... Netduino running .NET Microframework

Displaying graphs

Page 36: Create The Internet of Your Things - programmez.com The Internet of Your Things Laurent Ellerbach ... Pay as you go, scale as you need ... Netduino running .NET Microframework

What about security?

Access denied if not authenticated as administrators

Page 37: Create The Internet of Your Things - programmez.com The Internet of Your Things Laurent Ellerbach ... Pay as you go, scale as you need ... Netduino running .NET Microframework

• Intake millions of events per

second

• Easy processing on continuous

streams of data

• Correlate streaming with reference

data

• Guaranteed events delivery

• Elasticity of the cloud for scale up

or scale down

• Low startup costs

Page 38: Create The Internet of Your Things - programmez.com The Internet of Your Things Laurent Ellerbach ... Pay as you go, scale as you need ... Netduino running .NET Microframework

Using Stream Analytics

WITH mydata as (

SELECT

CAST(WindSpeed as bigint) as speed,

CAST(WindSpeedAverage as float) as average,

CAST(WindDirection as bigint) as direction,

CAST(SensorID as bigint) as sensorID,

CAST(Temperature as float) as temperature,

CAST(Humidity as float) as humidity,

CAST(Luminosity as bigint) as liminosite,

CAST(SoilHumidity as bigint) as soilhumid

FROM arrosageinput)

SELECT speed, average, direction, sensorID

INTO

arrosagewind

FROM mydata

SELECT temperature, humidity, liminosite,

soilhumid, sensorID

INTO

arrosagehum

FROM mydata

Page 39: Create The Internet of Your Things - programmez.com The Internet of Your Things Laurent Ellerbach ... Pay as you go, scale as you need ... Netduino running .NET Microframework

Website for v2

Page 40: Create The Internet of Your Things - programmez.com The Internet of Your Things Laurent Ellerbach ... Pay as you go, scale as you need ... Netduino running .NET Microframework

Why API in v2?using System.Net;using System.Net.Http;using System.Web;using System.Web.Http;using Newtonsoft.Json;using System.IO;using System.Text;

namespace WeatherAPI.Controllers{

public class WeatherController : ApiController{

// GET api/weatherpublic ForecastData GetForecast(String location){

//Building parameterString baseURL = "https://query.yahooapis.com/v1/public/yql";String yqlQuery = "select * from weather.forecast where woeid in (select woeid from

geo.places(1) where text='" + location + "')";String format = "json";String requestURL = baseURL + "?q=" + HttpUtility.UrlEncode(yqlQuery) + "&format=" + format;

//Creating WebRequest and getting the responseHttpWebRequest request = (HttpWebRequest)WebRequest.Create(requestURL);HttpWebResponse response = (HttpWebResponse)request.GetResponse();

//Response stream to stringString responseString;using (Stream stream = response.GetResponseStream()){

StreamReader reader = new StreamReader(stream, Encoding.UTF8);responseString = reader.ReadToEnd();

}

//Deserialize response to objectForecastData forecastData = JsonConvert.DeserializeObject<ForecastData>(responseString);

return forecastData;}

}}

xhr.open("GET", "https://microsoft-apiappccd711277be14956b169a7c59837294a.azurewebsites.net:443/api/Recommandation", true);

Page 41: Create The Internet of Your Things - programmez.com The Internet of Your Things Laurent Ellerbach ... Pay as you go, scale as you need ... Netduino running .NET Microframework

What to do with the analytics?

10101010011000110101010111010011010101010100110111011110111001010100001101010101110100110101010111010011101010101011010011010101010101001101100010101111010011101010101011011110100111

10101010011000110101010111010011010101010100110111011110111001010100001101010101110100110101010111010011101010101011010011010101010101001101100010101111010011101010101011011110100111

Page 42: Create The Internet of Your Things - programmez.com The Internet of Your Things Laurent Ellerbach ... Pay as you go, scale as you need ... Netduino running .NET Microframework

Machine learning

Page 43: Create The Internet of Your Things - programmez.com The Internet of Your Things Laurent Ellerbach ... Pay as you go, scale as you need ... Netduino running .NET Microframework

A bit of Machine Learning – v2

Test + code +

documentation auto

generated

Simple model

to predict if

necessary to

sprinkle

Page 44: Create The Internet of Your Things - programmez.com The Internet of Your Things Laurent Ellerbach ... Pay as you go, scale as you need ... Netduino running .NET Microframework

Microsoft Power BI

Page 45: Create The Internet of Your Things - programmez.com The Internet of Your Things Laurent Ellerbach ... Pay as you go, scale as you need ... Netduino running .NET Microframework

What about a bot?

https://dev.botframework.com/

Page 46: Create The Internet of Your Things - programmez.com The Internet of Your Things Laurent Ellerbach ... Pay as you go, scale as you need ... Netduino running .NET Microframework

The bot architecture: example with email

Raspberry PI running

Linux and node.js

Azure IoT Hub

Message

(picture)

SQL Azure

Blob storage

Web App, Bot framework

Bot providers

Page 47: Create The Internet of Your Things - programmez.com The Internet of Your Things Laurent Ellerbach ... Pay as you go, scale as you need ... Netduino running .NET Microframework

Bot framework: example of Skype integration

Page 48: Create The Internet of Your Things - programmez.com The Internet of Your Things Laurent Ellerbach ... Pay as you go, scale as you need ... Netduino running .NET Microframework

Deployment? A bit of DevOps in v2

Page 49: Create The Internet of Your Things - programmez.com The Internet of Your Things Laurent Ellerbach ... Pay as you go, scale as you need ... Netduino running .NET Microframework

Exposing an API with humidity information

Page 50: Create The Internet of Your Things - programmez.com The Internet of Your Things Laurent Ellerbach ... Pay as you go, scale as you need ... Netduino running .NET Microframework

The sprinkler board

Page 51: Create The Internet of Your Things - programmez.com The Internet of Your Things Laurent Ellerbach ... Pay as you go, scale as you need ... Netduino running .NET Microframework

The Sprinkler board v2

Page 52: Create The Internet of Your Things - programmez.com The Internet of Your Things Laurent Ellerbach ... Pay as you go, scale as you need ... Netduino running .NET Microframework

What is in the garden

+ +

Page 53: Create The Internet of Your Things - programmez.com The Internet of Your Things Laurent Ellerbach ... Pay as you go, scale as you need ... Netduino running .NET Microframework

The sprinkler architecture

Netduino

http

1 Page to manage programming

1 to manage sprinkler opening

and closing

Simple browser as a client

2 Pages to manage calendar and

programming

Timer to launch psrinkler and automated mode

• Used in production for all summer

• Fully REST API based

• Can be accessed by apps, simple key

security

• Fully customizable with settings in SD card

Page 54: Create The Internet of Your Things - programmez.com The Internet of Your Things Laurent Ellerbach ... Pay as you go, scale as you need ... Netduino running .NET Microframework

Programming sprinkler

Page 55: Create The Internet of Your Things - programmez.com The Internet of Your Things Laurent Ellerbach ... Pay as you go, scale as you need ... Netduino running .NET Microframework

How does it looks like on the device

Page 56: Create The Internet of Your Things - programmez.com The Internet of Your Things Laurent Ellerbach ... Pay as you go, scale as you need ... Netduino running .NET Microframework

Does it really work?

Page 57: Create The Internet of Your Things - programmez.com The Internet of Your Things Laurent Ellerbach ... Pay as you go, scale as you need ... Netduino running .NET Microframework

My next steps with this project

Page 58: Create The Internet of Your Things - programmez.com The Internet of Your Things Laurent Ellerbach ... Pay as you go, scale as you need ... Netduino running .NET Microframework

One last thing…

Page 59: Create The Internet of Your Things - programmez.com The Internet of Your Things Laurent Ellerbach ... Pay as you go, scale as you need ... Netduino running .NET Microframework

Internet of Wine (IoW)

Page 60: Create The Internet of Your Things - programmez.com The Internet of Your Things Laurent Ellerbach ... Pay as you go, scale as you need ... Netduino running .NET Microframework

Before

Page 61: Create The Internet of Your Things - programmez.com The Internet of Your Things Laurent Ellerbach ... Pay as you go, scale as you need ... Netduino running .NET Microframework

After

Page 62: Create The Internet of Your Things - programmez.com The Internet of Your Things Laurent Ellerbach ... Pay as you go, scale as you need ... Netduino running .NET Microframework

How does it work?

Page 63: Create The Internet of Your Things - programmez.com The Internet of Your Things Laurent Ellerbach ... Pay as you go, scale as you need ... Netduino running .NET Microframework

0

1

2

3

4

5

6

30/12/2014 30/01/2015 28/02/2015 31/03/2015 30/04/2015 31/05/2015 30/06/2015 31/07/2015 31/08/2015 30/09/2015 31/10/2015 30/11/2015 31/12/2015 31/01/2016 29/02/2016

Some BI, 2014/12/30->2016/03/13 = 263 bottles210 bottles in 2015

Page 64: Create The Internet of Your Things - programmez.com The Internet of Your Things Laurent Ellerbach ... Pay as you go, scale as you need ... Netduino running .NET Microframework

Comprehensive IoT platform for developers

InsightsData AnalyticsCloud & Infrastructure

Devices & Assets

10101010011000110101010111010011010101010100110111011110111001010100001101010101110100110101010111010011101010101011010011010101010101001101100010101111010011101010101011011110100111

10101010011000110101010111010011010101010100110111011110111001010100001101010101110100110101010111010011101010101011010011010101010101001101100010101111010011101010101011011110100111

Internet of Your Things Development

Page 65: Create The Internet of Your Things - programmez.com The Internet of Your Things Laurent Ellerbach ... Pay as you go, scale as you need ... Netduino running .NET Microframework

http://blogs.msdn.com/laurelle

http://github.com/ellerbach

http://www.windowsondevices.com

http://azure.microsoft.com

Page 66: Create The Internet of Your Things - programmez.com The Internet of Your Things Laurent Ellerbach ... Pay as you go, scale as you need ... Netduino running .NET Microframework

www.InternetofYourThings.com