CoAP Response Code Meaning Misunderstood
DodaTech
Updated 2026-06-26
1 min read
In this tutorial, you'll learn about CoAP Response Code Meaning Misunderstood. We cover key concepts, practical examples, and best practices to help you understand and apply this topic effectively.
The Problem
CoAP response code does not match the expected semantics (e.g., using 2.05 for empty body).
Quick Fix
Wrong
res.code = '2.05'; // Content — but no payload sent
res.end();```
Client confused: 2.05 Content with no payload. Should use 2.03 Valid.
### Right
```cpp
#include <coap.h>
void get_handler(coap_context_t *ctx, coap_resource_t *res,
coap_session_t *session, coap_pdu_t *request,
coap_binary_t *token, coap_string_t *query,
coap_pdu_t *response) {
// 2.05 Content — has payload
unsigned char buf[] = "temperature data";
coap_pdu_set_code(response, COAP_RESPONSE_CODE_CONTENT);
coap_add_data(response, sizeof(buf) - 1, buf);
}
void check_handler(coap_context_t *ctx, coap_resource_t *res,
coap_session_t *session, coap_pdu_t *request,
coap_binary_t *token, coap_string_t *query,
coap_pdu_t *response) {
// 2.03 Valid — no payload, just validation
coap_pdu_set_code(response, COAP_RESPONSE_CODE_VALID);
}```
/gets: 2.05 Content with data. /check: 2.03 Valid with no body.
## Prevention
CoAP response codes are three-digit: 2.XX (Success), 4.XX (Client Error), 5.XX (Server Error). Key codes: 2.01=Created, 2.02=Deleted, 2.03=Valid (no body), 2.04=Changed, 2.05=Content (has body). 4.00=Bad Request, 4.01=Unauthorized, 4.04=Not Found, 4.05=Method Not Allowed. 5.00=Internal Server Error, 5.01=Not Implemented, 5.02=Bad Gateway, 5.03=Service Unavailable.
DodaTech engineers apply these same patterns across Doda Browser, DodaZIP, and Durga Antivirus Pro for production IoT reliability.
## FAQ
<details style="margin-bottom:12px;border:1px solid #e2e8f0;border-radius:10px;overflow:hidden"><summary style="cursor:pointer;padding:14px 18px;font-weight:600;font-size:1.05rem;background:#f8fafc;border-bottom:1px solid #e2e8f0;color:#1e293b">### 2.03 Valid vs 2.05 Content?</summary><div style="padding:14px 18px;color:#475569;line-height:1.7;background:#fff"><p>2.03 Valid = success, no payload (e.g., ETag validation). 2.05 Content = success with response payload.</p>
<h3 id="404-vs-405">4.04 vs 4.05?</h3><p>4.04 Not Found = resource doesn't exist. 4.05 Method Not Allowed = resource exists but method not supported.</p>
<h3 id="what-code-for-server-error">What code for server error?</h3><p>5.00 Internal Server Error. 5.01 Not Implemented (method not supported by server). 5.02 Bad Gateway (proxy error). 5.03 Service Unavailable (temporary overload).</p>
</div></details>
← Previous
CoAP Resource Discovery Returns 4.04 Not Found
Next →
CoAP DTLS Handshake Fails — Complete Guide
Built by the developers of DodaTech
Doda Browser, DodaZIP & Durga Antivirus Pro