CoAP · Study deck

CoAP API Design: Delivery and Security Decisions

A sleepy node may lose a confirmable message or repeat a command.

Broker Bex is your guide for this deck.

iotclass.org

After studying this chapter

Learning objectives

You will be able to:

  • Explain: The selection depends on criticality and update timing rather than using the same exchange policy for both valve commands and routine temperature reports.
  • Explain: An HTTP-to-CoAP proxy can return stale readings when one cache policy is applied to clients with different freshness needs.
  • Explain: The Mistake: HTTP-to-CoAP proxy aggressively caches based on Max-Age without considering that freshness requirements vary by use case.
  • Explain: Repeated wakeups consume battery energy, while excessive traffic can make a client unresponsive and produce repeated reset responses.
iotclass.org

Major section

Message Type Selection

Confirmable messages support failure detection for actuator commands, configuration changes, and important alerts.

  • The selection depends on criticality and update timing rather than using the same exchange policy for both valve commands and routine temperature reports.
  • Configuration changes.
  • Any operation where failure must be detected.
  • If no, ask whether the data will be sent again soon.
iotclass.org

Major section

Security Best Practices

A protected CoAP service combines transport protection with controls on resource access and request behavior.

  • DTLS protects the transport path, while access control decides which clients may use particular resources.
  • Input validation and rate limits address malformed or excessive requests that encryption alone does not resolve.
  • [ ] Use DTLS (coaps://) not plain CoAP (coap://).
  • [ ] Validate input (prevent injection attacks).

Why it matters

[ ] Rate-limit requests (prevent DoS).

iotclass.org

Major section

Security Best Practices (continued)

[ ] Rate-limit requests (prevent DoS).

  • Credential rotation and session limits remain separate operating responsibilities after the protected connection has been established.
  • [ ] Implement access control (not all clients can access all resources).
  • [ ] Use short session timeouts (minimize exposure).
  • Token bucket algorithm (allow bursts, limit sustained rate).
iotclass.org

Major section

Common Pitfall: CoAP Observe Notification Flood

An Observe server can overwhelm clients when notifications follow minor sensor changes without a separate delivery policy.

  • Repeated wakeups consume battery energy, while excessive traffic can make a client unresponsive and produce repeated reset responses.
  • A minimum notification interval and a meaningful change threshold separate sensor sampling from useful notification delivery.
  • Client sends RST messages repeatedly.
iotclass.org

Major section

Pitfall: HTTP-CoAP Proxy Caching Stale Data

An HTTP-to-CoAP proxy can return stale readings when one cache policy is applied to clients with different freshness needs.

  • Max-Age describes a validity interval, but that interval must still fit the receiving use case.
  • The Mistake: HTTP-to-CoAP proxy aggressively caches based on Max-Age without considering that freshness requirements vary by use case.
  • Key principle: Safety-critical clients should always request fresh data (max-age=0).

Why it matters

Per-client cache control allows the proxy to distinguish routine reuse from a request that needs fresh evidence.

iotclass.org

Deck summary

Key takeaways

Confirmable messages support failure detection for actuator commands, configuration changes, and important alerts.

  • A protected CoAP service combines transport protection with controls on resource access and request behavior.
  • [ ] Rate-limit requests (prevent DoS).
  • An Observe server can overwhelm clients when notifications follow minor sensor changes without a separate delivery policy.
  • An HTTP-to-CoAP proxy can return stale readings when one cache policy is applied to clients with different freshness needs.
iotclass.org

Retrieval practice

Recall check 1 of 2

Broker Bex says: answer from memory, then check your reasoning.

Q1A CoAP client sends a valve command and must detect delivery failure. Which message type fits?

ACON for confirmable delivery
BNON for superseding telemetry
CNON because the command payload is short
DCON only after treating the command as routine telemetry
Show answer

Answer: A The section selects CON for actuator commands and detected failure.

Q2A CoAP service uses protected transport but lets any client modify resources. Which control is missing?

AA shorter sensor sampling interval
BA different payload display format
CA larger response buffer
DResource access control
Show answer

Answer: D The checklist separately requires permission checks for resource access.

iotclass.org

Retrieval practice

Recall check 2 of 2

Broker Bex says: answer from memory, then check your reasoning.

Q3Place each CoAP API contract element where it lives so you can request the right resource and interpret its compact response without HTTP assumptions.

AStable Resource URI
BContent-Format Option
CSafe CoAP Method
DClass.Detail Response Code
Show answer

Answer: A Place each CoAP API contract element where it lives so you can request the right resource and interpret its compact response without HTTP assumptions.

Q4Complete the CoAP resource endpoint with content format:

Aasync def render_get(self, request):
Bdef handle_get(self, request):
Casync def get(self, request):
Dasync def on_get(self, request):
Show answer

Answer: A CoAP server resources extend aiocoap.resource.Resource and implement render_get/render_put/render_post methods. Responses use CoAP response codes like CONTENT (2.05). Payloads must be bytes, so strings need .encode().

iotclass.org

Print reference

Answers

Answer key.

  1. A · The section selects CON for actuator commands and detected failure.
  2. D · The checklist separately requires permission checks for resource access.
  3. A · Place each CoAP API contract element where it lives so you can request the right resource and interpret its compact response without HTTP assumptions.
  4. A · CoAP server resources extend aiocoap.resource.Resource and implement render_get/render_put/render_post methods. Responses use CoAP response codes like CONTENT (2.05). Payloads must be bytes, so strings need .encode().
iotclass.org