how to build own iot platform

31
HOW TO BUILD OWN IOT PLATFORM?

Upload: patrick-omiotek

Post on 16-Apr-2017

523 views

Category:

Internet


1 download

TRANSCRIPT

Page 1: How to build own IoT Platform

HOW TO BUILD OWN IOT PLATFORM?

Page 2: How to build own IoT Platform

AGENDA

➤ What is Internet of Things

➤ What we may do with it?

➤ Does it involve in our lives?

Page 3: How to build own IoT Platform

SOME EXAMPLES

Page 4: How to build own IoT Platform

SOME EXAMPLES

Page 5: How to build own IoT Platform

REST API

➤ KISS - Keep It Simple Stupid

➤ Make documentation

➤ Use e. g. Swagger

➤ Integration with other APIs

Page 6: How to build own IoT Platform

COLLECT DATA AND ANALYSE

➤ e. g. Elasticsearch and Kibana

Page 7: How to build own IoT Platform

MONITORING

Page 8: How to build own IoT Platform

MQTT

➤ MQTT is lightweight, secure, battery friendly and machine-to-machine (M2M) / “Internet of Things” connectivity protocol

➤ Publish-subscribed based

➤ Designed for connections with remote locations where “small code footprint” is required and/or network bandwidth is limited

➤ The publish-subscribe messaging pattern requires a message broker

➤ The broker is responsible for distributing messages to interested clients based on the topic of a message

Page 9: How to build own IoT Platform

MQTT

➤ supports offline messaging

➤ retains messages like key/value store

Page 10: How to build own IoT Platform

ARCHITECTURE

Page 11: How to build own IoT Platform

ARCHITECTURE

Page 12: How to build own IoT Platform

MQTT SUBSCRIBER

var mqtt = require('mqtt');

// load balancer var client = mqtt.connect('mqtt://YOUR.BROKER.URL');

client.subscribe('business/link');

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

console.log('Client started...');

Page 13: How to build own IoT Platform

MQTT PUBLISHER

var mqtt = require('mqtt');

// load balancer var client = mqtt.connect('mqtt://YOUR.BROKER.URL');

client.subscribe('business/link');

console.log('Client publishing...'); client.publish('business/link', ‘Welcome at IoT meeting… Test Ping! ' + Date());

client.end();

Page 14: How to build own IoT Platform

MQTT.FQ

Page 15: How to build own IoT Platform

MQTT BROKERS

➤ Mosquito

➤ Mosca

➤ CloudMQTT

➤ HiveMQ

Page 16: How to build own IoT Platform

MQTT.JS

➤ 20k packets/second parser

➤ stream based

➤ High-Level Client API

➤ Low-Level Server

Page 17: How to build own IoT Platform

MOSCA

➤ Standalone usage

➤ Embeddable in your app

➤ Authentication API

➤ Supports AMQP, Mongo, Redis, and MQTT as pub/sub backends

➤ Needs a DB as LevelDB, Mongo or Redis

➤ Support Websockets

➤ Fast, 10k+ messages routed per second

➤ Scalable, 10k+ concurrent connections

Page 18: How to build own IoT Platform

MOSCA, MQTT.JS, BROWSER

➤ Works on top of WebSockets

➤ Node.js excels that ;)

➤ MQTT over Websocket is ‘standard’

➤ Uses test broker at test.mosca.io

Page 19: How to build own IoT Platform

MOSCA SPEED

Page 20: How to build own IoT Platform

MOSCA VS MOSQUITTO

Page 21: How to build own IoT Platform

ECLIPSE PONTE

➤ Supports multiple protocols HTTP, MQTT, CoAP

➤ Based on Mosca, Express and Node.js

➤ Will support data transformation too!

Page 22: How to build own IoT Platform

THANKS

➤ Metteo Collina for an awesome stuff ;)

Page 23: How to build own IoT Platform

ANGULAR SERVICEdefine([ 'angular', ], function (angular) { 'use strict';

angular.module('BenfiIoTApp.Services.MQTTService', [ 'BenfiIoTApp.Config' ]) .factory('MQTTService', ServiceFn);

ServiceFn.$inject = [];

function ServiceFn() {

var service = this; var client = {};

service.connect = connect; service.publish = publish; service.onMessage = onMessage;

function connect(host, port, user, password) { var options = { username: user, password: password }; console.log("Try to connect to MQTT Broker " + host + " with user " + user); client = mqtt.connect(host, {}); client.subscribe("presence");

client.subscribe("sensors/brightness"); client.subscribe("sensors/temperature"); client.subscribe("sensors/humidity");

client.on('error', function(err) { console.log('error!', err); client.stream.end(); });

client.on('message', function (topic, message) { service.callback(topic, message); }); }

function publish(topic, payload) { client.publish(topic, payload, {retain: true}); console.log('publish-Event sent '+ payload + ' with topic: ' + topic + ' ' + client); }

function onMessage(callback) { service.callback = callback; }

return service; } });

Page 24: How to build own IoT Platform

BROWSER SUBSCRIBERdefine([ 'angular' ], function (angular) { 'use strict';

angular.module('BenfiIoTApp.Controllers.RealtimeCtrl', [ 'BenfiIoTApp.Config', 'BenfiIoTApp.Services.MQTTService' ]) .controller('RealtimeCtrl', ControllerFn);

ControllerFn.$inject = ['$scope', 'MQTTService'];

function ControllerFn($scope, MQTTService) { var vm = this;

vm.brightness = 0; vm.temperature = 0; vm.humidity = 0;

MQTTService.connect( ‘ws://YOUR.BROKER.URL' );

MQTTService.onMessage(function(topic, payload) { switch (topic) { case 'sensors/brightness': vm.brightness = payload.toString(); break; case 'sensors/temperature': vm.temperature = payload.toString(); break; case 'sensors/humidity': vm.humidity = payload.toString(); break; default: break; } $scope.$apply();

}); } });

Page 25: How to build own IoT Platform

BROWSER PUBLISHERdefine([ 'angular' ], function (angular) { 'use strict';

angular.module('BenfiIoTApp.Controllers.ColorCtrl', [ 'BenfiIoTApp.Services.MQTTService' ]) .controller('ColorCtrl', ControllerFn);

ControllerFn.$inject = ['MQTTService'];

function ControllerFn(MQTTService) { var vm = this;

vm.selectedColor = '#000000'; vm.send = send;

MQTTService.connect( 'ws://YOUR.BROKER:URL' );

function send() { MQTTService.publish('color', vm.selectedColor); }

} });

Page 26: How to build own IoT Platform

DEVICE SOFTWARE

➤ On your Arduino Yun install packages:

➤ opkg update

➤ opkg install mosquitto mosquitto-client libmosquitto

Page 27: How to build own IoT Platform

DEVICE PUB/SUB#include <MQTTclient.h> #define MQTT_HOST “YOUR.BROKER.URL”

void setup() { Serial.begin(115200); // remember the bridge! Bridge.begin(); // begin the client library (initialize host) mqtt.begin(MQTT_HOST, 1883); mqtt.subscribe("color", colorEvent); }

void loop() { // check for incoming events mqtt.monitor();

mqtt.publish("sensors/brightness", brightness); mqtt.publish("sensors/temperature", temperature); mqtt.publish("sensors/humidity", humidity);

delay(1000);

}

void colorEvent(const String& topic, const String& subtopic, const String& message) { // hex to rgb String hexstring = message; // Get rid of '#' and convert it to integer long number = strtol( &hexstring[1], NULL, 16); // Split them up into r, g, b values long r = number >> 16; long g = number >> 8 & 0xFF; long b = number & 0xFF;

for (int i = 0; i < NUMPIXELS; i++) {

pixels.setPixelColor(i, pixels.Color(r,g,b)); // Moderately bright green color. pixels.show(); // This sends the updated pixel color to the hardware. delay(delayval); // Delay for a period of time (in milliseconds). } }

Page 28: How to build own IoT Platform

WHY CLOUD? WHY AWS? WHAT MAY BE USEFUL?

➤ Load balancers

➤ Security groups

➤ Autoscaling

➤ Elastic Beanstalk

➤ EC2

➤ S3

➤ Elasticsearch Service

➤ ElasticCache

➤ Lambda

➤ Kinesis

Page 31: How to build own IoT Platform

QUESTIONS?

Patryk [email protected]

https://865632885505.signin.aws.amazon.com/console/