The constrained application protocol (coap) part 3

Post on 16-Apr-2017

134 views 3 download

transcript

The Constrained Application Protocol (CoAP)-Part 3&

Conclusion

Khamdamboy Urunov, a Ph.D. student.,hamdamboy.urunov@gmail.com

2

CoAP Method

http://www.slideshare.net/JunHwanHuh/one-m2mprotocol-binding/15

3

The PUT method requests that the resource identified by the request URI be updated or created with the enclosed representation.

If a resource exists at the request URI, the enclosed representation SHOULD be considered a modified version of that resource, and a 2.04 (Changed) Response Code SHOULD be returned.

If no resource exists, then the server MAY create a new resource with that URI, resulting in a 2.01 (Created) Response Code.

If the resource could not be created or modified, then an appropriate error Response Code SHOULD be sent.

Method: PUTURI: coap://scrc.com/Value: PUT/resource/db/app1/sensor/temp/5afb?it=32.25

CoAP methods (cont…)PUT

Client Server

CON PUT/resource/db/…/?it=32.25

ACK Changed 2.04 Up

date

4

The DELETE method requests that the resource identified by the request URI be deleted.

A 2.02 (Deleted) Response Code SHOULD be used on success or in case the resource did not exist before the request.

DELETE is not safe but is idempotent.

Method: DELETEURI: coap://scrc.com/Value: DELETE/resource/db/app1/sensor/temp/value/

Client Server

CON DELETE/resource/db/app/sensor/temp/value/

ACK Deleted De

-regi

ster

CoAP methods (cont…)DELETE

Code status

5

CoAP messages are encoded in a simple binary format. The Message Header (4 bytes).The variable-length token value 0 and 8 bytes long.

6

Ver - Version (1) 2 bit unsigned integer . Implementations of this field to 1 (01 binary).

T – Message Type 2- bit unsigned integer. (Confirmable, Non-Confirmable, Acknowledgement, Reset).

TKL- Token Length 4-bit unsigned integer. Indicates the length of the variable-length Token field (0-8 bytes).

Code – 8-bit unsighted integer. 3 bit class(most signification bits). 5 bits detail (least significant bits).

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

Message ID – 16-bit identifier for matching responses

Token – Optional response matching token

Message Format

Standards Track RFC 7252 June, 2014

Caching

7

• CoAP includes a simple caching modelCache ability determined by response codeAn option number mask determines if it is a cache key• Freshness modelMax-Age option indicates cache lifetime• Validation modelValidity checked using the Etag Option• A proxy often supports cachingUsually on behalf of a constrained node,a sleeping node,or to reduce network load

The Max-Age Option indicates the maximum time a response may be cached before it MUST be considered not fresh.

The option value is an integer number of seconds between 0 and 2^32-1 inclusive (about 136.1 years).

A default value of 60 seconds is assumed in the absence of the option in a response. This option is "elective". It MUST NOT occur more than once.

Proxying and caching

8

Observation

9

COAP Observation

PROBLEM: REST paradigm is often “PULL” type, that is, data is obtained by issuing an explicit request

Information/data in WSN is often periodic/

triggered (e.g., get me a temperature sample every

2 seconds or get me a warning if temperature goes

below 5°C)

SOLUTION: use Observation on COAP resources

CoAP observation (cont… )

10http://docs.exosite.com/coap/

Getting Started with CoAP

11

• There are many open source implementations available

Java CoAP Library Californium

C CoAP Library Erbium

libCoAP C Library

jCoAP Java Library

OpenCoAP C Library

TinyOS and Contiki include CoAP support

• CoAP is already part of many commercial products/systems

Sensinode NanoService

RTX 4100 WiFi Module

• Firefox has a CoAP plugin called Copper

• Wireshark has CoAP dissector support

• Implement CoAP yourself, it is not that hard!

12

Getting Started with CoAP (cont…)

https://en.wikipedia.org/wiki/Constrained_Application_Protocol

LOBARO–COAP

13

Resource Directory

14

Discovery

15

• Service DiscoveryWhat services are available in the first place?

Goal of finding the IP address, port and

protocol

Usually performed by e.g. DNS-SD when DNS

is available

• Resource DiscoveryWhat are the Web resources I am interested in?Goal of finding URIsPerformed using Web Linking or some REST interface

CoRE Link Format is designed to enable resource discovery

Discovery (cont…)

16

The mechanism used by a node to search for resources among other nodes of the network.

A user at a node provides a search query containing a set of keywords corresponding to the resource being searched for.

A resource discovery protocol is then used to forward the search query to other nodes and search for the resource on those nodes.

When a resource is located at a node, a success message is sent to the node that originated the search query

Add CoAP to your application

17

Initial demonstration step of CoAP

18

Initial demonstration step of CoAP (cont…)• Installing Mozilla + Copper (Cu)• Java (JRE 7~8)• Eclipse (Mars 4.5) • Eclipse/ Help/ Reactive Block• Import packege CoAP and other

19

Initial demonstration step of CoAP (cont…)

20

Initial demonstration step of CoAP (cont…)

CoAP & MQTT

21

Conclusion

22

Thank you !

hamdmboy.urunov@gmail.com

23