Download - COAP
Constrained Application Protocol
Sachin Bang
Internet of things (IoT)• A scenario in which objects, animals or people are provided
with unique identifiers and the ability to transfer data over a network without requiring human-to-human or human-to-computer interaction. Gartner predicts there will be 26 billion connected devices by the end of 2020.
Challenges- Internet Engineering Task Force • To standardize a communication methodology for machines to
independently exchange information with each other, keeping in mind, that they want to build on and leverage existing knowledge and infrastructure, they wanted to address the following challenges:
1. Able to leverage existing IP infrastructure 2. Allow communication for a large number of machines on the “Internet” 3. Enable small size machines to communicate ensuring commercial viability of solution.4. Find a way to easily leverage the existing HTTP based investments.
Constrained Application ProtocolSolution• A “lightweight HTTP”, something that does not require too much
processing power and can be used by tiny devices.
• CoAP defines the message format (arrangement of bytes) and message exchange rules between two or more participating “Things”. Given its simplicity, it is also easier to implement CoAP based systems on small embedded hardware.
• One of the best things about CoAP is that it closely resembles HTTP and it is therefore very easy to convert from one format to other.
CoAP concept diagram
More about CoAP
• Constrained Application Protocol is a protocol at the application level that is designed to allow message exchange between resource constrained devices over resource constrained networks.
• Resource constrained devices are small devices that lack the processing power, memory footprint and speed , that we generally expect, from our computing devices.
More about CoAP
• CoAP uses the REST model. This is largely HTTP, with some modifications. Specific meanings of the four REST commands are slightly different from their HTTP meanings.
• It runs over UDP (User Datagram Protocol), which has no delivery guarantees. This is where the REST nature can be useful.
• Messages can optionally be marked as “confirmable” if you want an acknowledgment of receipt
• Compact 4-byte Header• Uses Datagram Transport Layer Security (DTLS) security which
is a derivation of SSL protocol. – It provides the same security services (integrity, authentication &
confidentiality) under UDP protocol.
CoAP Request/Response Messaging Model
There are 4 message types. • CON – This represents a confirmable message. A confirmable
message requires a response, either a positive or a negative acknowledgement. In case ack. is not received, retransmissions are made until all attempts are exhausted. NON – This represents a non-confirmable message. This is used for unreliable transmission (Even if one value is missed, there is not too much impact). Such a message is generally not acknowledged.
• ACK – This represents an acknowledgement. It is sent to acknowledge a confirmable (CON) message.
• RST – This represents a negative ack. and means “Reset”. It generally indicates, some kind of failure.
Exchanging Large Payloads using Block Transfer
• While CoAP is designed for small exchanges, sometimes it might become necessary to exchange bigger loads. This is made possible by a concept called “Block Transfer”.
• Client can send large data sets in smaller chunks over multiple calls to the server or client can get a large dataset from the server in small chunks .
CoAP Client and Server
• In the figure above, the server exposes the interface to query the temperature as a RESTful URL with the path as “sensors/temperature”.
• There is also a secure version, just like https, you can use coaps. • In the figure above, the full path provides the scheme name, the
DNS name, the port number and the path. Default port suggested for CoAP is 5683. Communication will use UDP and not TCP.
• Client needs to establish a UDP connection with the server, send a GET request to the server over the given URL path and get a response.
• The specification allows for various response/content formats e.g. JSON, XML & plain text.
Applications of CoAP • Wearables and smart connected devices for medical,
fitness, security, safety • Real Time Condition Based Monitoring in SmartGrid • Building Automation • Aircraft and Defense Equipment • Factory Instrumentation • Energy management systems• Smart farming• Smart city - transportation ,parking and traffic, street
lighting, waste disposal and environmental quality
CoAP Implementation
• Java Script – https://github.com/mcollina/node-coap– Max packet size is 1280(blockwise is not supported)
• Android– http://people.inf.ethz.ch/mkovatsc/californium.php
• IOS – https://github.com/stuffrabbit/iCoAP
• .NET– http://www.coapsharp.com/ (VS Studio .net micro
framework)– https://github.com/smeshlink/CoAP.NET
Questions ?
• Thank you for your time!