Tutorial: CoAP - simonduq/contiki-ng GitHub Wiki

This tutorial will show you how to set up a Contiki-NG node that runs a CoAP server as well as a shell client (see doc:coap).

Let us use the example under examples/coap/coap-examples-server. Add the shell (insert MODULES += os/services/shell in the Makefile and then run make distclean). Compile the example and program your device with it. Team up with someone who is also at this stage, so that you can interact with their CoAP device.

$ make coap-example-server.upload PORT=/dev/ttyUSB0

CoAP nodes expose a list of their resources under .well-known/core. We will use the shell to query a node from another one. From one of the node's shell interface, try:

> coap get coap://[fd00::212:4b00:14b5:ee9a]:5683 .well-known/core
Performing CoAP request to fd00::212:4b00:14b5:ee9a
CoAP request sent
CoAP response code: 69, payload: '</.well-known/core>;ct=40,</test/hello>;title="Hello world: ?len'
CoAP response code: 69, payload: '=0..";rt="Text",</debug/mirror>;title="Returns your decoded mess'
CoAP response code: 69, payload: 'age";rt="Debug",</test/chunks>;title="Blockwise demo";rt="Data",'
CoAP response code: 69, payload: '</test/separate>;title="Separate demo",</test/push>;title="Perio'
CoAP response code: 69, payload: 'dic demo";obs,</sensors/button>;title="Event demo";obs,</test/su'
CoAP response code: 69, payload: 'b>;title="Sub-resource demo",</test/b1sepb2>;title="Block1 + Sep'
CoAP response code: 69, payload: 'arate + Block2 demo"'
CoAP request done.

The output is not parsed by the node here, but you can see a list of resources. For instance, test/hello, or sensors/button. Try requesting these.

⚠️ **GitHub.com Fallback** ⚠️