CoAP utils

The CoAP utils library is a simple module that enables communication with devices that support the CoAP protocol. It allows sending and receiving non-confirmable CoAP requests.

Overview

The library uses CoAP and BSD socket API.

After calling coap_init(), the library opens a socket for receiving UDP packets for IPv4 or IPv6 connections, depending on the ip_family parameter. At this point, you can start sending CoAP non-confirmable requests, to which you will receive answers depending on the server configuration.

Limitations

Currently, the library only supports the User Datagram Protocol (UDP) protocol.

Configuration

To enable the CoAP utils library, set the CONFIG_COAP_UTILS Kconfig option.

API documentation

Header file: include/net/coap_utils.h
Source files: subsys/net/lib/coap_utils/
group coap_utils

Functions

void coap_init(int ip_family, struct sockaddr *addr)

Open socket and start the receiving thread.

Parameters
  • [in] ip_family: Network ip protocol family (AF_INET or AF_INET6).

  • [in] addr: Local address to bind for receiving data. Pass NULL pointer if no address is provided.

int coap_send_request(enum coap_method method, const struct sockaddr *addr, const char *const *uri_path_options, uint8_t *payload, uint16_t payload_size, coap_reply_t reply_cb)

Send CoAP non-confirmable request.

Parameters
  • [in] method: CoAP method type.

  • [in] addr: pointer to socket address struct for IPv6.

  • [in] uri_path_options: pointer to CoAP URI schemes option.

  • [in] payload: pointer to the CoAP message payload.

  • [in] payload_size: size of the CoAP message payload.

  • [in] reply_cb: function to call when the response comes.

Return Value
  • >=: 0 On success.

  • <: 0 On failure.