Top Banner
Politecnico di Milano Advanced Network Technologies Laboratory Application Layer Protocols for the IoT 1
49

Application Layer Protocols for the IoT - Intranet DEIBhome.deib.polimi.it/cesana/teaching/IoT/2017/classes/7.Application... · Application Layer Protocols for the IoT 1. ... o Embedded

May 22, 2018

Download

Documents

phamdan
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Application Layer Protocols for the IoT - Intranet DEIBhome.deib.polimi.it/cesana/teaching/IoT/2017/classes/7.Application... · Application Layer Protocols for the IoT 1. ... o Embedded

Politecnico di MilanoAdvanced Network Technologies Laboratory

Application Layer Protocols for the IoT

1

Page 2: Application Layer Protocols for the IoT - Intranet DEIBhome.deib.polimi.it/cesana/teaching/IoT/2017/classes/7.Application... · Application Layer Protocols for the IoT 1. ... o Embedded

Politecnico di MilanoAdvanced Network Technologies Laboratory

COnstrained ApplicationProtocol(COAP)

2

Page 3: Application Layer Protocols for the IoT - Intranet DEIBhome.deib.polimi.it/cesana/teaching/IoT/2017/classes/7.Application... · Application Layer Protocols for the IoT 1. ... o Embedded

o GOAL:toenableweb-basedservicesinconstrainedwirelessnetworksn 8bitmicro-controllersn limitedmemoryn low-powernetworks

o Problem:WEBsolutionarehardlyapplicable

o Solution:re-designweb-basedservicesforconstrainednetworks->COAP

Background

3

Page 4: Application Layer Protocols for the IoT - Intranet DEIBhome.deib.polimi.it/cesana/teaching/IoT/2017/classes/7.Application... · Application Layer Protocols for the IoT 1. ... o Embedded

o ResourcesintheWebare:n managedbyserversn identifiedbyURIsn accessedsynchronouslyby

clientsthroughrequest/responseparadigms

o Inaword,RepresentationalStateTransfer(REST)

HowDoestheWebWork?

4

Page 5: Application Layer Protocols for the IoT - Intranet DEIBhome.deib.polimi.it/cesana/teaching/IoT/2017/classes/7.Application... · Application Layer Protocols for the IoT 1. ... o Embedded

URL Resolution

5

Page 6: Application Layer Protocols for the IoT - Intranet DEIBhome.deib.polimi.it/cesana/teaching/IoT/2017/classes/7.Application... · Application Layer Protocols for the IoT 1. ... o Embedded

The CoAP Architecture

6

Page 7: Application Layer Protocols for the IoT - Intranet DEIBhome.deib.polimi.it/cesana/teaching/IoT/2017/classes/7.Application... · Application Layer Protocols for the IoT 1. ... o Embedded

o Embedded web transfer protocol (coap://)o Asynchronous transaction model

o UDP binding with reliability and multicast supporto GET, POST, PUT, DELETE methodso URI support

o 4 byte headero Subset of MIME types and HTTP response codeso Built-in discovery o Optional observation and block transfer

CoAP At a Glance

7

Page 8: Application Layer Protocols for the IoT - Intranet DEIBhome.deib.polimi.it/cesana/teaching/IoT/2017/classes/7.Application... · Application Layer Protocols for the IoT 1. ... o Embedded

o Transport: n (mainly) UDP binding

o Message Exchange between Endpointsn Messages with 4 bytes header (shared by request and

responses) containing a message ID (16 bits)

n Reliable exchange through Confirmable Messages which must be acknowledged (through ACK or Reset Messages). Simple Stop-and-Wait retransmission with exponential back-off.

n Unreliable exchange through Non-Confirmable Messagen Duplicate detection for both confirmable and non-confirmable

messages (through message ID)

COAPMessagingBasics

8

Page 9: Application Layer Protocols for the IoT - Intranet DEIBhome.deib.polimi.it/cesana/teaching/IoT/2017/classes/7.Application... · Application Layer Protocols for the IoT 1. ... o Embedded

COAPMessaging

9

Message ID

Page 10: Application Layer Protocols for the IoT - Intranet DEIBhome.deib.polimi.it/cesana/teaching/IoT/2017/classes/7.Application... · Application Layer Protocols for the IoT 1. ... o Embedded

o REST Request/Response piggybacked on CoAP Messages

o Method, Response Code and Options (URI, content-type etc.)

COAP Message Semantics

10

Page 11: Application Layer Protocols for the IoT - Intranet DEIBhome.deib.polimi.it/cesana/teaching/IoT/2017/classes/7.Application... · Application Layer Protocols for the IoT 1. ... o Embedded

COAPRequest/Response Examples

11

Message ID

Token

Page 12: Application Layer Protocols for the IoT - Intranet DEIBhome.deib.polimi.it/cesana/teaching/IoT/2017/classes/7.Application... · Application Layer Protocols for the IoT 1. ... o Embedded

COAP:SeparateResponse

12

Page 13: Application Layer Protocols for the IoT - Intranet DEIBhome.deib.polimi.it/cesana/teaching/IoT/2017/classes/7.Application... · Application Layer Protocols for the IoT 1. ... o Embedded

COAP:Non-confirmableRequest

13

Page 14: Application Layer Protocols for the IoT - Intranet DEIBhome.deib.polimi.it/cesana/teaching/IoT/2017/classes/7.Application... · Application Layer Protocols for the IoT 1. ... o Embedded

0 1 2 30 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1

+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+|Ver| T | TKL | Code | Message ID |+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+| Token (if any, TKL bytes) ...+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+| Options (if any) ...+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+|1 1 1 1 1 1 1 1| Payload (if any) ...+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

Ver - Version (1)

T – Message Type (Confirmable, Non-Confirmable, Acknowledgement, Reset)

TKL- Token Length, if any, the number of Token bytes after this header

Code - Request Method (1-10) or Response Code (40-255)

Message ID – 16-bit identifier for matching responses

Token – Optional response matching token

Message Header (4 bytes)

14

Page 15: Application Layer Protocols for the IoT - Intranet DEIBhome.deib.polimi.it/cesana/teaching/IoT/2017/classes/7.Application... · Application Layer Protocols for the IoT 1. ... o Embedded

0 1 2 3 4 5 6 7+---------------+---------------+| | || Option Delta | Option Length | 1 byte| | |+---------------+---------------+\ \/ Option Delta / 0-2 bytes\ (extended) \+-------------------------------+\ \/ Option Length / 0-2 bytes\ (extended) \+-------------------------------+\ \/ /\ \/ Option Value / 0 or more bytes\ \/ /\ \+-------------------------------+

Option Delta - Difference between this option type and the previousLength - Length of the option value

Value - The value of Length bytes immediately follows Length

Option Format

15

Page 16: Application Layer Protocols for the IoT - Intranet DEIBhome.deib.polimi.it/cesana/teaching/IoT/2017/classes/7.Application... · Application Layer Protocols for the IoT 1. ... o Embedded

+-----+---+---+---+---+----------------+--------+--------+----------+| No. | C | U | N | R | Name | Format | Length | Default |+-----+---+---+---+---+----------------+--------+--------+----------+| 1 | x | | | x | If-Match | opaque | 0-8 | (none) || 3 | x | x | - | | Uri-Host | string | 1-255 | (see || | | | | | | | | below) || 4 | | | | x | ETag | opaque | 1-8 | (none) || 5 | x | | | | If-None-Match | empty | 0 | (none) || 7 | x | x | - | | Uri-Port | uint | 0-2 | (see || | | | | | | | | below) || 8 | | | | x | Location-Path | string | 0-255 | (none) || 11 | x | x | - | x | Uri-Path | string | 0-255 | (none) || 12 | | | | | Content-Format | uint | 0-2 | (none) || 14 | | x | - | | Max-Age | uint | 0-4 | 60 || 15 | x | x | - | x | Uri-Query | string | 0-255 | (none) || 16 | | | | | Accept | uint | 0-2 | (none) || 20 | | | | x | Location-Query | string | 0-255 | (none) || 35 | x | x | - | | Proxy-Uri | string | 1-1034 | (none) || 39 | x | x | - | | Proxy-Scheme | string | 1-255 | (none) |+-----+---+---+---+---+----------------+--------+--------+----------+

C=Critical, U=Unsafe, N=NoCacheKey, R=Repeatable

Base Specification Options

16

Page 17: Application Layer Protocols for the IoT - Intranet DEIBhome.deib.polimi.it/cesana/teaching/IoT/2017/classes/7.Application... · Application Layer Protocols for the IoT 1. ... o Embedded

o StopandWaitapproacho Repeatarequestafteratime-outincase

ACK(orRST)isnotcomingback

Dealing with Packet Loss

17

Page 18: Application Layer Protocols for the IoT - Intranet DEIBhome.deib.polimi.it/cesana/teaching/IoT/2017/classes/7.Application... · Application Layer Protocols for the IoT 1. ... o Embedded

o Initialtime-outsetto:n Rand[ACK_TIMEOUT,ACK_TIMEOUT*

ACK_RANDOM_FACTOR]([2s,3s])o Whentime-outexpiresandthetransmissioncounteris

lessthanMAX_RETRANSMIT(4)n retransmitn Increasetransmissioncountern doublethetime-outvalue

o Theprocedureisrepeateduntiln AACKisreceivedn ARSTmessageisreceivedn thetransmissioncounterexceedsMAX_RETRANSMITn thetotalattemptdurationexceedsMAX_TRANSMIT_WAIT

(93s)

Back-OffDetails

18

Page 19: Application Layer Protocols for the IoT - Intranet DEIBhome.deib.polimi.it/cesana/teaching/IoT/2017/classes/7.Application... · Application Layer Protocols for the IoT 1. ... o Embedded

Proxyng and caching

19

Page 20: Application Layer Protocols for the IoT - Intranet DEIBhome.deib.polimi.it/cesana/teaching/IoT/2017/classes/7.Application... · Application Layer Protocols for the IoT 1. ... o Embedded

o PROBLEM:n RESTparadigmisoften“PULL”type,thatis,

dataisobtainedbyissuinganexplicitrequestn Information/datainWSNisoften

periodic/triggered(e.g.,getmeatemperaturesampleevery2secondsorgetmeawarningiftemperaturegoesbelow5°C)

o SOLUTION:useObservationonCOAPresources

COAPObservation

20

Page 21: Application Layer Protocols for the IoT - Intranet DEIBhome.deib.polimi.it/cesana/teaching/IoT/2017/classes/7.Application... · Application Layer Protocols for the IoT 1. ... o Embedded

Observation

21See draft-ietf-core-observe

Page 22: Application Layer Protocols for the IoT - Intranet DEIBhome.deib.polimi.it/cesana/teaching/IoT/2017/classes/7.Application... · Application Layer Protocols for the IoT 1. ... o Embedded

o PROBLEM:avoidsegmentationinthelowerlayers(IPv6)

o SOLUTION:COAPBlockTransferModen bringsupfragmentationattheapplication

layer

COAPBlockTransfer

22

Page 23: Application Layer Protocols for the IoT - Intranet DEIBhome.deib.polimi.it/cesana/teaching/IoT/2017/classes/7.Application... · Application Layer Protocols for the IoT 1. ... o Embedded

o Block2 Optionaddedtomessagesn nr=incrementalblocknumberwithinoriginaldatan m=moreblocksflagn sz=blocksize

Block transfer

23

Page 24: Application Layer Protocols for the IoT - Intranet DEIBhome.deib.polimi.it/cesana/teaching/IoT/2017/classes/7.Application... · Application Layer Protocols for the IoT 1. ... o Embedded

o Resource Discoveryn GOAL: Discovering the links hosted by

CoAP (or HTTP) serversGET /.well-known/core?optional_query_string

n Returns a link-header style formato URL, relation, type, interface, content-type etc.

Discovery & Semantics

24

Page 25: Application Layer Protocols for the IoT - Intranet DEIBhome.deib.polimi.it/cesana/teaching/IoT/2017/classes/7.Application... · Application Layer Protocols for the IoT 1. ... o Embedded

</dev/bat>;obs;if="";rt="ipso:dev-bat";ct="0",</dev/mdl>;if="";rt="ipso:dev-mdl";ct="0",</dev/mfg>;if="";rt="ipso:dev-mfg";ct="0”,</pwr/0/rel>;obs;if="";rt="ipso:pwr-rel";ct="0",</pwr/0/w>;obs;if="";rt="ipso:pwr-w";ct="0",</sen/temp>;obs;if="";rt="ucum:Cel";ct="0"

CoRE Resource Discovery

25

Page 26: Application Layer Protocols for the IoT - Intranet DEIBhome.deib.polimi.it/cesana/teaching/IoT/2017/classes/7.Application... · Application Layer Protocols for the IoT 1. ... o Embedded

o Open source implementations:n Java CoAP Library Californium n C CoAP Library Erbiumn libCoAP C Library n jCoAP Java Libraryn OpenCoAP C Libraryn TinyOS and Contiki include CoAP support

o Firefox has a CoAP plugin called Coppero Wireshark has CoAP plugin

Getting Started with CoAP

26

Page 27: Application Layer Protocols for the IoT - Intranet DEIBhome.deib.polimi.it/cesana/teaching/IoT/2017/classes/7.Application... · Application Layer Protocols for the IoT 1. ... o Embedded

Politecnico di MilanoAdvanced Network Technologies Laboratory

TheMessageQueuingTelemetryTransport(MQTT)

Inventedin1999(IBMproprietarystandard)Releasedin2010OfficialOASISstandardsince2014CurrentversionMQTT3.1.1 http://docs.oasis-open.org/mqtt/mqtt/v3.1.1/mqtt-v3.1.1.html

27

Page 28: Application Layer Protocols for the IoT - Intranet DEIBhome.deib.polimi.it/cesana/teaching/IoT/2017/classes/7.Application... · Application Layer Protocols for the IoT 1. ... o Embedded

MQTTisaClientServerpublish/subscribemessaging transportprotocol.

o Morefeatures:n Simpletoimplement(especiallyatthesensor

side)n QoS Supportn Lightweightandbandwidthefficientn Dataagnosticn Sessionawareness

MQTTinshort

28

Page 29: Application Layer Protocols for the IoT - Intranet DEIBhome.deib.polimi.it/cesana/teaching/IoT/2017/classes/7.Application... · Application Layer Protocols for the IoT 1. ... o Embedded

o Publish/Subscribeparadigmn Clientsdon’tknoweachothern One-to-Manyparadigmn Everyclientpublishes&subscribesn PUSHinformationparadigmcomparedtoPULL’s

oneinCOAP

CommunicationPattern

29

Publish: “30° C” Publish: “30° C”

Publish: “30° C”

Subscribe: “?°C”

Subscribe: “?°C”MQTT

Senosr nodeMobile device

Laptop

Page 30: Application Layer Protocols for the IoT - Intranet DEIBhome.deib.polimi.it/cesana/teaching/IoT/2017/classes/7.Application... · Application Layer Protocols for the IoT 1. ... o Embedded

o Publish/Subscribeparadigmn Clientsdon’tknoweachothern One-to-Manyparadigmn Everyclientpublishes&subscribesn PUSHinformationparadigmcomparedtoPULL’s

oneinCOAP

MQTTComponents

30

Publish: “30° C” Publish: “30° C”

Publish: “30° C”

Subscribe: “?°C”

Subscribe: “?°C”

Senosr nodeMQTT Client Mobile device

MQTT Client

LaptopMQTT Client

MQTTBroker

Page 31: Application Layer Protocols for the IoT - Intranet DEIBhome.deib.polimi.it/cesana/teaching/IoT/2017/classes/7.Application... · Application Layer Protocols for the IoT 1. ... o Embedded

deib/antlab/room5/temperature

o Wildcardsallowedonlywhensubscribing

deib/antlab/ + /temperature

Plussigncanbeusedinmultiplelevels

MQTTTopics

31

Topic level Topic separator

Single level Wildcard

Page 32: Application Layer Protocols for the IoT - Intranet DEIBhome.deib.polimi.it/cesana/teaching/IoT/2017/classes/7.Application... · Application Layer Protocols for the IoT 1. ... o Embedded

deib/antlab/room5/ #

Multi-levelWildcards

32

Multi-level Wildcard(can be used only at the end)

Page 33: Application Layer Protocols for the IoT - Intranet DEIBhome.deib.polimi.it/cesana/teaching/IoT/2017/classes/7.Application... · Application Layer Protocols for the IoT 1. ... o Embedded

o EachMQTTclientopensoneconnectiontotheMQTTBroker

o Pushcapabilitieso Workseventhrough

firewalls

MQTTConnections

33

MQTT

TCP

IP

Page 34: Application Layer Protocols for the IoT - Intranet DEIBhome.deib.polimi.it/cesana/teaching/IoT/2017/classes/7.Application... · Application Layer Protocols for the IoT 1. ... o Embedded

o CONNECTmessagefields:n clientId “clientMatteo”n cleanSession truen username (opt) “matteo”n password (opt) “1234”n lastWillTopic (opt) “matteo/temp”n lastWillQoS (opt) 1n lastWillMessage (opt) “something wrong”n keepAlive 30

OpenConnections

34

MQTTBroker

MQTTClient

CONNECT

CONNACK

Page 35: Application Layer Protocols for the IoT - Intranet DEIBhome.deib.polimi.it/cesana/teaching/IoT/2017/classes/7.Application... · Application Layer Protocols for the IoT 1. ... o Embedded

o CONNACKmessagefields:n sessionPresent truen returnCode 0-4

0: everything ok1: unacceptable version2: id rejected3: server unavailable4: bad username and pwd5: unauthorized

OpenConnections

35

MQTTBroker

MQTTClient

CONNECT

CONNACK

Page 36: Application Layer Protocols for the IoT - Intranet DEIBhome.deib.polimi.it/cesana/teaching/IoT/2017/classes/7.Application... · Application Layer Protocols for the IoT 1. ... o Embedded

o PUBLISHmessagefieldsn packeId 2n topicName “matteo/temp”n QoS 1n retainFlag falsen Payload “temperature:30”n dupFlag false

Publishing

36

MQTTBroker

MQTTClient

PUBLISH

MQTTClient

MQTTClient

MQTTClient

PUBLISH

Page 37: Application Layer Protocols for the IoT - Intranet DEIBhome.deib.polimi.it/cesana/teaching/IoT/2017/classes/7.Application... · Application Layer Protocols for the IoT 1. ... o Embedded

o Bestefforttransfer(samereliabilityprovidedbytheunderlyingtrasportprotocol)

QoS 0:“atmostonce”

37

MQTTBroker

MQTTClient

PUBLISH QoS=0

Page 38: Application Layer Protocols for the IoT - Intranet DEIBhome.deib.polimi.it/cesana/teaching/IoT/2017/classes/7.Application... · Application Layer Protocols for the IoT 1. ... o Embedded

o TheMQTTclientstoresthemessageandkeepsretransmittingituntilitisacknowledgedbytheMQTTbroker(messagecanbereceivedmultipletimes)

o PUBACKmessagefields:n packetId 2

QoS 1:“atleastonce”

38

MQTTBroker

MQTTClient

PUBLISH QoS=1

PUBACK

Page 39: Application Layer Protocols for the IoT - Intranet DEIBhome.deib.polimi.it/cesana/teaching/IoT/2017/classes/7.Application... · Application Layer Protocols for the IoT 1. ... o Embedded

o PUBREC,PUBREL,PUBCOMPmessagefields:n PacketId 2

o PUBLISHreception@MQTTbroker:processthepacketaccordingly, sendPUBRECmessageback,storelocallypacketId toavoidduplicateprocessing

o PUBRECreception@MQTTclient:discardtheinitialpacketandsendPUBRELo PUBRELreception@MQTTclient:clearanycurrent stateandsendPUBCOMP

QoS 2:“exactlyonce”

39

MQTTBroker

MQTTClient

PUBLISH QoS=1

PUBREC

PUBREL

PUBCOMP

Page 40: Application Layer Protocols for the IoT - Intranet DEIBhome.deib.polimi.it/cesana/teaching/IoT/2017/classes/7.Application... · Application Layer Protocols for the IoT 1. ... o Embedded

o SUBSCRIBEmessagefields:n packetId 2n QoS1 0n Topic1 “matteo/temp/1”n QoS2 1n Topic2 “kitchen/temp/2”n …....... ........

Subscribing

40

MQTTBroker

MQTTClient

SUBSCRIBE

SUBACK

o SUBACKmessage fields:n packetId 2n returnCode 1 2n returnCode 2 0

one returnCodefor each topic inthe subscription

one QoS/topic couplefor each subscription

Page 41: Application Layer Protocols for the IoT - Intranet DEIBhome.deib.polimi.it/cesana/teaching/IoT/2017/classes/7.Application... · Application Layer Protocols for the IoT 1. ... o Embedded

o UNSUBSCRIBEmessagefields:n packetId 2n Topic1 “matteo/temp/1”n Topic2 “kitchen/temp/2”n …....... ........

Unsubscribing

41

MQTTBroker

MQTTClient

UNSUBSCRIBE

UNSUBACK

o UNSUBACKmessage fields:n packetId 2

one returnCodefor each topic inthe subscription

Page 42: Application Layer Protocols for the IoT - Intranet DEIBhome.deib.polimi.it/cesana/teaching/IoT/2017/classes/7.Application... · Application Layer Protocols for the IoT 1. ... o Embedded

o Indefaultoperationmodewhentheclientdisconnects,alltheclient-relatedstatusatthebrokerisflushed(listofsubscription,QoS pendingmessages,etc.)

o Inpersistentsessionsbothclientandbrokermaintainasession:n Broker:

o Existenceofasession,eveniftherearenosubscriptionso Allsubscriptionso AllmessagesinQoS 1or2flow,whicharenotconfirmedbythecliento AllnewQoS 1or2messages,whichtheclientmissedwhileitwasofflneo AllreceivedQoS 2messages,whicharenotyetconfirmedtotheclient

n Cliento AllmessagesinaQoS 1or2flow,whicharenotconfirmedbythebrokero AllreceivedQoS 2messages,whicharenotyetconfirmedtothebroker

o Thatmeanseveniftheclientisofflinealltheabovewillbestoredbythebrokerandareavailablerightaftertheclientreconnects.

PersistentSessions

42

Page 43: Application Layer Protocols for the IoT - Intranet DEIBhome.deib.polimi.it/cesana/teaching/IoT/2017/classes/7.Application... · Application Layer Protocols for the IoT 1. ... o Embedded

o Problem:publishingandsubscribingareasynchronousprocesses

o Aclientsubscribingtoatopicpatternmaynotgetanymessageonthattopicuntilsomeotherclientpublishesonit

o Retaind messagesarePUBLISHmessageswiththeretainedFlag settoone

o Thebrokerstoreslocallytheretainedmessageandsendittoanyotherclientwhichsubscribestoatopicpatternmatchingthatoftheretainedmessage

RetainedMessges

43

Page 44: Application Layer Protocols for the IoT - Intranet DEIBhome.deib.polimi.it/cesana/teaching/IoT/2017/classes/7.Application... · Application Layer Protocols for the IoT 1. ... o Embedded

o TheLastWillandTestament(LWT)notifiesotherclientsaboutanharddisconnec byaspecificclient

o Eachclientcanspecifyitslastwillmessagewhenconnectingtoabroker

o Thebrokerwillstorethemessageuntilitdetectsclientharddisconnection

o Thebrokersendsthemessagetoallsubscribedclientsonthespecifictopic

o ThestoredLWTmessagewillbediscardedifaclientdisconnectsgracefullybysendingaDISCONNECTmessage.

LastWillMessage

44

Page 45: Application Layer Protocols for the IoT - Intranet DEIBhome.deib.polimi.it/cesana/teaching/IoT/2017/classes/7.Application... · Application Layer Protocols for the IoT 1. ... o Embedded

o CONNECTmessagefields:n clientId “clientMatteo”n cleanSession truen username (opt) “matteo”n password (opt) “1234”n lastWillTopic (opt) “matteo/temp”n lastWillQoS (opt) 1n lastWillMessage (opt) “something wrong”n keepAlive 30

LWTSetUp

45

MQTTBroker

MQTTClient

CONNECT

CONNACK

Page 46: Application Layer Protocols for the IoT - Intranet DEIBhome.deib.polimi.it/cesana/teaching/IoT/2017/classes/7.Application... · Application Layer Protocols for the IoT 1. ... o Embedded

o AnI/Oerrorornetworkfailureisdetectedbytheserver.

o TheclientfailstocommunicatewithintheKeepAlivetime.

o TheclientclosesthenetworkconnectionwithoutsendingaDISCONNECTpacketfirst.

o Theserverclosesthenetworkconnectionbecauseofaprotocolerror.

LWTMessageissentwhen..

46

Page 47: Application Layer Protocols for the IoT - Intranet DEIBhome.deib.polimi.it/cesana/teaching/IoT/2017/classes/7.Application... · Application Layer Protocols for the IoT 1. ... o Embedded

o Itisresponsability oftheclienttokeeptheMQTTconnectionactive

o Uponexpirationofthekeepalive,ifnootherinteractionhashappenedwithbroker,theclient”pings”thebrokerwhich“pingsitback”

o PINGREQandPINGRESPmessageshavenullpayload

Keepalive

47

MQTTBroker

MQTTClient

PINGREQ

PINGRESP

Page 48: Application Layer Protocols for the IoT - Intranet DEIBhome.deib.polimi.it/cesana/teaching/IoT/2017/classes/7.Application... · Application Layer Protocols for the IoT 1. ... o Embedded

o Maindifferencesn Extendedarchitecture

withGatewaysandForwarders

n Newgatewaydiscoveryprocedures(andmessages)

n Somemessagesaremore“compressed”

n Extendedkeepaliveprocedurestosupportsleepingclients

MQTT-SN

48

Page 49: Application Layer Protocols for the IoT - Intranet DEIBhome.deib.polimi.it/cesana/teaching/IoT/2017/classes/7.Application... · Application Layer Protocols for the IoT 1. ... o Embedded

o Brokerslistn Mosquitton HiveMQ

o MQTTandNodeRed.Let’suseit

Gettingstarted

49