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
include/net/coap_utils.h
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:
ip_family – [in] Network IP protocol family (AF_INET or AF_INET6).
addr – [in] 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:
method – [in] CoAP method type.
addr – [in] pointer to socket address struct for IPv6.
uri_path_options – [in] pointer to CoAP URI schemes option.
payload – [in] pointer to the CoAP message payload.
payload_size – [in] size of the CoAP message payload.
reply_cb – [in] function to call when the response comes.
- Return values:
>= – 0 On success.
< – 0 On failure.
-
void coap_init(int ip_family, struct sockaddr *addr)