CoAP · Study deck

CoAP Observe: Efficiency and Lifecycle

A network address translator (NAT) may let an idle UDP mapping expire before the next change reaches an observer, a client waiting for sensor changes.

Broker Bex is your guide for this deck.

observe
Broker Bex, the module guide, in a scene from this chapter.
iotclass.org

After studying this chapter

Learning objectives

Keep network path, notification freshness, and observer state under review.

  • Decide when Observe beats polling.
  • Measure notification rate and radio wakes; size keep-alives from measured NAT lifetime.
  • Match tokens after restart and honor Max-Age freshness.
  • Clean up ghost observers; treat battery quotients as model outputs.
iotclass.org

Major section

Start With the Decision

A network address translator (NAT) may let an idle UDP mapping expire before the next change reaches an observer, a client waiting for sensor changes.

  • A keep-alive is a small message sent to keep that path open.

Weigh its cost against making a new connection.

iotclass.org

Major section

Worked Example: Industrial Vibration Monitoring with Observe

Maintenance dashboard needs real-time updates when vibration exceeds thresholds (normal: <2.5 mm/s, warning: 2.5-4.5 mm/s, critical: >4.5 mm/s).

  • Critical alarm crossings bypass the routine 60-second cap, so alerts have no polling delay.

Why it matters

Server-side rate limiting prevents notification floods.

Scenario: A manufacturing plant monitors vibration levels on 100 motors using ESP32 sensors with accelerometers.

iotclass.org

Major section

Common Mistake: Forgetting to Handle Observer Cleanup After Client Crashes

The Error: Server registers Observe subscriptions but never removes them when clients crash or restart, leading to "ghost observers" that consume memory and network bandwidth sending notifications to unreachable clients.

  • When a client crashes and restarts, it may generate a new token.

The Error: Server registers Observe subscriptions but never removes them when clients crash or restart, leading to "ghost observers" that consume memory and network bandwidth sending notifications to unreachable clients.

iotclass.org

Major section

Common Mistake: Forgetting to Handle Observer Cleanup After Client Crashes (continued)

The server can continue sending notifications to the old token; if the restarted client receives an unrecognized notification, it can reject it with RST.

  • CON notification failures (retry limit):: This is transport pseudocode: send_datagram_once sends exactly one datagram and does not perform library-managed retransmission.
  • Use CON notifications (not NON) so you detect unreachable clients.
  • Use at most four retransmissions after the original CON send (RFC 7252 default).
iotclass.org

Major section

Checkpoint: Failure Modes

You now know unknown tokens after a restart should trigger RST cleanup rather than silent drops.

  • You now know UDP NAT mapping lifetimes vary, so quiet Observe streams may need client-originated keep-alives or re-registration.
  • You now know RST and failed CON delivery remove ghost observers; an optional server lease is separate from Max-Age freshness.
iotclass.org

Major section

1. Using Confirmable Messages for Every CoAP Request

CON messages require an ACK exchange.

  • With RFC 7252 defaults, four retransmissions occur after randomized waits totaling 30–45 seconds; the final acknowledgement wait can extend failure detection to 62–93 seconds, regardless of any fixed packet-loss percentage.

Use NON for periodic telemetry where data freshness matters more than guaranteed delivery; reserve CON for actuation commands.

iotclass.org

Major section

Hands-On Practice

Exercise 2: Bandwidth Calculation: A smart building has 200 temperature sensors, each observed by 3 clients (dashboard, HVAC controller, alarm system).

  • Sensors report every time temperature changes by 0.5°C.
  • Estimated notifications per hour (assuming 2 significant changes per sensor per hour).
iotclass.org

Major section

Checkpoint: Evidence Before Selection

You now know the chapter's 100-observer example can show 99% bandwidth reduction when changes are infrequent.

  • You now know the vibration example's 772-day polling figure is a transmit-only charge quotient, and its Observe quotient is much larger under the same assumptions.

- You now know the chapter's 100-observer example can show 99% bandwidth reduction when changes are infrequent.

iotclass.org

Deck summary

Key takeaways

A network address translator (NAT) may let an idle UDP mapping expire before the next change reaches an observer, a client waiting for sensor changes.

  • Maintenance dashboard needs real-time updates when vibration exceeds thresholds (normal: <2.5 mm/s, warning: 2.5-4.5 mm/s, critical: >4.5 mm/s).
  • The Error: Server registers Observe subscriptions but never removes them when clients crash or restart, leading to "ghost observers" that consume memory and network bandwidth sending notifications to unreachable clients.
  • You now know unknown tokens after a restart should trigger RST cleanup rather than silent drops.
  • CON messages require an ACK exchange.
iotclass.org

Retrieval practice

Recall check 1 of 4

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

Q1A measured NAT mapping lasts forty seconds. The chosen safety fraction is three quarters. What keep-alive interval follows the chapter’s rule?

AThirty seconds, three quarters of the observed 40-second mapping.
BTen seconds, one quarter of the mapping rather than three quarters.
CForty seconds, the full mapping lifetime with no safety fraction.
DAbout fifty-three seconds, dividing forty by the safety fraction.
Show answer

Answer: A Forty seconds multiplied by three quarters gives a thirty-second interval, before mapping expiry.

Q2A client refreshes 30 NAT mappings every 30 seconds. How many refresh datagrams does it send per minute?

A1 datagram per minute
B900 datagrams per minute
C60 datagrams per minute
D30 datagrams per minute
Show answer

Answer: C Each mapping needs a refresh each interval.

iotclass.org

Retrieval practice

Recall check 2 of 4

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

Q3A CoAP client behind NAT registered for temperature updates. A gateway trace shows its UDP mapping expired during two minutes of inactivity; the client is still running and the next server notification cannot reach it. What happened and what is the direct recovery policy?

AThe client crashed - implement automatic restart
BNAT mapping expired; use keep-alives.
CServer bug - increase the notification buffer size
DNetwork congestion - switch to TCP for reliable delivery
Show answer

Answer: B NAT mappings expire without traffic.

Q4A smart thermostat app wants to receive temperature updates whenever the value changes, without polling. Which CoAP feature enables this?

ABlockwise transfer for streaming large payloads
BMulticast messaging to all subscribers
CObserve extension allowing server-push notifications
DSeparate response mode for async replies
Show answer

Answer: C The Observe extension (RFC 7641) enables pub/sub-like behavior: client registers once, server pushes changes automatically.

iotclass.org

Retrieval practice

Recall check 3 of 4

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

Q5An Observe sensor now sends a push for every tiny change. What should the review compare before claiming an energy saving?

AJudge energy from one notification byte count and ignore radio wakes.
BCompare only the number of subscribers without traffic timing.
CCompare only the latest dashboard value without radio current.
DCompare push notices, wakes, and restarts against polling cost.
Show answer

Answer: D Frequent pushes and recovery can erase the expected traffic and wake savings.

iotclass.org

Retrieval practice

Recall check 4 of 4

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

Q6What removes a CoAP observer when it no longer wants or can receive updates?

ARegister with GET + Observe
BSequence Each Notification
CCancel and Clean Up
DHonor Max-Age Freshness
Show answer

Answer: C RST, an explicit cancel, or server timeout removes an observer that no longer wants or can receive updates.

iotclass.org

Print reference

Answers

Answer key.

  1. A · Forty seconds multiplied by three quarters gives a thirty-second interval, before mapping expiry.
  2. C · Each mapping needs a refresh each interval.
  3. B · NAT mappings expire without traffic.
  4. C · The Observe extension (RFC 7641) enables pub/sub-like behavior: client registers once, server pushes changes automatically.
  5. D · Frequent pushes and recovery can erase the expected traffic and wake savings.
  6. C · RST, an explicit cancel, or server timeout removes an observer that no longer wants or can receive updates.
iotclass.org
Q1: A — 30 seconds. Q2: C — 60 refreshes per minute. Q3: B — inspect the expired network address translator mapping. Q4: C — Observe. Q5: D — compare total wake and recovery traffic. Q6: C → A → D → B — register, sequence, freshness, cleanup. Reveal each after five seconds; retain the full print key.