CoAP · Study deck

CoAP Block and Discovery Contracts

A constrained node cannot always carry a firmware image in one CoAP message, and a new client cannot use a resource it cannot discover.

Broker Bex is your guide for this deck.

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

After studying this chapter

Learning objectives

You will be able to:

  • Choose Block1 or Block2 and record block size, retry, resume, and hash-verification evidence for a large CoAP transfer.
  • Decode Block option NUM, M, and SZX fields and check them against byte offsets in a trace.
  • Describe /.well-known/core discovery, CoRE Link Format attributes, filtered discovery queries, and Content-Format 40.
  • Review Max-Age, ETag revalidation, and proxy caching decisions for constrained CoAP resources.
iotclass.org

Major section

Reassemble the Image the Server Actually Sent

It selects the firmware resource and requests a block.

  • Four full blocks carry (4\times1{,}024=4{,}096) bytes, leaving (5{,}000-4{,}096=904) bytes in the fifth block.
  • The client should expect exactly 5,000 assembled bytes before checking the image hash and signature.
  • Discovery has its own precision.

Numbers to remember

5,000 bytesnew blocks could produce 5,000 bytes that are still unsafe.
CoAP Block2 transfer contract showing block option semantics, representation continuity, exactly-once reassembly under retry or reorder, and final length and hash evidence.
CoAP Block2 transfer contract showing block option semantics, representation continuity, exactly-once reassembly under retry or reorder, and final length and hash evidence.
iotclass.org

Major section

Reassemble the Image the Server Actually Sent (continued)

A lost response does not mean the server should advance state blindly.

  • The client can request the same block number again, and the server should return the matching portion of the same representation.
  • Mixing old and new blocks could produce 5,000 bytes that are still unsafe.
  • A link-format record can name a resource path, content type, interface, resource type, and observability.
  • Authorization remains separate from knowing that a URI exists.
iotclass.org

Major section

Start With the Broken Firmware Download

One block is missing, and a nearby cache may describe an old file.

  • The device needs proof before it resumes or installs anything.
  • A protocol means the shared rules for a message exchange.
  • CoAP means Constrained Application Protocol, a compact message system for small devices.
  • Firmware means the software stored on a device.
iotclass.org

Major section

Start With the Broken Firmware Download (continued)

A block is one numbered piece of a larger transfer.

  • This runway does not prove every proxy or update route.
  • The device asks for a firmware image, receives several blocks, loses one packet, then wakes later behind a proxy that may still have cached metadata.
  • A working demo is not enough; the transfer needs block size, numbering, retry, resume, hash, discovery, and freshness evidence.
iotclass.org

Major section

Overview: Block-wise Transfer Moves Big Payloads Through Small Datagrams

The key benefit is failure isolation.

  • Each block is carried in its own request/response exchange with its own Message ID, so a lost block is retransmitted alone rather than forcing the entire payload to restart.
  • In a real maintenance window, that isolation changes the rollout plan.

Key terms

Each block
Each block is its own exchange, so loss costs one block, not the whole transfer.
Encryption
Encryption is a separate concern (DTLS/OSCORE).

Why it matters

A loss repeats only its numbered block; continuity fields prevent pieces from different representations being combined; final length and hash evidence close acceptance.

CoAP Block2 transfer contract showing block option semantics, representation continuity, exactly-once reassembly under retry or reorder, and final length and hash evidence.
CoAP Block2 transfer contract showing block option semantics, representation continuity, exactly-once reassembly under retry or reorder, and final length and hash evidence.
iotclass.org

Major section

Overview: Block-wise Transfer Moves Big Payloads Through Small Datagrams (continued)

The transfer has 384 numbered blocks.

  • The review evidence should record the chosen block size, retry cap, resume point, hash check, and the condition that triggers rollback to the previous profile.
  • That ordered contract turns the pump-controller example into a testable transfer rather than assuming that smaller datagrams alone make delivery safe.
  • Failure isolation Each block is its own exchange, so loss costs one block, not the whole transfer.
iotclass.org

Major section

Practitioner: The Block Option Encodes NUM, More, and a Size Exponent

With SZX 4 the client sends 256-byte Block1 chunks, so it needs ceil(18,432 / 256) = 72 blocks.

  • NUM is the block number within the transfer.
  • M (the More flag) is 1 while further blocks follow and 0 on the last block.
  • Fewest exchanges; needs the largest buffer/MTU.

Numbers to remember

256 bytesSZX 4 is 256 bytes
1024 bytesand SZX 6 is the maximum 1024 bytes.
iotclass.org

Major section

Under the Hood: Discovery via CoRE Link Format, and Caching Through Proxies

Here rt is the resource type, if is the interface description, ct is the content-format the resource speaks (50 = JSON), and obs marks it observable.

  • A client can narrow the query — GET /.well-known/core?rt=temperature returns only temperature links — which keeps discovery cheap on a large node.
  • Every response carries an implicit or explicit Max-Age (option 14, default 60 seconds) stating how long it stays fresh.
  • The evidence record should show the discovery query, Link Format body, Max-Age value, ETag revalidation result, and which resources are excluded from shared caching.
iotclass.org

Major section

Under the Hood: Discovery via CoRE Link Format, and Caching Through Proxies (continued)

A caching CoAP proxy — forward or reverse — can store a response and serve it to other clients until Max-Age expires, so ten dashboards observing one sensor need not each wake the device.

  • When freshness lapses, an ETag (option 4) lets the proxy revalidate: it repeats the ETag, and if nothing changed the origin answers 2.03 Valid with no body, saving the payload entirely.
  • Max-Age caching A proxy reuses a stored response until Max-Age expires, sparing the origin device.
  • Once resources are known, caching reduces how often a sleepy node is disturbed.
iotclass.org

Deck summary

Key takeaways

It selects the firmware resource and requests a block.

  • A lost response does not mean the server should advance state blindly.
  • One block is missing, and a nearby cache may describe an old file.
  • A block is one numbered piece of a larger transfer.
  • The key benefit is failure isolation.
iotclass.org

Retrieval practice

Recall check 1 of 3

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

Q1Why does CoAP use block-wise transfer instead of relying on IP fragmentation for a large firmware image?

ABlock-wise transfer encrypts each block, which IP fragmentation cannot do.
BEach CoAP block is its own retransmittable exchange.
CIP fragmentation is not allowed on any IoT network.
DBlock-wise transfer makes the payload smaller overall.
Show answer

Answer: B Block-wise transfer isolates failures to a single block, which is far more robust than IP fragmentation on lossy constrained links.

iotclass.org

Retrieval practice

Recall check 2 of 3

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

Q2In a CoAP block-wise option, a block has SZX = 6 and the More (M) flag set to 0. What does that mean?

ASZX is the literal byte count, so this is a 6-byte final block.
BIt uses 1024-byte blocks and this block is final.
CIt uses 1024-byte blocks and another block must follow.
DSZX chooses the CBOR content format for this block.
Show answer

Answer: B Block size is 2^(SZX+4) = 2^10 = 1024 bytes, and M = 0 marks the last block, so the transfer ends here.

iotclass.org

Retrieval practice

Recall check 3 of 3

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

Q3A CoAP caching proxy holds a sensor response whose Max-Age has just expired. It revalidates and the value is unchanged. What response makes this efficient?

A2.03 Valid with no payload, returned after the proxy revalidates using the stored ETag.
B2.05 Content resending the full payload every time Max-Age expires.
C4.04 Not Found, because the cached copy is stale.
DThe proxy must delete the entry and force every client to poll the device directly.
Show answer

Answer: A ETag-based revalidation lets the origin answer 2.03 Valid without resending the body, refreshing the cache cheaply.

iotclass.org

Print reference

Answers

Answer key.

  1. B · Block-wise transfer isolates failures to a single block, which is far more robust than IP fragmentation on lossy constrained links.
  2. B · Block size is 2^(SZX+4) = 2^10 = 1024 bytes, and M = 0 marks the last block, so the transfer ends here.
  3. A · ETag-based revalidation lets the origin answer 2.03 Valid without resending the body, refreshing the cache cheaply.
iotclass.org