Block2 (option 23)
For the firmware GET, request response blocks 0 through 4. The final data block clears M; its payload contains the remaining 904 bytes.
Progress saves as you read. Mark sections complete as you go; your progress appears in the sidebar.
Related reference: CoAP message types.
A device has received part of a 5,000-byte firmware file when a response is lost. Should it request the missing bytes, resume after waking, or discard what it saved? Work through the byte positions first, then check whether the server and cache still describe the same file.
A protocol defines message-exchange rules. CoAP means Constrained Application Protocol. Firmware is software installed on a device. A payload is the application data inside a message. A representation is the bytes supplied for a resource in a particular format and version; a block carries one numbered part of those bytes.
For the running example, assume the client already knows the firmware resource and the server keeps one version available. The file contains 5,000 bytes and the agreed block payload size is 1,024 bytes. Four full blocks carry 4×1,024=4,096 bytes; the fifth carries 5,000−4,096=904 bytes.
Number the blocks from zero. Blocks 0, 1, 2 and 3 start at byte offsets 0, 1,024, 2,048 and 3,072. The final block, number 4, starts at 4,096. The More flag, written M, is 1 on the first four data blocks and 0 on the final one. A final block may be shorter than the agreed size.
Now lose block 2’s response. Request block 2 again and place its bytes at offset 2,048. Do not append a duplicate response at the end of the file. This recovery works only while the saved blocks and repeated response belong to the same representation.
A validator identifies a representation so a client can check whether it changed. An ETag is one such validator: an identifier the client can compare across responses. If the server returns a different ETag during this download, stop combining blocks and restart against a consistent version. A matching ETag supports continuity; it is not a signature proving who authorized the firmware.
Read the figure in the parent chapter as a sequence of decisions: locate the resource, request a numbered part, place the response at its byte offset, and check continuity before accepting the next part. A digest, or hash, is a value calculated from the file bytes for comparison with the expected file. A digital signature supports checking the firmware against a trusted signing identity. After assembly, check the expected length, digest and firmware signature under the update policy before installation. Reaching 5,000 bytes alone does not make an image trustworthy.
Resume One Download Without Trusting Stale Details
A proxy is an intermediary that exchanges requests with the origin server on a client’s behalf. It may keep a cache, a stored response reused when the request and caching rules permit it. When the device wakes, both its saved blocks and the proxy’s metadata need checking.
Use the 5,000-byte fixture to test the decision before relying on a real update. These are test instructions, not a claim that a transfer was run here.
fw-A, and the recorded firmware URI, format and 1,024-byte block size. In this fixture, the proxy’s discovery response has Max-Age 45 seconds and age 50 seconds: it is stale by 5 seconds. Revalidate discovery; suppose 2.03 Valid refreshes it and the firmware link remains present. Before reading the outcomes below, choose retry, resume or restart for a resumed Block2 response with NUM 2, SZX 6 and ETag fw-A, then choose again if its ETag is fw-B. Explain whether refreshed discovery alone permits reuse of the saved firmware bytes. If the URI, format, size, offsets or validator evidence is missing, discard partial assembly and restart.fw-A and the recorded transfer identity unchanged, resume by requesting block 2 and placing its 1,024 bytes at offset 2,048; expect 3,072 assembled bytes with no duplicate segment. A lost response during that same transfer calls for a retry of block 2 at the same offset. With fw-B, stop combining blocks, discard the saved fw-A assembly and restart against the new representation; no fw-A bytes may enter the new assembly. Refreshed discovery validates the link list, not the firmware representation. Installing mixed versions is a failed continuity test even if the final length is correct.Retain the responses, cache age and Max-Age, discovery revalidation, repeated requests, firmware validators, assembled length, digest, signature result and install decision. Each record answers a different part of the resume decision.
After this page, you should be able to:
CoAP Advanced Features introduces the feature choices. Here, the missing-block example turns them into a decision procedure: locate the resource, map blocks to bytes, check representation continuity, then check cache freshness and installation evidence.
Use the same procedure for a log upload or a cached sensor reading. The direction of transfer and the final application check change; byte placement and evidence still need an explicit contract.
On the UDP transport discussed here, a CoAP message occupies a UDP datagram. A datagram is one network-carried message unit. Splitting the firmware body into CoAP blocks lets the client request a missing portion rather than depend on reassembling one large fragmented packet. Losing a required network fragment prevents that packet from being reassembled.
Block2, option 23, controls a response body: the firmware bytes returned by GET, the method used to retrieve a resource. Block1, option 27, controls a request body: for example, log bytes sent using PUT (create or replace at an address) or POST (submit data for processing). Each block participates in a request/response exchange. A protocol retransmission and a later application request for the same block are distinct events; neither should cause duplicate bytes in the assembled object.
In the running download, request Block2 number 2 again after its response is lost. Keep blocks 0 and 1 only if they still belong to the same representation. A restart does not automatically preserve a usable transfer: record what was saved and how its identity will be checked before resuming.
Inspect the figure in the parent chapter for the link between a numbered request and the bytes retained by the client.
Follow the figure in the parent chapter from the requested block to its position in the assembled file. Retry places bytes in that position again; validator checks decide whether earlier bytes remain usable. The final length and digest checks follow assembly, rather than replacing continuity checks.
For the firmware GET, request response blocks 0 through 4. The final data block clears M; its payload contains the remaining 904 bytes.
For a log upload, split the request body across blocks. Check the server response before advancing or declaring the upload complete.
Repeat the missing block when saved bytes and representation identity remain valid. Lost state or a changed version can require a restart.
Choose a block size whose complete message, including headers and security overhead, fits the path limits. Block-wise transfer alone does not guarantee the absence of fragmentation.
For the firmware response, NUM is the block number, M indicates whether more data blocks follow, and SZX encodes the selected block size. With SZX 6, size is 2^(6 + 4) = 1024 bytes. NUM 4 therefore starts at 4 × 1024 = 4096; M 0 ends the body after its 904-byte payload. SZX sets the block size, not the exact length of a short final payload.
Transfer example. An 18,432-byte log upload uses Block1 with SZX 4, or 2^(4 + 4) = 256 bytes per block. It needs 18,432 / 256 = 72 full blocks. NUM 31 starts at 31 × 256 = 7936 with M 1. NUM 71 starts at 71 × 256 = 18176 and carries the final 256 bytes with M 0. Compare byte offsets even when a library supplies the option fields.
For ordinary UDP blocks, SZX values 0 through 6 select sizes from 16 through 1,024 bytes using 2^(SZX + 4). A smaller size can be negotiated when buffers or path limits require it. If size changes, recalculate NUM from the required byte position; continuing the old number with a new size points to different bytes. The table assumes a fixed size throughout a 4,096-byte body.
In a successful continuing Block1 upload, 2.31 Continue asks for further request data; it does not prove final application acceptance. Check the final operation response, such as 2.01 Created or 2.04 Changed on success. An incomplete request can produce 4.08 Request Entity Incomplete; an oversized request can produce 4.13 Request Entity Too Large, possibly with a smaller size hint. Specify upload identity and commit behavior separately: the Block2 ETag example does not establish a generic upload-resume contract.
A resource address is a URI. To find advertised resource addresses, request GET /.well-known/core from a server that supports discovery. Its CoRE Link Format response is a comma-separated list of links and attributes, sent as Content-Format 40 (application/link-format). Content-Format identifies the payload format. A link names a resource; its attributes describe it.
For example, </sensors/temp>;rt="temperature";if="sensor";ct=50;obs advertises a temperature resource. Here rt names the resource type, if describes its interface, ct lists a supported content format (50 means JSON), and obs advertises support for observing changes. These attributes do not grant access or guarantee that an Observe registration will succeed. Query /.well-known/core?rt=temperature when that agreed type is the one needed; inspect the returned links rather than guessing paths.
Transfer example. A greenhouse gateway discovers </zone/3/temp>;rt="temperature";if="sensor";ct=60;obs and </zone/3/valve>;rt="irrigation";if="actuator";ct=50. Suppose the temperature GET response permits caching and supplies Max-Age 45 seconds: its freshness lifetime. At age 30 seconds, 15 seconds remain; at age 50 seconds, it is stale by 5 seconds and needs revalidation before reuse. A proxy may reuse it for an eligible matching request within the remaining lifetime and access policy. The cache key is the request information used to select a stored response. After expiry, send its ETag to the origin in a validating GET. If the representation is unchanged, 2.03 Valid refreshes the cached metadata without a response payload; if changed, 2.05 Content supplies replacement bytes and their ETag. An unchanged validator does not, by itself, extend freshness.
Check the returned resource address and Content-Format 40. Discovery describes what is advertised; access to a known address remains a separate decision.
Use rt for type selection, if for interface information and ct for formats. Treat sz size metadata and obs capability as claims to check against transfer and registration results.
Max-Age is option 14; when absent, its default is 60 seconds. Check remaining freshness, the request cache key and sharing policy before reusing an eligible cached GET response.
ETag is option 4. A validating GET can yield 2.03 Valid without a payload; keep the stored bytes and update freshness from the response. A changed representation requires replacement bytes.
A firmware body is 2,050 bytes and the path uses 256-byte CoAP blocks. How many data blocks carry the body?
Nine blocks cover the 2,050-byte firmware body.
Correct. Eight full blocks carry 2,048 bytes, leaving two bytes for a ninth.
A Block2 response has NUM=4, SZX=4 and M=1. Where should its bytes go, and is it final?
Offset 1,024; more data follows.
Correct. 4 × 256 = 1,024, and M=1 signals further data blocks.
Before accepting the design, retain evidence for each decision:
?rt=temperature. Check authorization separately; a hidden link does not revoke direct access.Return to the feature tour for the broad use cases, then check method and multicast contracts where those choices affect exchanges.

Chapter
CoAP Method Codes and Multicast Contracts
for method, Token, multicast, and response-code behavior.

Chapter
CoAP Implementation Stack and Trace Contracts
for trace-based acceptance tests.
Return to CoAP Advanced Features, then continue to CoAP Security and Applications for securing block transfers and discovered resources.

Knowledge check · self-test
__IOT_RELATED_TITLE__
__IOT_RELATED_DESCRIPTION__