mqtt - communication in the internet of things

64
#dwx14 1 MQTT Christian Götz, dc-square - Kommunikation im Internet der Dinge

Upload: christian-goetz

Post on 06-May-2015

1.027 views

Category:

Internet


6 download

DESCRIPTION

Das Internet der Dinge (IoT) und Maschine-zu-Maschine Kommunikation (M2M) ist momentan in aller Munde. Studien zeigen das es bis 2020 50 Milliarden Geräte sein werden, die über das Internet miteinander kommunizieren und jede Sekunde kommen 80 neue Geräte hinzu. Momentan dominierende Protokolle wie HTTP/REST sind nur bedingt geeignet, um die Anforderungen abzudecken. Herausforderungen sind zum Beispiel das Senden von Nachrichten von einem Gerät zu vielen, Skalierung der Anzahl an Geräte, Push Notifications und Sicherstellung der korrekten Übermittlung. Das Publish/Subscribe-Protokoll MQTT erfüllt diese Anforderungen und wurde für mobile Geräte entwickelt. Es wird beispielsweise von Facebook für den Messenger eingesetzt. Dieser Vortrag gibt eine Einführung in MQTT sowie die Implementierung Eclipse Paho und zeigt anhand von Beispielquellcode und einer Livedemo, welche Probleme man damit lösen kann. - See more at: http://www.developer-week.de/History/2014/Programm/Veranstaltung/(event)/14178#sthash.ioXw2aoi.dpuf

TRANSCRIPT

Page 1: MQTT - Communication in the Internet of Things

#dwx14

1

MQTT

Christian Götz, dc-square

- Kommunikation im Internet der Dinge

Page 2: MQTT - Communication in the Internet of Things

Hi, I’m Christian Götz

author & speakerbuilding solutions

CEO & co-founder

developer@goetzchr

Page 3: MQTT - Communication in the Internet of Things

IoT?

Page 4: MQTT - Communication in the Internet of Things

GPSGPS

GPSGPS

GPSGPS

GPS

Detected: Traffic Jam!

GPS

GPS

GPS

Page 5: MQTT - Communication in the Internet of Things

THINGS?

Page 6: MQTT - Communication in the Internet of Things

Consumer Goods

Page 7: MQTT - Communication in the Internet of Things

Industry Machines

Page 8: MQTT - Communication in the Internet of Things

objects in our everyday life

Page 9: MQTT - Communication in the Internet of Things

logistics has a lot of things...

Page 10: MQTT - Communication in the Internet of Things

Internet of Things?

Page 11: MQTT - Communication in the Internet of Things

Technology that connects Devices

over wired or wireless communication

Page 12: MQTT - Communication in the Internet of Things

why should I care ?

Page 13: MQTT - Communication in the Internet of Things

6,5 per person

DEVICES outnumber people

0,0

15,0

30,0

45,0

60,0

2003 2010 2015 2020

50,0

25,0

12,5

0,5

6,0

19,5

33,0

46,5

60,0

2003 2010 2015 2020

7,67,36,86,3

250 new every sec

http://blogs.cisco.com/news/cisco-connections-counter/

http://www.cisco.com/web/about/ac79/docs/innov/IoT_IBSG_0411FINAL.pdf

2020in billions

people

devices

Page 14: MQTT - Communication in the Internet of Things

finally a use case for IPv6 ;)

Page 15: MQTT - Communication in the Internet of Things

Open Hardware is everywhere

simple

accessible

affordable

Page 16: MQTT - Communication in the Internet of Things

How do things talk?

Page 17: MQTT - Communication in the Internet of Things

17

Page 18: MQTT - Communication in the Internet of Things

HTTP/REST

used since 1991

widely known and adapted

request/response

point 2 point

HTTP 2.0 - still work in progress

Page 19: MQTT - Communication in the Internet of Things

Challenges

Page 20: MQTT - Communication in the Internet of Things

Constrained devices

Bi-directional

Scalability

Unreliable Networks

Push Messaging

Security

IoTHTTP

IoT challenges

Page 21: MQTT - Communication in the Internet of Things

CoAPConstrained Application Protocol? HTTP

Page 22: MQTT - Communication in the Internet of Things

MQTT is a good fit

I’ll tell you why

Page 23: MQTT - Communication in the Internet of Things

Messaging Protocolsimple

on top of TCP

Pub/Subbinary

minimal overheaddata-agnostic

unreliable networks

Page 24: MQTT - Communication in the Internet of Things
Page 25: MQTT - Communication in the Internet of Things
Page 26: MQTT - Communication in the Internet of Things

Subscribe

Page 27: MQTT - Communication in the Internet of Things

Publish

Page 28: MQTT - Communication in the Internet of Things

Temperaturfühler MQTT-Broker

Laptop

Mobiles Endgerät

publish: “21°C“publish: “21°C“

publish: “21°C“

subscribe

subscribe

Page 29: MQTT - Communication in the Internet of Things

1999 2010 2013 2014

Arlen Nipper & Andy Stanford-Clark

invent MQTTroyalty free OASIS TC

formedMQTT becomes Standard

MQTT history

Page 30: MQTT - Communication in the Internet of Things

London

BigBen

London Eye

people

temp

people

temp

/

/

/

MQTT topics 101

/ /

Page 31: MQTT - Communication in the Internet of Things

London

BigBen

London Eye

people

temp

people

temp

/

/

/

The temperature of Big Ben London/BigBen/temp

MQTT topics 101

/ /

Page 32: MQTT - Communication in the Internet of Things

London

BigBen

London Eye

people

temp

people

temp

/

/

All temperature values London/+/temp

/

MQTT topics 101

/ /

Page 33: MQTT - Communication in the Internet of Things

London

BigBen

London Eye

people

temp

people

temp

/

/

All from the London Eye London/LondonEye/#

/

MQTT topics 101

/ /

Page 34: MQTT - Communication in the Internet of Things

London

BigBen

London Eye

people

temp

people

temp

/

/

All messages #

/

MQTT topics 101

/ /

Page 35: MQTT - Communication in the Internet of Things

Push instead of Poll

Minimal Bandwidth is important

Unreliable networks

Constrained devices

Low Latency

MQTT use cases

Page 36: MQTT - Communication in the Internet of Things

Quality of Service

Retained Messages Last Will and Testament

Persistent Sessions Heartbeats

Topic Wildcards

MQTT features

Page 37: MQTT - Communication in the Internet of Things

MQTT features Quality of Services

QoS 1

QoS 2

QoS 0B

B

B

Page 38: MQTT - Communication in the Internet of Things

MQTT features Last Will and Testament

BConnect

LWT

device123/status: „offline“

Bdropped

device123/status: „offline“

Page 39: MQTT - Communication in the Internet of Things

MQTT features w/o Retained Messages

Bdevice1/temp: „23,0“

device1

every 5 min

device2

device1/temp: „23,0“

Delay <= 5min

Page 40: MQTT - Communication in the Internet of Things

MQTT features Retained Messages

Bdevice1/temp: „23,0“ R

device1

every 5 min

device2

device1/temp: „23,0“ R

No Delay!

stores msg per topic

Page 41: MQTT - Communication in the Internet of Things

MQTT features Persistent Sessions

BConnect

Subscribedevice/+/status

device/12/status: „1“

1st

BRe-Connect

device/12/status: „1“2nd

Page 42: MQTT - Communication in the Internet of Things

MQTT-SN Overview

Gateway MQTT-Broker

MQTT-SN MQTT / -SN

• UDP instead of TCP • Topic is just an ID (Preregister/Register) • Sleeping Clients • Different types of Gateways • Discovery Mechanisms

Devices

B

Page 43: MQTT - Communication in the Internet of Things

MQTT over Websockets

Page 44: MQTT - Communication in the Internet of Things

MQTT Security

Protocol

Username/Password

Transport

TLS, client certificate authentification

Broker

fine-grained authentication, 3rd party integration

Page 45: MQTT - Communication in the Internet of Things

Broker implementations

Page 46: MQTT - Communication in the Internet of Things

MQTT Broker Mosquitto

Open Source

Ideal for constraint devices Supports Bridging

Written in C

Page 47: MQTT - Communication in the Internet of Things

MQTT Broker HiveMQ

High performance broker

Open Plugin System for Java Clustering

Bridging Scalable to > 100.000 connections

Native Websocket support

Page 48: MQTT - Communication in the Internet of Things

MQTT Broker

+ othershttp://mqtt.org/wiki/doku.php/brokers

Page 49: MQTT - Communication in the Internet of Things

MQTT Broker Public Broker

www.mqttdashboard.com

Page 50: MQTT - Communication in the Internet of Things

Real World Use Cases

Page 51: MQTT - Communication in the Internet of Things

MQTT real world usage

https://www.facebook.com/notes/facebook-engineering/building-facebook-messenger/

10150259350998920

Page 52: MQTT - Communication in the Internet of Things

Getting started

Page 53: MQTT - Communication in the Internet of Things

MQTT Implementation

Page 54: MQTT - Communication in the Internet of Things

Open Source

“Reference Implementation”

Many languages: Java, Javascript, Lua, C, C++, Go, Python

Active Community

JS Library uses MQTT over Websockets

Paho facts

Page 55: MQTT - Communication in the Internet of Things

MqttClient client = new MqttClient( "tcp://localhost:1883", //URI "publisher", //Client ID new MemoryPersistence()); //Persistence

Paho Init Connection

Page 56: MQTT - Communication in the Internet of Things

MqttClient client = new MqttClient(...); !MqttConnectOptions connOptions = new MqttConnectOptions(); !connOptions.setKeepAliveInterval(120); connOptions.setWill("my/status", "offline".getBytes(), 2, true); connOptions.setCleanSession(false); connOptions.setUserName("user"); connOptions.setPassword(„pass".toCharArray()); !client.connect(connOptions);

Paho Init Connection

Page 57: MQTT - Communication in the Internet of Things

!!client.publish("my/topic/123",//topic "Hello!".getBytes(), //message

1, //QoS false); //retained !!

client.disconnect();

Paho Synchronous API

Page 58: MQTT - Communication in the Internet of Things

final MqttClient client = new MqttClient(...); client.setCallback(new MqttCallback() { @Override public void connectionLost(Throwable cause) {} !@Override public void messageArrived(String topic, MqttMessage message)throws Exception { System.out.println(new String(message.getPayload())); } !@Override public void deliveryComplete(IMqttDeliveryToken token) {} }); !client.connect(); client.subscribe("#");

Paho Synchronous API

Page 59: MQTT - Communication in the Internet of Things

MqttAsyncClient client = new MqttAsyncClient(...); client.connect(null, new IMqttActionListener() { @Override public void onSuccess(IMqttToken asyncActionToken) { try { client.publish(...); } catch (MqttException e) {}

} @Override public void onFailure(IMqttToken asyncActionToken, Throwable exception) {} }); !client.disconnect();

Paho Asynchronous API

Page 60: MQTT - Communication in the Internet of Things

MQTT Implementation

http://m2mqtt.wordpress.com/download/

MQTT Library for .NET

Page 61: MQTT - Communication in the Internet of Things

It’s ShowtimeDemo

Page 62: MQTT - Communication in the Internet of Things

Demo from device to the web with MQTT

https://github.com/dc-square/mqtt-with-paho-eclipsecon2013

available on

Page 63: MQTT - Communication in the Internet of Things

Demo Under the hood

Page 64: MQTT - Communication in the Internet of Things

Danke! Thanks!

@goetzchr