CoAP TCP Client

Browse source code on GitHub

Overview

This sample demonstrates how to use the CoAP over TCP client API to communicate with a CoAP server using reliable transports as specified in RFC 8323.

This demo assumes that the platform of choice has networking support, some adjustments to the configuration may be needed.

The sample shows:

  • Connecting to a CoAP TCP server

  • Waiting for CSM exchange completion using event callbacks

  • Sending GET requests over TCP

  • Using Ping/Pong signals with event-based waiting

  • Graceful session release

  • Event callback for server signals (Release, Abort)

Requirements

Building and Running

The easiest way to run this sample application is to build and run it as a native_sim application. Some setup is required as described in Networking with native_sim board.

A CoAP server with TCP support must be running on the host. Using aiocoap:

python -m pip install "aiocoap[all]"
mkdir file_root
echo "Hello from CoAP TCP!" > file_root/test
aiocoap-fileserver --bind "coap+tcp://[::]:5683" file_root

Launch net-setup.sh in net-tools:

./net-setup.sh

Build and run the sample:

west build -b native_sim samples/net/sockets/coap_client_tcp
west build -t run

Configuration

The server address and port can be modified via Kconfig and in src/main.c:

The following Kconfig options are relevant:

See Also

See also

COAP Library
CoAP TCP client API