CoAP · Study deck

CoAP API Design: Delivery and Security Decisions

A sleepy node may lose a confirmable message, one that asks for an acknowledgement, 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.
  • Protect the production exchange with DTLS (coaps://) or an appropriate OSCORE deployment.

Why it matters

Rate-limit requests (prevent DoS).

iotclass.org

Major section

Security Best Practices (continued)

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).
  • Validate input (prevent injection attacks).
  • 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

Common Pitfall: CoAP Observe Notification Flood (continued)

Max-Age communicates value validity, and client reset responses provide evidence that the notification policy needs review.

  • The mistake: Configuring a server to send Observe notifications on every minor resource change, overwhelming clients.
  • Client device becomes unresponsive or crashes.
  • Monitor client RST responses (may indicate an unrecognized notification or lost observation state).
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.
  • CoAP Max-Age itself is a response freshness option, not a client request option.

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.
  • Credential rotation and session limits remain separate operating responsibilities after the protected connection has been established.
  • An Observe server can overwhelm clients when notifications follow minor sensor changes without a separate delivery policy.
  • Max-Age communicates value validity, and client reset responses provide evidence that the notification policy needs review.
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, requesting acknowledgement for the consequential valve command.
BNON, meant for replaceable telemetry rather than valve control.
CUse NON because a short command payload makes delivery reliable.
DCON only after recasting the valve 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.

Q3What expresses a CoAP operation whose safety and idempotence affect retry behaviour?

AStable Resource URI
BContent-Format Option
CClass.Detail Response Code
DCoAP Request Method
Show answer

Answer: D GET, PUT, POST, or DELETE expresses the requested operation whose safety and idempotence shape retry behaviour.

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

Four API decisions

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. D · GET, PUT, POST, or DELETE expresses the requested operation whose safety and idempotence shape retry behaviour.
  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
1. A: confirmable delivery helps detect a missing acknowledgement. 2. D: resource access control restricts who may change state. 3. A: URI names the resource; method requests the operation; Content-Format labels representation bytes; response code reports outcome. 4. A: render_get handles the read. Pair the exchange with the reported valve state.