CoAP · Study deck

CoAP Observe: Subscriptions and Updates

CoAP is a compact request-and-response protocol for constrained devices.

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

You will be able to:

  • Implement Server Push: Configure and build CoAP Observe for real-time notifications using RFC 7641
  • Design Observer Registries: Construct server-side data structures to manage registration, notifications, and deregistration lifecycle
  • Calculate Bandwidth Savings: Apply formulas to quantify Observe benefits over traditional polling for specific IoT scenarios
  • Diagnose Edge Cases: Identify and resolve NAT timeout, token reuse, and ghost observer problems in deployed systems
iotclass.org

Major section

Start With the Decision

CoAP is a compact request-and-response protocol for constrained devices.

  • Observe lets a client register interest in a resource.
  • An Observe relation records that registration; a notification is a later response carrying updated resource state.
  • A thermostat needs fresh changes, not a flood of copies after a link returns.
iotclass.org

Major section

In 60 Seconds

The useful result is a fresh change at the right pace, not merely an open subscription.

  • A protocol means the shared rules for a message exchange.
  • A broker means a service that receives and forwards named messages.
  • Telemetry means measured status sent from a device.
  • CoAP means Constrained Application Protocol, a compact system for small devices.

Key terms

MQTT
MQTT means Message Queuing Telemetry Transport, a broker-based system.

Why it matters

Observe can reduce request traffic when changes are infrequent; measure notification, registration, and recovery traffic before claiming a percentage saving.

iotclass.org

Major section

In 60 Seconds (continued)

MQTT means Message Queuing Telemetry Transport, a broker-based system.

  • Register one observer, change the value, lose a notification, reconnect, and remove the observer.
  • This runway does not prove every push design or energy saving.
  • CoAP Observe (RFC 7641) lets a client register interest in a resource and receive notifications of updated state.
iotclass.org

Major section

Start With the Quiet Thermostat

A thermostat does not need to ask a room sensor the same question every ten seconds when the temperature barely changes.

  • It needs one registration, then a trustworthy update only when the value crosses a meaningful boundary.
  • Observe is that subscription story for CoAP.
  • The chapter builds from the simple "tell me when it changes" promise into registries, notification pacing, cleanup, edge cases, and evidence that the push stream saves energy instead of creating a flood.
iotclass.org

Major section

Count Radio Wakes, Not Only Bytes

Idealised event-energy model; measure sleep current, retries, and cell behavior before predicting battery life.

  • The idealised cell ledger yields 563 polling days versus 3,361 Observe days.
  • The day counts are idealised projections.
  • Sleep current, retries, and cell behavior remain outside this estimate.
The 225 mAh cell at 3.0 volts stores 2,430 joules. In this idealised example, the daily energy values imply 563 days for polling and 3,361 days for Observe. These projections exclude sleep current, retries, and battery behavior; they are not deployment-life predictions.
iotclass.org

Major section

For Beginners: Understanding Observe vs Polling

You keep asking the same question over and over, even if the answer hasn't changed.

  • You ask once, then relax - they'll let you know when something changes.
  • Battery life: Every time a device sends a message, it uses power.
  • With Observe, you might only send 10 messages when values actually change.
Sequence diagram comparing CoAP polling (repeated GET requests) versus Observe pattern (single registration with change-driven notifications), showing reduced message exchange with Observe
Sequence diagram comparing CoAP polling (repeated GET requests) versus Observe pattern (single registration with change-driven notifications), showing reduced message exchange with Observe
iotclass.org

Major section

Putting Numbers to It

We can quantify the exact bandwidth savings.

  • Multiple clients can observe one resource, but each relationship needs its own retained state; the next sections trace registration and notification behavior inside that contract.
CoAP Observe state contract across client, wire, and server, including registry retention, ordering, failure ownership, and bounded acceptance evidence
CoAP Observe state contract across client, wire, and server, including registry retention, ordering, failure ownership, and bounded acceptance evidence
iotclass.org

Major section

Observe Protocol Flow

GET + Observe 0 + token → ordered notifications → RST or cancellation → reconcile and re-register.

  • Cancellation or relationship loss ends an observation.The client must re-register and reconcile the current resource value.
  • A client sends RST to stop an observation.The server removes the observer relationship associated with that request.
  • Notifications must belong to the live relationship.The client checks token and ordering before accepting an update.
CoAP Observe evidence lifecycle from registration through ordered notifications, cancellation or loss, and re-registration with reconciliation
CoAP Observe evidence lifecycle from registration through ordered notifications, cancellation or loss, and re-registration with reconciliation
iotclass.org

Major section

Putting Numbers to It

If 82°C is configured as an urgent alarm threshold, crossing it sends an immediate alarm notification even inside that 60-second interval.

  • where Δv=vnew−vlast\Delta v = v_{\text{new}} - v_{\text{last}}Δv=vnew​−vlast​ is the value change and Δt=tnow−tlast\Delta t = t_{\text{now}} - t_{\text{last}}Δt=tnow​−tlast​ is time since last notification.
  • Alarm handling is a separate path; routine updates retain the cap.
  • This dual-threshold policy caps the notification rate and ignores small changes.

Why it matters

The rate limiting logic above combines two thresholds to prevent notification storms.

iotclass.org

Deck summary

Key takeaways

CoAP is a compact request-and-response protocol for constrained devices.

  • The useful result is a fresh change at the right pace, not merely an open subscription.
  • MQTT means Message Queuing Telemetry Transport, a broker-based system.
  • A thermostat does not need to ask a room sensor the same question every ten seconds when the temperature barely changes.
  • If each wake-transmit-sleep cycle costs about 3.00 mJ, energy falls from 4.32 to 0.723 J/day, an 83.3% event-energy saving.
iotclass.org

Retrieval practice

Recall check 1 of 6

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

Q1A CoAP Observe design replaces polling for a fast-changing sensor. What evidence should be reviewed before accepting it?

APolling reduction only, with no lifecycle evidence
BNo deregistration path and unlimited notify bursts
CRegistration lifetime, pacing limits, and cleanup behavior
DFixed update-on-every-delta behavior for all sensors
Show answer

Answer: C CoAP Observe review should cover registration lifecycle, notification control, network state, and protocol trade-offs.

iotclass.org

Retrieval practice

Recall check 2 of 6

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

Q2A client sends GET /temperature with Observe: 0 and Token: 0xAB12. The server responds with Observe: 47. What does the value 47 in the server's response represent?

AThe number of registered observers currently tracking this resource
BA sequence value used to reject stale or out-of-order notifications
CThe Max-Age value in seconds before the observation expires
DThe port number the server will use to send future notifications
Show answer

Answer: B The Observe option value in server responses and notifications is a 24-bit sequence number (0 to 16,777,215).

iotclass.org

Retrieval practice

Recall check 3 of 6

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

Q3Complete the CoAP observe subscription for real-time updates:

Arequest = Message(code=GET, uri='coap://sensor.local/temp', observe=0)
Brequest = Message(code=OBSERVE, uri='coap://sensor.local/temp')
Crequest = Message(code=GET, uri='coap://sensor.local/temp', subscribe=True)
Drequest = Message(code=SUBSCRIBE, uri='coap://sensor.local/temp')
Show answer

Answer: A CoAP Observe uses observe=0 in the GET request to register for notifications.

iotclass.org

Retrieval practice

Recall check 4 of 6

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

Q4What information must the server store for each observer in the observer registry?

AClient IP only, leaving Token and resource identity out of registry.
BClient endpoint, Token, resource, and relevant GET options.
CClient password and PIN instead of subscription identity fields.
DComplete GET debug logs alone, without a bounded observer entry.
Show answer

Answer: B RFC 7641 identifies an observation by endpoint and token and associates it with a target resource and request options.

iotclass.org

Retrieval practice

Recall check 5 of 6

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

Q5A CoAP server has 100 clients observing a temperature resource that changes 10 times per second. It currently notifies every client on every change without pacing, and its measured delivery capacity is below 1,000 notifications per second. What problem should the team fix first?

ANo problem - servers can handle unlimited notifications
BClients will miss notifications - use CON instead of NON
CNotification flood - add rate limits and change thresholds
DMemory exhaustion - limit number of observers
Show answer

Answer: C Rate limits or change thresholds reduce unnecessary notifications below the measured capacity, while the design must still meet its freshness contract.

iotclass.org

Retrieval practice

Recall check 6 of 6

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

Q6A client restarts and rejects an old Observe notification with RST. What should the server do?

ATreat the RST as ACK and retain the obsolete observer entry.
BReuse the old Token for a restarted client without a new registration.
CRemove the old observer entry after its notification is rejected.
DKeep sending to the stale Token even after the client rejects it.
Show answer

Answer: C RST says this notification no longer belongs to a live observation.

iotclass.org

Print reference

Answers 1 of 2

Answer key.

  1. C · CoAP Observe review should cover registration lifecycle, notification control, network state, and protocol trade-offs.
  2. B · The Observe option value in server responses and notifications is a 24-bit sequence number (0 to 16,777,215).
  3. A · CoAP Observe uses observe=0 in the GET request to register for notifications.
  4. B · RFC 7641 identifies an observation by endpoint and token and associates it with a target resource and request options.
iotclass.org
With the answer frame visible, connect the checks. Register with G-E-T and Observe zero. Use the Observe sequence to reject old updates. Store the endpoint, token, resource, and relevant options for each observer. Pace a fast stream and remove a stale entry after reset. A new registration still needs current-state reconciliation.

Print reference

Answers 2 of 2

Answer key.

  1. C · Rate limits or change thresholds reduce unnecessary notifications below the measured capacity, while the design must still meet its freshness contract.
  2. C · RST says this notification no longer belongs to a live observation.
iotclass.org