create the internet of your things example of a real system - laurent ellerbach

68
@ITCAMPRO #ITCAMP16 Community Conference for IT Professionals Many thanks to our sponsors & partners! GOLD SILVER PARTNERS PLATINUM POWERED BY

Upload: itcamp

Post on 07-Jan-2017

875 views

Category:

Technology


0 download

TRANSCRIPT

@ITCAMPRO #ITCAMP16Community Conference for IT Professionals

Many thanks to our sponsors & partners!

GOLD

SILVER

PARTNERS

PLATINUM

POWERED BY

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

“ ”

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

Comprehensive IoT platform for developers

InsightsData AnalyticsCloud & Infrastructure

Devices & Assets

10101010011000110101010111010011010101010100110111011110111001010100001101010101110100110101010111010011101010101011010011010101010101001101100010101111010011101010101011011110100111

10101010011000110101010111010011010101010100110111011110111001010100001101010101110100110101010111010011101010101011010011010101010101001101100010101111010011101010101011011110100111

Internet of Your Things Development

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

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

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

A concrete example: my house

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

Example IoT solution

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

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

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

Creating my own wind and rain sensor - v1

600

1µF

antena

DTS

Pull up internes

Prototype - v1

Beta version - v1

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!

Prototype for decoding and posting to Azure mobile services - v1

New challenge: a greenhouse to manage!

Prototype - v2

v2

What to do with the generated data?

101010100110001101010101110100110101010101001101011101001110101010101101001101010101010100

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

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();

} }

What about security?

Using Azure Event Hubs - v2

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

New: Azure IoT Hub

V2: RPI upgraded to v2

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

Inside the greenhouse

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

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

What to do with the data?

101010100110001101010101110100110101010101001101110111101110010101000011010101011101001110101010101101001101010101010100110110001010111101001110101010

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

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

Accessing data thru Excel

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

Displaying graphs

What about security?

Access denied if not authenticated as administrators

• 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

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

Website for v2

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);

What to do with the analytics?

10101010011000110101010111010011010101010100110111011110111001010100001101010101110100110101010111010011101010101011010011010101010101001101100010101111010011101010101011011110100111

10101010011000110101010111010011010101010100110111011110111001010100001101010101110100110101010111010011101010101011010011010101010101001101100010101111010011101010101011011110100111

Machine learning

A bit of Machine Learning – v2

Test + code +

documentation auto

generated

Simple model

to predict if

necessary to

sprinkle

Microsoft Power BI

What about a bot?

https://dev.botframework.com/

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

Bot framework: example of Skype integration

Deployment? A bit of DevOps in v2

Exposing an API with humidity information

The sprinkler board

The Sprinkler board v2

What is in the garden

+ +

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

Programming sprinkler

How does it looks like on the device

Does it really work?

My next steps with this project

One last thing…

Internet of Wine (IoW)

Before

After

How does it work?

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

Comprehensive IoT platform for developers

InsightsData AnalyticsCloud & Infrastructure

Devices & Assets

10101010011000110101010111010011010101010100110111011110111001010100001101010101110100110101010111010011101010101011010011010101010101001101100010101111010011101010101011011110100111

10101010011000110101010111010011010101010100110111011110111001010100001101010101110100110101010111010011101010101011010011010101010101001101100010101111010011101010101011011110100111

Internet of Your Things Development

http://blogs.msdn.com/laurelle

http://github.com/ellerbach

http://www.windowsondevices.com

http://azure.microsoft.com

@ITCAMPRO #ITCAMP16Community Conference for IT Professionals

Q & A

www.InternetofYourThings.com