getting started with aws iot, devices & sdks

40
AWS Pop-up Loft London Getting Started with AWS IoT, Devices & SDKs Danilo Poccia, Technical Evangelist @danilop danilop

Upload: amazon-web-services

Post on 16-Apr-2017

1.326 views

Category:

Technology


2 download

TRANSCRIPT

Page 1: Getting Started with AWS IoT, Devices & SDKs

AWS Pop-up Loft LondonGetting Started with AWS IoT, Devices & SDKs

Danilo Poccia, Technical Evangelist @danilop danilop

Page 2: Getting Started with AWS IoT, Devices & SDKs

AWS IoT

Page 3: Getting Started with AWS IoT, Devices & SDKs

Authentication & Authorization

AWS Auth+

HTTPS

MQTT+

Mutual Auth TLS

WebSockets wss://…

Page 4: Getting Started with AWS IoT, Devices & SDKs

Registry

Hardware RevisionFirmware VersionSerial Numbers

Device TypeDevice Group

Device DescriptionLink to ProductDocumentation

. . .

Page 5: Getting Started with AWS IoT, Devices & SDKs

Device Gateway

Millions of devices and apps can connect over

MQTT,WebSockets,and HTTP 1.1

PowerfulPub/Sub Broker with Long-livedbi-directional

messages

Page 6: Getting Started with AWS IoT, Devices & SDKs

Rules EngineSELECT * FROM ‘things/thing-2/color’ WHERE color = ‘red’

Simple & Familiar Syntax

SQL Statement to define topic filter

with JSON supportFunctions improve

signal : noise

Page 7: Getting Started with AWS IoT, Devices & SDKs

Device Shadow

Intermitted Connections

PersistentDevice State

(JSON)Desired Vs Reported

=> Delta

RESTful API

Shadow

Page 8: Getting Started with AWS IoT, Devices & SDKs

AWS IoT Device SDK

C-SDK

JS-SDK

Arduino Yún

Mobile SDK Android

iOS

Page 9: Getting Started with AWS IoT, Devices & SDKs

MQTT

Page 10: Getting Started with AWS IoT, Devices & SDKs

MQTT TopicDevice A“Sensor”

Device B“Control Center”

(1) Subscribe

(3) Message

(2) Publish

MQTT Topic = topic level / topic level / … ↓

“myapp/customer123/house4/kitchen/temperature”

Page 11: Getting Started with AWS IoT, Devices & SDKs

Wildcards

‘+’ single level ‘#’ multi level

“myapp/customer123/house4/+/temperature”“myapp/customer123/+/kitchen/temperature”

“myapp/customer123/house4/#”“myapp/customer123/#”

$topics are not subscribed by “#’”

Page 12: Getting Started with AWS IoT, Devices & SDKs

Device Shadows

Page 13: Getting Started with AWS IoT, Devices & SDKs

Device Shadows RESTful API

https://endpoint/things/thingName/shadow

endpoint = identifier.iot.region.amazonaws.com

HTTP GET → GetThingShadow

HTTP POST → UpdateThingShadow

HTTP DELETE → DeleteThingShadow

Page 14: Getting Started with AWS IoT, Devices & SDKs

MQTT topics The Thing Shadows service sends messages to this topic when

$aws/things/myLightBulb/shadow/update/accepted an update is successfully made to a thing shadow

$aws/things/myLightBulb/shadow/update/rejected an update to a thing shadow is rejected

$aws/things/myLightBulb/shadow/update/delta a difference is detected between the reported and desired sections of a thing shadow

$aws/things/myLightBulb/shadow/get/accepted a request for a thing shadow is made successfully

$aws/things/myLightBulb/shadow/get/rejected a request for a thing shadow is rejected

Page 15: Getting Started with AWS IoT, Devices & SDKs

Lightbulb Thing ShadowsService

Application

Page 16: Getting Started with AWS IoT, Devices & SDKs

Lightbulb Thing ShadowsService

$aws/things/myLightbulb/shadow/update

{ "state": { "reported": { "color": "red" } }}

Application

Page 17: Getting Started with AWS IoT, Devices & SDKs

Lightbulb Thing ShadowsService

$aws/things/myLightBulb/shadow/update/accepted

{ "state":{ "reported":{ "color":"red" } }, "metadata":{ "reported":{ "color":{ "timestamp":1447437304 } } }, "version":1, "timestamp":1447437304 }

Application

Page 18: Getting Started with AWS IoT, Devices & SDKs

Lightbulb Thing ShadowsService

$aws/things/myLightBulb/shadow/get

“”(empty message)

Could be a RESTful call to GetThingShadow

Application

Page 19: Getting Started with AWS IoT, Devices & SDKs

Lightbulb Thing ShadowsService

$aws/things/myLightBulb/shadow/get/accepted

{ "state":{ "reported":{ "color":"red" } }, "metadata":{ "reported":{ "color":{ "timestamp":1447437304 } } }, "version":1, "timestamp":1447437398 }

Application

Page 20: Getting Started with AWS IoT, Devices & SDKs

Lightbulb Thing ShadowsService

$aws/things/myLightBulb/shadow/update

{ "state": { "desired": { "color": "green" } }}

Could be a RESTful call to UpdateThingShadow

Application

Page 21: Getting Started with AWS IoT, Devices & SDKs

Lightbulb Thing ShadowsService

$aws/things/myLightBulb/shadow/update/accepted

{ "state":{ "desired":{ "color":"green" } }, "metadata":{ "desired":{ "color":{ "timestamp":1447437647 } } }, "version":2, "timestamp":1447437647 }

Application

Page 22: Getting Started with AWS IoT, Devices & SDKs

Lightbulb Thing ShadowsService

$aws/things/myLightBulb/shadow/update/delta

{ "version":2, "timestamp":1447437647, "state":{ "color":"green" }, "metadata":{ "color":{ "timestamp":1447437647 } }}

Application

Page 23: Getting Started with AWS IoT, Devices & SDKs

Lightbulb Thing ShadowsService

$aws/things/myLightbulb/shadow/update

{ "state":{ "reported":{ "color":"green" }, "desired":null} }}

Application

Page 24: Getting Started with AWS IoT, Devices & SDKs

Lightbulb Thing ShadowsService

$aws/things/myLightBulb/shadow/update/accepted

{ "state":{ "reported":{ "color":"green" } }, "metadata":{ "reported":{ "color":{ "timestamp":1447437894 } } }, "version":3, “timestamp":1447437894}

Application

Page 25: Getting Started with AWS IoT, Devices & SDKs

{ "state" : { "desired" : { "color" : "RED", "sequence" : [ "RED", "GREEN", "BLUE" ] }, "reported" : { "color" : "GREEN" } }, "metadata" : { "desired" : { "color" : { "timestamp" : 12345 }, "sequence" : { "timestamp" : 12345 } }, "reported" : { "color" : { "timestamp" : 12345 } } }, "version" : 10, "clientToken" : "UniqueClientToken", "timestamp": 123456789}

Sample Thing Shadow

Document

Page 26: Getting Started with AWS IoT, Devices & SDKs

Optimistic Locking

Initial State

Update

Result

Page 27: Getting Started with AWS IoT, Devices & SDKs

{ "state" : { "desired" : { "colors" : ["RED", "GREEN", "BLUE" ] } }, "version" : 10}

Optimistic Locking

Initial State

Update

Result

Page 28: Getting Started with AWS IoT, Devices & SDKs

{ "state" : { "desired" : { "colors" : ["RED", "GREEN", "BLUE" ] } }, "version" : 10}

{ "state": { "desired": { "colors": [ "BLUE" ] } }, "version": 9}

Optimistic Locking

Initial State

Update

Result

Page 29: Getting Started with AWS IoT, Devices & SDKs

{ "state" : { "desired" : { "colors" : ["RED", "GREEN", "BLUE" ] } }, "version" : 10}

{ "state": { "desired": { "colors": [ "BLUE" ] } }, "version": 9}

409 Conflict

Optimistic Locking

Initial State

Update

Result

Page 30: Getting Started with AWS IoT, Devices & SDKs

{ "state" : { "desired" : { "colors" : ["RED", "GREEN", "BLUE" ] } }, "version" : 10}

{ "state": { "desired": { "colors": [ "BLUE" ] } }, "version": 10}

Optimistic Locking

Initial State

Update

Result

Page 31: Getting Started with AWS IoT, Devices & SDKs

{ "state" : { "desired" : { "colors" : ["RED", "GREEN", "BLUE" ] } }, "version" : 10}

{ "state": { "desired": { "colors": [ "BLUE" ] } }, "version": 10}

{ "state": { "desired": { "colors": [ "BLUE" ] } }, "version": 11}

Optimistic Locking

Initial State

Update

Result

Page 32: Getting Started with AWS IoT, Devices & SDKs

MQTT Connection

Create and maintain a mutually authenticatedTLS connection over which it runs MQTT

Subscribing to MQTT topics + callback function

Thing Shadow

Retrieve, update and delete Thing Shadows Abstracts the necessary MQTT topic subscriptions by automatically subscribing to and unsubscribing

from the reserved topics as neededInbound state change requests are automatically signalled

via a configurable callback

Device SDKs

Page 33: Getting Started with AWS IoT, Devices & SDKs

Connecting to the AWS IoT MQTT platform

rc = aws_iot_mqtt_connect( &connectParams );

Subscribe to a topic

MQTTSubscribeParams subParams = MQTTSubscribeParamsDefault; subParams.mHandler = MQTTcallbackHandler;subParams.qos = QOS_0;subParams.pTopic = "sdkTest/sub";rc = aws_iot_mqtt_subscribe( &subParams );

Update Thing Shadow from a device

rc = aws_iot_shadow_update(&mqttClient, AWS_IOT_MY_THING_NAME, pJsonDocumentBuffer, ShadowUpdateStatusCallback, pCallbackContext, TIMEOUT_4SEC, persistenSubscription);

C SDK

Page 34: Getting Started with AWS IoT, Devices & SDKs

var awsIot = require(‘aws-iot-device-sdk');

var device = awsIot.device({ keyPath: <YourPrivateKeyPath>, certPath: <YourCertificatePath>, caPath: <YourRootCACertificatePath>, clientId: <YourUniqueClientIdentifier>, region: <YourAWSRegion> });

device .on('connect', function() { console.log('connect'); device.subscribe('topic_1'); device.publish('topic_2', JSON.stringify({ test_data: 1})); });

device .on('message', function(topic, payload) { console.log('message', topic, payload.toString()); });

JS SDK

Device Class

Page 35: Getting Started with AWS IoT, Devices & SDKs

var thingShadows = awsIot.thingShadow({ keyPath: <YourPrivateKeyPath>, certPath: <YourCertificatePath>, caPath: <YourRootCACertificatePath>, clientId: <YourUniqueClientIdentifier>, region: <YourAWSRegion>});

thingShadows.on('connect', function() { thingShadows.register( 'RGBLedLamp' ); setTimeout( function() { var rgbLedLampState = {"state":{"desired":{"red":rval,"green":gval,"blue":bval}}}; clientTokenUpdate = thingShadows.update('RGBLedLamp', rgbLedLampState ); if (clientTokenUpdate === null) { console.log('update shadow failed, operation still in progress'); } }, 5000 ); });

JS SDK

Thing Shadow

Class

Page 36: Getting Started with AWS IoT, Devices & SDKs

thingShadows.on('status', function(thingName, stat, clientToken, stateObject) { console.log('received '+stat+' on '+thingName+': '+ JSON.stringify(stateObject)); });

thingShadows.on('delta', function(thingName, stateObject) { console.log('received delta on '+thingName+': '+ JSON.stringify(stateObject)); });

JS SDK

Thing Shadow

Class

Page 37: Getting Started with AWS IoT, Devices & SDKs

<demo>...

</demo>

Page 38: Getting Started with AWS IoT, Devices & SDKs

AWS IoT

Page 39: Getting Started with AWS IoT, Devices & SDKs

Focus on Your Idea

Page 40: Getting Started with AWS IoT, Devices & SDKs

Danilo Poccia @danilop danilop

Thank You