Zephyr API Documentation
3.5.0
A Scalable Open Source RTOS
|
|
3.5.0 |
CoAP client API. More...
Data Structures | |
struct | coap_client_request |
Representation of a CoAP client request. More... | |
struct | coap_client_option |
Representation of extra options for the CoAP client request. More... | |
Macros | |
#define | MAX_COAP_MSG_LEN |
Typedefs | |
typedef void(* | coap_client_response_cb_t) (int16_t result_code, size_t offset, const uint8_t *payload, size_t len, bool last_block, void *user_data) |
Callback for CoAP request. | |
Functions | |
int | coap_client_init (struct coap_client *client, const char *info) |
Initialize the CoAP client. | |
int | coap_client_req (struct coap_client *client, int sock, const struct sockaddr *addr, struct coap_client_request *req, int retries) |
Send CoAP request. | |
CoAP client API.
#define MAX_COAP_MSG_LEN |
#include <zephyr/net/coap_client.h>
coap_client_response_cb_t |
#include <zephyr/net/coap_client.h>
Callback for CoAP request.
This callback is called for responses to CoAP client requests. It is used to indicate errors, response codes from server or to deliver payload. Blockwise transfers cause this callback to be called sequentially with increasing payload offset and only partial content in buffer pointed by payload parameter.
result_code | Result code of the response. Negative if there was a failure in send. coap_response_code for positive. |
offset | Payload offset from the beginning of a blockwise transfer. |
payload | Buffer containing the payload from the response. NULL for empty payload. |
len | Size of the payload. |
last_block | Indicates the last block of the response. |
user_data | User provided context. |
int coap_client_init | ( | struct coap_client * | client, |
const char * | info | ||
) |
#include <zephyr/net/coap_client.h>
Initialize the CoAP client.
[in] | client | Client instance. |
[in] | info | Name for the receiving thread of the client. Setting this NULL will result as default name of "coap_client". |
int coap_client_req | ( | struct coap_client * | client, |
int | sock, | ||
const struct sockaddr * | addr, | ||
struct coap_client_request * | req, | ||
int | retries | ||
) |
#include <zephyr/net/coap_client.h>
Send CoAP request.
Operation is handled asynchronously using a background thread. If the socket isn't connected to a destination address, user must provide a destination address, otherwise the address should be set as NULL. Once the callback is called with last block set as true, socket can be closed or used for another query.
client | Client instance. |
sock | Open socket file descriptor. |
addr | the destination address of the request, NULL if socket is already connected. |
req | CoAP request structure |
retries | How many times to retry or -1 to use default. |