3. 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: PUT
URI: coap://scrc.com/
Value: PUT/resource/db/app1/sensor/temp/5afb?it=40004
CoAP methods (cont…)
PUT
Client Server
CON PUT/resource/db/…/?it=4404
ACK Changed 2.04
Update
4. 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: DELETE
URI: coap://scrc.com/
Value: DELETE/resource/db/app1/sensor/temp/value/
Client Server
CON DELETE/resource/db/app/sensor/temp/value/
ACK Deleted
De-register
CoAP methods (cont…)
DELETE
7. CoAP messages are encoded in a simple binary format.
The Message Header (4 bytes).
The variable-length token value 0 and 8 bytes long.
7
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
8. Caching
8
• CoAP includes a simple caching model
Cache ability determined by response code
An option number mask determines if it is a cache key
• Freshness model
Max-Age option indicates cache lifetime
• Validation model
Validity checked using the Etag Option
• A proxy often supports caching
Usually 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.
10. Observation
10
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
12. Getting Started with CoAP
12
• 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!
13. 13
Getting Started with CoAP (cont…)
https://en.wikipedia.org/wiki/Constrained_Application_Protocol
16. Discovery
16
• Service Discovery
What 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 Discovery
What are the Web resources I am interested in?
Goal of finding URIs
Performed using Web Linking or some REST interface
CoRE Link Format is designed to enable resource discovery
17. Discovery (cont…)
17
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
18. Add CoAP to your application
18
Initial demonstration step of CoAP
19. 19
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