Register
GET with Observe = 0. Server replies 2.05 Content plus an Observe option (starting sequence number).
Progress saves as you read. Mark sections complete as you go; your progress appears in the sidebar.
Related reference: CoAP message types.
A wall display receives a room temperature and then loses its connection. A green tile without a freshness warning can imply that the room is still being watched. An Observe client needs a freshness decision even when the value itself has not changed.
A room display observes /sensors/temp. At elapsed time 100 s, it accepts a temperature notification with Max-Age: 30. If no newer response renews freshness, the allowance ends at 130 s. At 131 s the screen can retain the last value for context, but this example’s display policy marks it stale and the current temperature unknown.
CoAP is a request/response protocol for small devices. Its Observe extension lets a client request later representations, meaning encoded resource states, without sending a new request for every update. An observation is that continuing request relationship. A notification is a response carrying an update within it.
Your task is to decide which updates this display may use. Check three things in order: does the update belong to this observation, is it newer than the accepted representation, and is that representation still fresh? A delivered packet cannot establish sensor accuracy or the physical sample time.
Work through the registration below, then carry the same display through silence and reordered updates. Use the tank-level case to transfer the rule to another resource.
After this page, you should be able to:
Observe: 0 through token-bound notifications and cancellation.CoAP Observe Server Push introduces change-driven notifications. Here the question is whether a particular notification may update a display. Keep the request identity, ordering decision, freshness deadline and recovery action together in the trace.
Use this record wherever a last-known value might be mistaken for a current one. The record supports a freshness decision; application requirements still determine what action follows an unknown state.
The room display sends GET /sensors/temp with Observe: 0 and Token 0x4a01. A Token is the request identifier echoed in responses from that server endpoint, meaning its network address and port. In this illustrative trace, the server returns 2.05 Content, a successful response containing the representation, with Observe 12 and Max-Age: 60. The response's Observe option establishes that the server accepted the observation; sending the GET alone does not.
Fourteen seconds later, a notification arrives from that endpoint with Token 0x4a01, a new Message ID, and Observe 13. Match endpoint and Token first. The Message ID supports message-level duplicate detection and acknowledgement matching; it does not identify the continuing observation. Reserve the Token while the observation remains active.
This is the Observe extension described by RFC 7641. The Observe option, numbered 6, requests registration when set to 0 in a GET and carries an ordering sequence in accepted responses. The server associates the client endpoint and Token with the requested resource. To cancel explicitly, send GET with Observe: 1, the same Token and the other request options of that observation. A client can also end it by rejecting a Confirmable notification with a Reset message, abbreviated RST.
Locate Observe among the message types and request methods in the figure in the parent chapter. Use the worked exchange above to identify the registration and its notifications by endpoint and Token.
Use the figure in the parent chapter as a message-type overview. In the trace above, the Token answers which observation the response belongs to; the Observe value answers which representation is newer. Neither field supplies the freshness deadline.
GET with Observe = 0. Server replies 2.05 Content plus an Observe option (starting sequence number).
Updates carry the registration Token and an Observe ordering value, which can wrap around.
Cancel with GET Observe = 1 using the same Token and request options, or reject a Confirmable notification with RST.
Match the server endpoint and reserved Token before considering an update for this observation.
Return to the room display's notification at 100 s with Max-Age: 30. Max-Age is the response's freshness lifetime in seconds. At 125 s, five seconds remain; at 131 s, the representation is stale if no accepted response renewed it. This example's policy marks the tile unknown and attempts to refresh the observation with GET and Observe: 0. Staleness does not establish whether the server failed or the room changed.
Observe follows changing state; it does not deliver a durable history of every transition. A Non-confirmable notification, abbreviated NON, needs no acknowledgement. A Confirmable notification, abbreviated CON, requests an acknowledgement, abbreviated ACK, and can be retransmitted. Later communication can restore a current representation after loss, but permanent loss cannot guarantee convergence. Even an active server cannot guarantee that a notification reaches the display before expiry.
Freshness and reachability are separate. Periodic CON notifications let the server check whether the observer still responds. If a CON exchange exhausts retransmissions without an ACK, the server removes the observer. That outcome shows failed communication, not a diagnosis of the client or network. A network address translation (NAT) binding, the router's mapping for the client's traffic, is one possible point of failure.
Transfer example. A gateway observes /tank/level. Suppose its chosen policy sends an update on a 2% level change or after 60 seconds, with Max-Age: 120. These are illustrative settings, not recommended limits. If no accepted update arrives during that freshness lifetime, mark the level stale and attempt renewal. Record the CON schedule separately; a failed reachability check cannot extend freshness. When changes arrive faster than the transmission budget, coalescing means combining them into an update containing the latest state. Compare trace counts with the polling alternative before claiming traffic savings.
The display accepts Observe 120, then receives 124 within a short interval. The small forward difference makes 124 newer. If 122 arrives two seconds later, keep 124. User Datagram Protocol (UDP), the datagram transport used here, can deliver packets out of order; arrival time alone would let an older representation overwrite the newer one.
The Observe option carries a sequence value up to 24 bits wide. It orders representations rather than counting events delivered to the client. Because the value wraps back to the low end of its range, compare it with the windowed rule attributed to RFC 7641 below.
Let V1 be the value of the notification the client currently accepts, received at time T1, and V2 the value of a newly arrived notification at time T2. The new notification is treated as fresher only if (V1 < V2 and V2 − V1 < 2^23) or (V1 > V2 and V1 − V2 > 2^23) — the two cases that correctly handle counter wraparound — or if more than 128 seconds have elapsed (T2 > T1 + 128 s), after which the later arrival simply wins regardless of value. If all three tests fail, do not replace the accepted representation or renew its freshness from that update. Message-level handling, including acknowledgement of a recognized CON message, remains separate.
Now apply the same rule across wraparound: 16777214 followed shortly by 1 passes the second comparison because the reverse difference exceeds 2^23. Accept 1 as newer. If more than 128 seconds have passed since the accepted notification, the third comparison permits the later arrival regardless of the numeric difference. Exactly 128 seconds does not satisfy that time test; evaluate the other comparisons.
This is why the Observe value must be read as a reordering sequence number, not as a reliable event counter. Lost Non-confirmable notifications mean the numbers a client sees can skip; a sequence gap is not a count of missed physical events, and later convergence requires communication to resume.
Up to 24 bits, used with elapsed time to compare notification order; not a delivered-event count.
The 2^23 threshold distinguishes a genuine increment from a wrapped-around older value.
After more than 128 s since the accepted notification, the time test permits the later arrival.
A notification failing all ordering tests must not replace the accepted representation; handle its message type separately.
Apply the whole decision to the room display again. It receives an accepted notification at 100 s with Max-Age 30 s. The deadline is 130 s. At 125 s it may still label the representation fresh; at 131 s it must follow this example’s stale-display policy. The receipt time does not establish when the physical temperature was sampled; that needs payload evidence.
Within a short interval, Observe 100 followed by 102 then delayed 101 leaves 102 accepted. Check endpoint and Token before comparing those values. Rejecting 101 for ordering must not reset the accepted representation’s freshness deadline. A higher sequence value also cannot grant indefinite freshness: use the accepted response’s Max-Age.
Try a changed case: the room temperature stays constant, but communication stops. What should the tile show when freshness expires? It shows the last value as stale and the current state as unknown, because silence is not a new measurement. If the client then restarts and loses its reserved Token, establish a new observation rather than attaching an arbitrary old notification to it.
Keep the trace, the acceptance decision and the display deadline together. A sequence gap does not identify every missed transition; applications that need complete event history need a separate durable-history contract. Observe freshness alone does not establish alarm coverage or a safe physical condition.
From the registered endpoint and Token, the display accepts Observe 120, receives 124 one second later, then 122 two seconds after that. Which representation remains accepted?
124, because 122 fails the short-interval ordering comparison.
Correct. 124 replaces 120. The delayed 122 passes neither sequence comparison nor the more-than-128-second test, so it cannot replace 124 or renew its freshness.
Review the trace and the display together:
Review the Observe flow first. Then check how message types affect retries.

Chapter
CoAP Observe Server Push
for the parent tutorial and implementation workflow.

Chapter
CoAP Implementation Labs
for code patterns that maintain observer registries and notification pacing.
Return to CoAP Observe Server Push, then continue to CoAP Advanced Features for block-wise transfer and large-payload considerations.

Knowledge check · self-test
__IOT_RELATED_TITLE__
__IOT_RELATED_DESCRIPTION__