viewof ohPayload = Inputs.range([1, 500], {
value: 4,
step: 1,
label: "Application payload (bytes):"
})
viewof ohIncludeEthernet = Inputs.toggle({
value: true,
label: "Include Ethernet frame (14 bytes):"
})
// Protocol headers (fixed sizes for comparison)
ohCoAPHeader = 4
ohUDPHeader = 8
ohTCPHeader = 20
ohIPv4Header = 20
ohEthernet = ohIncludeEthernet ? 14 : 0
ohMQTTFixed = 2
ohMQTTVariable = 2 + 10 // packet ID + topic
ohHTTPHeader = 120 // minimal GET response headers
ohCoAPTotal = ohPayload + ohCoAPHeader + ohUDPHeader + ohIPv4Header + ohEthernet
ohCoAPOverhead = ohCoAPTotal - ohPayload
ohCoAPPct = (ohCoAPOverhead / ohCoAPTotal * 100)
ohMQTTTotal = ohPayload + ohMQTTFixed + ohMQTTVariable + ohTCPHeader + ohIPv4Header + ohEthernet
ohMQTTOverhead = ohMQTTTotal - ohPayload
ohMQTTPct = (ohMQTTOverhead / ohMQTTTotal * 100)
ohHTTPTotal = ohPayload + ohHTTPHeader + ohTCPHeader + ohIPv4Header + ohEthernet
ohHTTPOverhead = ohHTTPTotal - ohPayload
ohHTTPPct = (ohHTTPOverhead / ohHTTPTotal * 100)
html`<div style="background: #f8f9fa; border-left: 4px solid #16A085; padding: 15px; margin-top: 15px; font-family: Arial, sans-serif;">
<p style="color: #2C3E50; margin-top: 0; font-weight: 700;">Protocol Overhead for ${ohPayload}-byte Payload</p>
<div style="display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 12px; margin-top: 10px;">
<div style="background: white; padding: 12px; border-radius: 4px; border: 1px solid #e0e0e0;">
<div style="color: #7F8C8D; font-size: 12px; text-transform: uppercase; margin-bottom: 5px;">CoAP / UDP</div>
<div style="color: #16A085; font-size: 22px; font-weight: bold;">${ohCoAPPct.toFixed(1)}%</div>
<div style="color: #7F8C8D; font-size: 11px; margin-top: 3px;">${ohCoAPOverhead}B overhead / ${ohCoAPTotal}B total</div>
<div style="margin-top: 8px; background: #e8f5e9; height: 8px; border-radius: 4px;">
<div style="background: #16A085; width: ${ohCoAPPct}%; height: 8px; border-radius: 4px;"></div>
</div>
</div>
<div style="background: white; padding: 12px; border-radius: 4px; border: 1px solid #e0e0e0;">
<div style="color: #7F8C8D; font-size: 12px; text-transform: uppercase; margin-bottom: 5px;">MQTT / TCP</div>
<div style="color: #E67E22; font-size: 22px; font-weight: bold;">${ohMQTTPct.toFixed(1)}%</div>
<div style="color: #7F8C8D; font-size: 11px; margin-top: 3px;">${ohMQTTOverhead}B overhead / ${ohMQTTTotal}B total</div>
<div style="margin-top: 8px; background: #fff3e0; height: 8px; border-radius: 4px;">
<div style="background: #E67E22; width: ${ohMQTTPct}%; height: 8px; border-radius: 4px;"></div>
</div>
</div>
<div style="background: white; padding: 12px; border-radius: 4px; border: 1px solid #e0e0e0;">
<div style="color: #7F8C8D; font-size: 12px; text-transform: uppercase; margin-bottom: 5px;">HTTP / TCP</div>
<div style="color: #E74C3C; font-size: 22px; font-weight: bold;">${ohHTTPPct.toFixed(1)}%</div>
<div style="color: #7F8C8D; font-size: 11px; margin-top: 3px;">${ohHTTPOverhead}B overhead / ${ohHTTPTotal}B total</div>
<div style="margin-top: 8px; background: #ffebee; height: 8px; border-radius: 4px;">
<div style="background: #E74C3C; width: ${ohHTTPPct}%; height: 8px; border-radius: 4px;"></div>
</div>
</div>
</div>
<div style="margin-top: 12px; padding: 10px; background: #f0f7ff; border-radius: 4px; font-size: 13px; color: #2C3E50;">
<strong>Insight:</strong> CoAP saves ${(ohHTTPTotal - ohCoAPTotal)} bytes per message vs HTTP (${((ohHTTPTotal - ohCoAPTotal) / ohHTTPTotal * 100).toFixed(0)}% smaller packets). ${ohPayload < 50 ? 'With small IoT payloads, protocol overhead dominates -- choose CoAP for constrained devices.' : 'As payload size increases, the relative overhead advantage of CoAP decreases.'}
</div>
</div>`Protocol Overhead Comparison Calculator
Protocol Overhead Comparison Calculator
animation
rest
protocols
Try Increase "Application payload (bytes):" and toggle "Include Ethernet frame (14 bytes):".
Observe After pressing Calculate protocol overhead, watch CoAP / UDP, MQTT / TCP, and HTTP / TCP overhead percentages as "Application payload (bytes):" changes.
Explain Explain why "Application payload (bytes):" changes the relative overhead advantage of CoAP after you press Calculate protocol overhead.
Technical boundaries. Protocol headers use fixed sizes for comparison, including a fixed topic and minimal HTTP response headers. The Ethernet toggle adds 14 bytes to each total.
Protocol Overhead Comparison Calculator
Compare the overhead percentage for CoAP, MQTT, and HTTP when sending small IoT payloads.