coap course for m2m and internet of things scenarios

44
1 Área Razón Social Cristina Peña Alcega (@CrisisP) Carlos Ralli Ucendo (@carlosralli) Telefónica Digital 19.12.2013 CoAP 6LowPAN & Raspberry Pi M2M Community

Upload: carlosralli

Post on 28-Jan-2015

121 views

Category:

Technology


6 download

DESCRIPTION

A course on CoRE-CoAP for m2m or IoT. A section on practical scenarios and another on CoAP basics. Many reference to other authors

TRANSCRIPT

Page 1: CoAP Course for m2m and Internet of Things scenarios

Cristina Peña Alcega (@CrisisP)Carlos Ralli Ucendo (@carlosralli)

Telefónica Digital

19.12.2013

CoAP6LowPAN &Raspberry PiM2M Community

Page 2: CoAP Course for m2m and Internet of Things scenarios

Index

DIY Scenarios & Solutions • Intro

• Scenario #1: z-wave + REST

• Scenario #2: 6LoWPAN + CoAP

I

II Behind the scenes: Constrained Application Protocol• Introduction and CoAP Architecture

• Messaging Model, Sub-layers, Reliability, Request/Response rules, and Message Format.

• Proxying and Caching

• Endpoints and URIs

• Discovery

• Multicast

• Security

• Status, advantages and limitations

• Available implementations

Page 3: CoAP Course for m2m and Internet of Things scenarios

I. DIY Scenarios & Solutions

Page 4: CoAP Course for m2m and Internet of Things scenarios

4M2M CommunityTelefónica Digital

01 How it all started…

Things (Devices) are getting smarter, from Class-1 to Consumer Electronics.

If a Thing is an Internet node, it’s subject of APIzation.

REST is the most successful Internet/Web API.

So we decided to start ourselves investing some 480€ to play with:

- 4 6LowPAN capable Motes (360€), 2 Raspberry PI (120€).

- Plus lots of hours of DIY “fun”!

CoRE /CoAP

Page 5: CoAP Course for m2m and Internet of Things scenarios

5M2M CommunityTelefónica Digital

02 Is CoAP Rocket Science? No, it’s just RESTTraditional REST WEB APIs relays on HTTP-TCP-IP

CoRE/CoAP = REST APIs over UDP-IP

Page 6: CoAP Course for m2m and Internet of Things scenarios

6M2M CommunityTelefónica Digital

03 Scenario1: Building a CoAP (IoT) Gateway

Page 7: CoAP Course for m2m and Internet of Things scenarios

7M2M CommunityTelefónica Digital

04 Scenario1: Software Architecture

Page 8: CoAP Course for m2m and Internet of Things scenarios

8M2M CommunityTelefónica Digital

05 Scenario1: Step 1

?

1.1) Install & compile ccoap in your laptop https://github.com/ipflavors/ccoap/tree/master/doc

Page 9: CoAP Course for m2m and Internet of Things scenarios

9M2M CommunityTelefónica Digital

06 Scenario1: Step 2

?

1.2) Install Firefox Navigator plus Copper (CU) Plugin https://addons.mozilla.org/en-US/firefox/addon/copper-270430/

Page 10: CoAP Course for m2m and Internet of Things scenarios

10M2M CommunityTelefónica Digital

07 Scenario1: Step 31.3) Test Firefox Copper with a CoAP server available in the Internet: coap://vs0.inf.ethz.ch:5683/

Page 11: CoAP Course for m2m and Internet of Things scenarios

11M2M CommunityTelefónica Digital

08 Scenario1: Step 3b1.3b) GET operation (of a long resource: 5x64bytes blocks): coap://vs0.inf.ethz.ch:5683/

Page 12: CoAP Course for m2m and Internet of Things scenarios

12M2M CommunityTelefónica Digital

09 Scenario1: Steps 4 & 5 1.4) Install z-way-server & configure z-wave devices w/ RaspberryPI. pi@raspberrypi:~$ wget -q -O - razberry.z-wave.me/install | sudo bash

To test installation: http://[IP_address]:8083

1.5) Install libcoap4.0.1 run server example in RaspberryPI. Download libcoap-4.0.1.tar.gz - http://sourceforge.net/projects/libcoap/

pi@raspberrypi:~$ tar xvzf libcoap-4.0.1.tar.gz

pi@raspberrypi:~$ cd libcoap-4.0.1

pi@raspberrypi:~$ ./configure

pi@raspberrypi:~$make

Page 13: CoAP Course for m2m and Internet of Things scenarios

13M2M CommunityTelefónica Digital

10 Scenario1: Steps 4 & 5

1.6) Run CoAP server example in RaspberryPI.

Page 14: CoAP Course for m2m and Internet of Things scenarios

14M2M CommunityTelefónica Digital

11 Scenario1: Step 61.6) Test against our RasPI server with Firefox Copper: coap://[2a02:9113:****:1f00:b***:****:****:***f]:5683/

Page 15: CoAP Course for m2m and Internet of Things scenarios

15M2M CommunityTelefónica Digital

12 Scenario1: Step 6b1.6b) Discover resources of our CoAP-RasPI server with Firefox Copper: coap://[2a02:9113:****:1f00:b***:****:****:***f]:5683/

Page 16: CoAP Course for m2m and Internet of Things scenarios

16M2M CommunityTelefónica Digital

13 Scenario1: Step 6c1.6c) GET operation (Firefox Copper): coap://[2a02:9113:****:1f00:b***:****:****:***f]:5683/

Page 17: CoAP Course for m2m and Internet of Things scenarios

17M2M CommunityTelefónica Digital

14 Scenario1: Step 6d1.6d) OBSERVE operation (PUSH Notifications) (Firefox Copper): coap://[2a02:9113:****:1f00:b***:****:****:***f]:5683/

Page 18: CoAP Course for m2m and Internet of Things scenarios

18M2M CommunityTelefónica Digital

15 Scenario1: Step 7

1.7) Modify server example to create CoAP resources based on z-wave dev:

- Follow IPSO Alliance Recs:http://www.ipso-alliance.org/wp-content/media/draft-ipso-app-framework-04.pdf

Page 19: CoAP Course for m2m and Internet of Things scenarios

19M2M CommunityTelefónica Digital

16 Scenario1: Implementing all this in FI-WAREWe are updating some FI-WARE IoT Ges to support this:

- “FIGWAY” SW to export CoAP resources too.

https://github.com/telefonicaid/fiware-raspberryPI-M2M-Gateway

Page 20: CoAP Course for m2m and Internet of Things scenarios

20M2M CommunityTelefónica Digital

17 Scenario1: A nice Project out there

?

WEBIPOI – Exports RasPI GPIO (wired) devices (CoRE & REST) http://code.google.com/p/webiopi/wiki/INTRODUCTION

Page 21: CoAP Course for m2m and Internet of Things scenarios

21M2M CommunityTelefónica Digital

18 Scenario2: CoAP (6LowPAN) Devices!

?

…Two (or more) Contiki-supported motes

“Nooliberry” -> 6LowPAN RasPI GPIO card

Your laptop - MACOSX, Linux, Windows…

Install Instant-Contiki VM in your Laptop

App coding:- Device: expose REST Resources over CoAP- Client: consume REST Resources (CoAP or HTTP)Web development as usual! Examples:

http://www.contiki-os.org/hardware.html http://www.advanticsys.com/ http://www.zolertia.com http://www.libelium.com (own Stack / OS)

http://www.contiki-os.org/start.html

https://github.com/contiki-os/contiki/blob/master/examples/rest-example/coap-client-server-example.csc

Page 22: CoAP Course for m2m and Internet of Things scenarios

22M2M CommunityTelefónica Digital

19 Scenario2: How it looks like?

Page 23: CoAP Course for m2m and Internet of Things scenarios

23M2M CommunityTelefónica Digital

20 Scenario2: Who’re already on board?

“Talking at CES today, Cerf described his home's sensor network, which uses IPv6 radios and the Arch Rock PhyNet smart grid system to track information like light levels, temperature, and humidity. This is important for a wine cellar…”

Page 24: CoAP Course for m2m and Internet of Things scenarios

II. Constrained Application Protocol

Page 25: CoAP Course for m2m and Internet of Things scenarios

25M2M CommunityTelefónica Digital

CoAP is an application layer protocol that enables web services for even the most constrained devices and networks, while integrating with the web

architecture and HTTP.

802.15.4

6LoWPAN

UDP

CoAP

Resources

Sensor

Contiki, Tiny OS, … 8-bit microcontrollers Aprox. 100KB of RAM for code,

heap, data… No filesystem

Proxy Server Client

CoAP

CoAP HTTP HTTP

Constrained Enviroments Low-power Lossy, high packet error rates Low thtoughpunt of 10s of kbps

Internet

01 CoAP: Constrained Application Protocol

Page 26: CoAP Course for m2m and Internet of Things scenarios

26M2M CommunityTelefónica Digital

CoAP: Designed for M2M

• CoAP implements the REST architectural style: can be transparently mapped to HTTP

• CoAP goes beyond HTTP providing: Very low over-head, avoids the need of IPv6 fragmentation Built-in discovery of services and resources Multicast support Asynchronous messages exchanges Native push notification

02

Page 27: CoAP Course for m2m and Internet of Things scenarios

27M2M CommunityTelefónica Digital

CoAP: The Web Architecture vs CoAP Architecture

The interaction model of CoAP is similar to the client/server model of the Web. However, M2M interactions typically result in a CoAP

implementation acting in both client and server roles.

02

Page 28: CoAP Course for m2m and Internet of Things scenarios

28M2M CommunityTelefónica Digital

CoAP: Messaging Model

• Short fixed-length binary header (4bytes)• Messages must fit in a single IP datagram

Default IP: 1280bytes, 6LoWPAN and IEEE802.15.4 127bytes

• Messages can be confirmable (CON) or non confirmable (NON).• Naturally runs over UDP and supports :

multicast IP destination addresses DTLS security

• Piggy-backed REST request/response The response to a CON message is carried in the ACK

• Request methods: GET, PUT, POST, and DELETE almost as in HTTP.

• Response methods: 2.xx (success), 4.xx (client error), 5.xx (server error).

03

Page 29: CoAP Course for m2m and Internet of Things scenarios

29M2M CommunityTelefónica Digital

CoAP: Sub-layers

Source: Matthias Kovatsch

04

Page 30: CoAP Course for m2m and Internet of Things scenarios

30M2M CommunityTelefónica Digital

CoAP: Unreliable Transmission

• Tipically, repeated readings from a sensor• If server lacks context to answer the request, sends Reset (RST)• Client can send the same mesage several times to ensure it

reaches the server

05

Page 31: CoAP Course for m2m and Internet of Things scenarios

31M2M CommunityTelefónica Digital

CoAP: Observing resources without reliability

Source: Klaus Hartke

06

Page 32: CoAP Course for m2m and Internet of Things scenarios

32M2M CommunityTelefónica Digital

CoAP: Reliable Transmission

• Normally bounded to non-reliable transport protocols, CoAP implements a lightweight reliability mechanism based on: Stop&wait retransmisssion for CON Duplicated detection for CON and NON

07

Page 33: CoAP Course for m2m and Internet of Things scenarios

33M2M CommunityTelefónica Digital

CoAP: Observing resources with reliability

Source: Klaus Hartke

08

Page 34: CoAP Course for m2m and Internet of Things scenarios

34M2M CommunityTelefónica Digital

CoAP: Request/Response Rules

Source: http://www.coapsharp.com

09

Page 35: CoAP Course for m2m and Internet of Things scenarios

35M2M CommunityTelefónica Digital

CoAP: Message Format

Source: Matthias Kovatsch

10

Page 36: CoAP Course for m2m and Internet of Things scenarios

36M2M CommunityTelefónica Digital

CoAP: Proxying and Caching

• CoAP supports caching Cacheability determined by response code An option number mask determines if it is a cache key. Max-age option indicates cache lifetime Validity checked using the Etag Option

• Caching can be at endpoint or intermediary (proxy).

• Proxy can be used to Improve performance (reduce network load) Access sleeping nodes Security reasons

• Very easy mapping CoAP (Cross-protocol-proxy)HTTP

11

Page 37: CoAP Course for m2m and Internet of Things scenarios

37M2M CommunityTelefónica Digital

CoAP: Proxying and Caching12

Page 38: CoAP Course for m2m and Internet of Things scenarios

38M2M CommunityTelefónica Digital

CoAP: Endpoints and URIs

• A CoAP endpoint is a source or destination of a message.• URI representations for resources:

coap-URI = "coap:" "//" <HOST> [ ":" <PORT> ] <PATH> [ "?" <QUERY> ] coaps-URI = "coaps:" "//" <HOST> [ ":" <PORT> ] <PATH> [ "?" <QUERY> ]

• HOST can be an IP address or a registered name. • PORT where CoAP server is located (default CoAP port: 5683)• Example: coap://example.com:436/sensors/temp?min=10

Host: example.com Port: 436 Path: sensors/temp Query: min=10

13

Page 39: CoAP Course for m2m and Internet of Things scenarios

39M2M CommunityTelefónica Digital

1. Discovering the servers: If unknown, the client has to learn HOST server

2. Discovering the resources The client queries the well known URI of the server on port 5683 The server returns the list of resources in CoRE Link Format

3. Both steps can be merged, querying the well known URI of “all CoAP nodes” using multicast address FF0X:0:0:0:0:0:0:C0A7

4. Resource Directories can be used

Related spec:• RFC 5785 defines the a path prefix for "well-known locations“• RFC 5988 defines the types of web links and a registry for them• RFC 6690 defines a link format for user Web Link in CORE.

CoAP: Service and Resource Discovery

GET /.well-known/core

<sensors/temp>;sz=512;title=Temperature Sensor;ct=50,<actuators/jack>;sz=256;title=Hydraulic Jacks;ct=50

14

Page 40: CoAP Course for m2m and Internet of Things scenarios

40M2M CommunityTelefónica Digital

• CoAP supports making requests to IP multicast groups in NON

• Leisure time• CoAP does not support yet the use of multicast with security

CoAP: RESTful Group Communication15

Page 41: CoAP Course for m2m and Internet of Things scenarios

41M2M CommunityTelefónica Digital

CoAP: Security

• CoAP is secured using Datagram TLS (RFC6347) over UDP.• The endpoint initiates session to the server and, after the DTLS

handshake, it can send the 1st CoAP request.• All CoAP messages are sent as DTLS “application data”.• DTLS adds a limited per-datagram overhead of aprox 13 bytes.• Security info (e.g. keys, ACLs) must be provided during the

provisioning of the device. • The device can be in 1 of 4 security modes:

NoSec: DTLS is disabled. Can be combined with alternative security (e.g. IPSEC)

PreSharedKey: DTLS enabled, preshared keys authenticate peers or groups of peers.

RawPublicKey: DTLS enabled, asymmetric keys without certificate. Certificate: DTLS enabled, asymmetric keys with x.509 certificate.

• DTLS is not appropriate to group keying (multicast).

16

Page 42: CoAP Course for m2m and Internet of Things scenarios

42M2M CommunityTelefónica Digital

CoAP: Status, Advantages and Limitations

• Proposed standard since July, 2013: draft-ietf-core-coap-18.

• Advantages: Designed for M2M, IoT Easily mapped to HTTP, compatible with Proxy infrastructures. Easy to map legacy protocols to CoAP Extensions: push notifications, discovery and Multicast.

• Limitations and work in progress: End to end secure connection required for CoAP/HTTP mapping at a

proxy using DTLS/TLS. Securing multicast communications. Semantics should be standardized. Caching of requests should also be allowed

17

Page 43: CoAP Course for m2m and Internet of Things scenarios

43M2M CommunityTelefónica Digital

CoAP: available implementations

• Implementations Contiki-2.6: Erbium http://www.contiki-os.org/ C: libcoap http://sourceforge.net/projects/libcoap/develop .NET (C#): CoAPSharp http://www.coapsharp.com/ Python: http://sourceforge.net/projects/coapy JAVA: Californium https://github.com/mkovatsc/Californium Firefox JavaScript browser plugin: Copper

https://github.com/mkovatsc/Copper, https://addons.mozilla.org/de/firefox/addon/copper-270430/

• Proxies: Squid 3.1.9 with transparent HTTP-CoAP mapping module

http://telecom.dei.unipd.it/pages/read/90/ jcoap Proxy http://code.google.com/p/jcoap/ Californium cf-proxy https://github.com/mkovatsc/Californium

• Updated List: http://en.wikipedia.org/wiki/Constrained_Application_Protocol#Implementations

18

Page 44: CoAP Course for m2m and Internet of Things scenarios