33#ifndef DETERMINISTICESPASYNCWEBSERVER_COAP_H
34#define DETERMINISTICESPASYNCWEBSERVER_COAP_H
43enum class CoapType : uint8_t
52enum class CoapMethod : uint8_t
65 static constexpr uint8_t COAP_ALLOW_GET = 1u << (unsigned)CoapMethod::COAP_GET;
66 static constexpr uint8_t COAP_ALLOW_POST = 1u << (unsigned)CoapMethod::COAP_POST;
67 static constexpr uint8_t COAP_ALLOW_PUT = 1u << (unsigned)CoapMethod::COAP_PUT;
68 static constexpr uint8_t COAP_ALLOW_DELETE = 1u << (unsigned)CoapMethod::COAP_DELETE;
72#define COAP_CODE(c, dd) ((uint8_t)(((c) << 5) | ((dd) & 0x1F)))
75enum class CoapResponseCode : uint8_t
77 COAP_RSP_CREATED = COAP_CODE(2, 1),
78 COAP_RSP_DELETED = COAP_CODE(2, 2),
79 COAP_RSP_VALID = COAP_CODE(2, 3),
80 COAP_RSP_CHANGED = COAP_CODE(2, 4),
81 COAP_RSP_CONTENT = COAP_CODE(2, 5),
82 COAP_RSP_CONTINUE = COAP_CODE(2, 31),
83 COAP_RSP_BAD_REQUEST = COAP_CODE(4, 0),
84 COAP_RSP_BAD_OPTION = COAP_CODE(4, 2),
85 COAP_RSP_NOT_FOUND = COAP_CODE(4, 4),
86 COAP_RSP_METHOD_NOT_ALLOWED = COAP_CODE(4, 5),
87 COAP_RSP_NOT_ACCEPTABLE = COAP_CODE(4, 6),
88 COAP_RSP_REQUEST_INCOMPLETE = COAP_CODE(4, 8),
89 COAP_RSP_REQUEST_TOO_LARGE = COAP_CODE(4, 13),
90 COAP_RSP_INTERNAL_ERROR = COAP_CODE(5, 0),
91 COAP_RSP_NOT_IMPLEMENTED = COAP_CODE(5, 1),
95enum class CoapContentFormat : uint16_t
103 COAP_CF_NONE = 0xFFFF,
117 const uint8_t *payload;
119 CoapContentFormat content_format;
133 CoapContentFormat content_format;
140typedef void (*CoapHandler)(
const CoapRequest *req, CoapResponse *resp);
147void coap_server_init();
158bool coap_server_add_resource(
const char *path, uint8_t methods, CoapHandler handler);
178size_t coap_server_process(
const uint8_t *req,
size_t req_len, uint8_t *resp,
size_t resp_cap);
185size_t coap_server_process_ex(
const uint8_t *req,
size_t req_len, uint8_t *resp,
size_t resp_cap, int32_t observe_seq);
197void coap_server_begin_udp(uint16_t port = 5683);
199#if DETWS_ENABLE_COAP_OBSERVE
210void coap_notify(
const char *path);
User-facing configuration for DeterministicESPAsyncWebServer.