Scenario: You need to update firmware on 100 ESP32 devices over a constrained 6LoWPAN network. Each firmware image is 512 KB. You must select the optimal Block2 size to minimize transfer time while respecting network constraints.
Given:
- Network MTU: 127 bytes (6LoWPAN typical)
- CoAP header + options: 12 bytes
- Block2 option: 3 bytes
- Available block sizes: 16, 32, 64, 128, 256, 512, 1024 bytes (SZX = 0 to 6)
- Packet loss rate: 5% (typical wireless)
- Round-trip time (RTT): 100 ms
- Each lost block requires retransmission
Step 1: Calculate maximum payload per block
Usable payload = MTU - CoAP headers - Block2 option
= 127 - 12 - 3 = 112 bytes
Largest block size that fits: 64 bytes (SZX=2)
- 128 bytes would require 128 + 15 = 143 bytes total (exceeds MTU)
Step 2: Calculate blocks needed per firmware
Block size options that fit in MTU: 16, 32, 64 bytes
For 512 KB (524,288 bytes) firmware:
16-byte blocks: 524,288 / 16 = 32,768 blocks
32-byte blocks: 524,288 / 32 = 16,384 blocks
64-byte blocks: 524,288 / 64 = 8,192 blocks
Step 3: Calculate transfer time with loss
Transfer time = (blocks × RTT) × (1 + loss_rate)
16-byte blocks:
Ideal time: 32,768 × 0.1s = 3,276.8 seconds (54.6 min)
With 5% loss: 3,276.8 × 1.05 = 3,440.6 seconds (57.3 min)
32-byte blocks:
Ideal time: 16,384 × 0.1s = 1,638.4 seconds (27.3 min)
With 5% loss: 1,638.4 × 1.05 = 1,720.3 seconds (28.7 min)
64-byte blocks:
Ideal time: 8,192 × 0.1s = 819.2 seconds (13.7 min)
With 5% loss: 819.2 × 1.05 = 860.2 seconds (14.3 min)
Step 4: Calculate total retransmission overhead
Expected retransmissions per firmware (5% loss):
16-byte blocks: 32,768 × 0.05 = 1,638 retries
32-byte blocks: 16,384 × 0.05 = 819 retries
64-byte blocks: 8,192 × 0.05 = 410 retries
Additional time for retries (assuming 2nd attempt succeeds):
16-byte: 1,638 × 0.1s = 163.8 seconds (2.7 min)
32-byte: 819 × 0.1s = 81.9 seconds (1.4 min)
64-byte: 410 × 0.1s = 41.0 seconds (0.7 min)
Step 5: Calculate fleet-wide update time
Sequential update of 100 devices:
16-byte blocks: 100 × 57.3 min = 5,730 min (95.5 hours)
32-byte blocks: 100 × 28.7 min = 2,870 min (47.8 hours)
64-byte blocks: 100 × 14.3 min = 1,430 min (23.8 hours)
Parallel update (10 devices at once, network allows):
16-byte blocks: 95.5 / 10 = 9.55 hours
32-byte blocks: 47.8 / 10 = 4.78 hours
64-byte blocks: 23.8 / 10 = 2.38 hours
Result:
- Optimal choice: 64-byte blocks (SZX=2)
- Transfer time: 14.3 minutes per device
- Fleet update: 23.8 hours sequential, 2.4 hours with 10-parallel
- 4× faster than 16-byte blocks despite same MTU constraint
- Efficiency: 64 bytes payload / 79 bytes total = 81% useful data
Key Insight: Larger block sizes dramatically reduce the number of round trips (8,192 vs 32,768), which is the dominant factor in transfer time. Always use the largest block size that fits within your network’s MTU. For 6LoWPAN (127-byte MTU), 64-byte blocks provide the best balance. For standard Ethernet (1500-byte MTU), use 1024-byte blocks.
Block transfer time depends on both block count and packet loss. For payload size \(S\) bytes, block size \(B\) bytes, RTT \(t\) seconds, and loss rate \(p\):
\[T_{\text{transfer}} = \left\lceil \frac{S}{B} \right\rceil \cdot t \cdot (1 + p)\]
For this firmware update with \(S = 524,288\) bytes, \(t = 0.1\text{s}\), \(p = 0.05\):
64-byte blocks: \(T = \lceil 524,288/64 \rceil \times 0.1 \times 1.05 = 8,192 \times 0.105 = 860\text{s} = 14.3\text{ min}\)
16-byte blocks: \(T = \lceil 524,288/16 \rceil \times 0.1 \times 1.05 = 32,768 \times 0.105 = 3,441\text{s} = 57.3\text{ min}\)
Speedup ratio: \(3,441/860 = 4\times\) faster with larger blocks.
The round-trip count \(N = \lceil S/B \rceil\) is inversely proportional to block size, explaining why larger blocks (up to MTU limit) minimize transfer time.