A Low-Power CoAP for Contiki Matthias Kovatsch, Simon Duquennoy, and Adam Dunkels kovatsch@inf.ethz.ch Monday, 17 Oct 2011 simonduq@sics.se adam@sics.se Internet of Things Protocol Stack Layer Protocol Application CoAP / REST Engine (Erbium) Transport UDP Network IPv6 / RPL Adaption 6LoWPAN MAC CSMA / link-layer bursts Radio Duty Cycling ContikiMAC Physical IEEE 802.15.4 Matthias Kovatsch – ETH Zürich A Low-Power CoAP for Contiki 2 Internet of Things Protocol Stack Layer Protocol Application CoAP / REST Engine (Erbium) Transport UDP Network IPv6 / RPL Adaption 6LoWPAN MAC CSMA / link-layer bursts Radio Duty Cycling ContikiMAC Physical IEEE 802.15.4 Matthias Kovatsch – ETH Zürich A Low-Power CoAP for Contiki 3 ContikiMAC Radio on D Data frame A ACK frame Sender D Receiver Channel check Matthias Kovatsch – ETH Zürich D D D A D A Transmission detected A Low-Power CoAP for Contiki 4 Link-layer Bursts Radio on D Data frame A ACK frame Sender D Receiver Channel check Matthias Kovatsch – ETH Zürich D D D A D A D A D A D A D A D A D A Transmission detected A Low-Power CoAP for Contiki 5 Constrained Application Protocol (CoAP) RESTful Web services for networked embedded devices Idealized architectural style of the Web HTTP for the Internet of Things coap://sky2/ coap://sky1/ coap://sky3/ Matthias Kovatsch – ETH Zürich A Low-Power CoAP for Contiki 6 «Erbium» CoAP for Contiki Implements draft-ietf-core-coap-07 Available in the Contiki repository on SourceForge Matthias Kovatsch – ETH Zürich A Low-Power CoAP for Contiki 7 «Erbium» CoAP Reliable UDP transport Observing resources Blockwise transfers Resource discovery Separate responses Blocking client requests Matthias Kovatsch – ETH Zürich A Low-Power CoAP for Contiki 8 «Erbium» REST Engine CoRE Link Format title="Hello world"; rt="TemperatureC"; Resource abstraction RESOURCE(handle, METHODs, URI-Path, Web Linking info); Resource handler PERIODIC_RESOURCE(handle, METHODs, URI-Path, info, period); Additional periodic handler EVENT_RESOURCE(handle, METHODs, URI-Path, info); Additional event handler Observable Matthias Kovatsch – ETH Zürich A Low-Power CoAP for Contiki 9 «Erbium» Memory Footprint ROM [kB] RAM [kB] CoAP REST Engine total 8.5 1.5 Measured stack usage – 0.1 REST Engine 0.7 0 CoAP-07 base 4.5 0 CoAP-07 server 1.9 0.3 CoAP-07 transport 0.4 0.9 CoAP-07 observing 0.9 0.2 CoAP-07 separate 0.1 0 Matthias Kovatsch – ETH Zürich A Low-Power CoAP for Contiki 10 Experimental Set-up 4 hops Energy data over USB 100 Requests each 3 hops Static routing Laptop with border router 1 hop Matthias Kovatsch – ETH Zürich A Low-Power CoAP for Contiki 2 hops 11 No duty cycling ContikiMAC Energy vs Latency for 64B Payload 1.0 400 8 Hz channel check rate 0.6% RDC 300 Latency [s] Energy [mJ] 0.8 200 100 0.6 0.4 0.2 0 0 1 Matthias Kovatsch – ETH Zürich 2 3 4 Number of hops 1 A Low-Power CoAP for Contiki 2 3 4 Number of hops 12 4 hops 2 hops 1 hop Transmitting Large Data 70 2 65 3 4 5 6 1 .8 60 Bursts avoid steps in latency 1 .6 55 1 .4 50 1 .2 40 35 Steps become less noticable 30 25 Latency [s] Energy [mJ] 45 1 .0 0 .8 0 .6 20 15 0 .4 10 0 .2 5 0 0 128 256 384 512 0 Payload [Bytes] Matthias Kovatsch – ETH Zürich 0 128 256 384 512 Payload [Bytes] A Low-Power CoAP for Contiki 13 Transmitting Large Data Radio on D Data frame A ACK frame Sender D Receiver Channel check Matthias Kovatsch – ETH Zürich D D D A D A D A D A D A D AD A D A Transmission detected A Low-Power CoAP for Contiki 14 Separate Responses Client Server Client Server Request Request ACK Retry Request processing Request processing Retry … Response Benchmark and switch automatically Response ACK Matthias Kovatsch – ETH Zürich A Low-Power CoAP for Contiki 15 Without With Separate Responses over 4 Hops 150 Savings marginal Energy [mJ] 125 100 75 50 25 0 5 10 15 20 25 Server processing time [s] Matthias Kovatsch – ETH Zürich A Low-Power CoAP for Contiki 16 Conclusion Internet of Things stack Isolated layers with different goals work together Layered architecture lowers complexity Optimize for single fragments No need to optimize payload size once fragmented CoAP Draft 07 implementation for Contiki Block size most important parameter for memory-constrained devices: Exponential sizes too coarse-grained Matthias Kovatsch – ETH Zürich A Low-Power CoAP for Contiki 17 Future Work Extend «Erbium» CoAP Blocking resource handler for UART Hierarchical resources / URI-Path handling Improve observer handling (only one buffer) Study RESTful approach Long-term deployment with smart appliances Separate application logic from device firmware and combine with «Californium» App Server Matthias Kovatsch – ETH Zürich A Low-Power CoAP for Contiki 18 THANK YOU Questions? Matthias Kovatsch – ETH Zürich A Low-Power CoAP for Contiki 19 Radio Duty Cycling Current consumption (ca.) [mA] 25 20 15 10 5 0 CPU (normal/LPM) Matthias Kovatsch – ETH Zürich Radio (RX/TX) Flash (R/W/idle) A Low-Power CoAP for Contiki Sensors (tmp./PIR/acc.) LEDs 20 Constrained Application Protocol (CoAP) RESTful Web services for networked embedded devices Idealized architectural style of the Web Usually implemented with HTTP Central mechanisms coap://sky2/ Reliable UDP transport («confirmable») Group communication (IP multicast) Push notifications («observing») Resource discovery («CoAP link format») Larger data transport («blockwise transfers») coap://sky3/ Matthias Kovatsch – ETH Zürich A Low-Power CoAP for Contiki 21 Blockwise Transfers Automatic or controlled by handler RESOURCE(handle, METHODs, URI-Path, Web Linking info); Resource handler handle_handler(void* request, void* response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset); Unaware: fill buffer up to REST_MAX_CHUNK_SIZE Chunk-aware: use offset and fill buffer up to preferred_size (update offset and set to -1 when finished) Matthias Kovatsch – ETH Zürich A Low-Power CoAP for Contiki 22 Observing Resources Post-handler registers observers automatically PERIODIC_RESOURCE(handle, METHODs, URI-Path, info, period); Additional periodic handler EVENT_RESOURCE(handle, METHODs, URI-Path, info); Additional event handler int handle_event_handler(resource_t *r) { ... REST.notify_subscribers(r->url, CON/NON, seqno, buf, len); } Every x-th is CON to resolve orphans Matthias Kovatsch – ETH Zürich A Low-Power CoAP for Contiki 23 Erbium REST Engine Manipulate messages with REST API REST.set_header_etag(response, etag_buf, etag_len); REST.get_query_variable(request, name, value_buffer); Link implementation coap-03 coap-06 coap-07 … HTTP (not yet implemented for Erbium) Matthias Kovatsch – ETH Zürich A Low-Power CoAP for Contiki 24