viewof payloadSize = Inputs.range([1, 100], {
value: 10,
step: 1,
label: "Sensor payload size (bytes):"
})
viewof bandwidth = Inputs.select([9600, 50000, 115200, 250000], {
value: 50000,
label: "Network bandwidth (bps):"
})
mqttHeader = 2
httpHeader = 200
mqttTotal = mqttHeader + payloadSize
httpTotal = httpHeader + payloadSize
mqttTime = (mqttTotal * 8) / bandwidth * 1000
httpTime = (httpTotal * 8) / bandwidth * 1000
savings = ((httpTotal - mqttTotal) / httpTotal * 100)
html`<div style="background: #f8f9fa; padding: 20px; border-radius: 8px; border-left: 4px solid #E67E22; margin: 20px 0;">
<h4 style="margin: 0 0 15px 0; color: #2C3E50;">MQTT vs HTTP Overhead Calculator</h4>
<div style="display: grid; grid-template-columns: 1fr 1fr; gap: 15px; margin-bottom: 15px;">
<div style="background: white; padding: 15px; border-radius: 6px; border: 1px solid #e0e0e0;">
<div style="font-size: 0.9em; color: #7F8C8D; margin-bottom: 5px;">MQTT (Stanford-Clark)</div>
<div style="font-size: 1.8em; font-weight: 600; color: #16A085;">${mqttTotal} bytes</div>
<div style="font-size: 0.85em; color: #7F8C8D; margin-top: 5px;">2-byte header + ${payloadSize}-byte payload</div>
<div style="font-size: 0.85em; color: #2C3E50; margin-top: 8px;">Transmit time: ${mqttTime.toFixed(2)} ms</div>
</div>
<div style="background: white; padding: 15px; border-radius: 6px; border: 1px solid #e0e0e0;">
<div style="font-size: 0.9em; color: #7F8C8D; margin-bottom: 5px;">HTTP (Berners-Lee)</div>
<div style="font-size: 1.8em; font-weight: 600; color: #E67E22;">${httpTotal} bytes</div>
<div style="font-size: 0.85em; color: #7F8C8D; margin-top: 5px;">~200-byte header + ${payloadSize}-byte payload</div>
<div style="font-size: 0.85em; color: #2C3E50; margin-top: 8px;">Transmit time: ${httpTime.toFixed(2)} ms</div>
</div>
</div>
<div style="font-size: 0.9em; color: #2C3E50; background: #e8f5e9; padding: 12px; border-radius: 6px;">
<strong>MQTT efficiency:</strong> ${savings.toFixed(1)}% bandwidth savings over HTTP<br>
<strong>Time saved:</strong> ${(httpTime - mqttTime).toFixed(2)} ms per message (${((httpTime/mqttTime)).toFixed(1)}× faster)<br>
<strong>Use case:</strong> ${bandwidth < 100000 ? "LoRaWAN/Satellite - MQTT strongly recommended" : "Wi-Fi/Cellular - Both protocols work well"}
</div>
</div>`MQTT vs HTTP Overhead Calculator
MQTT vs HTTP Overhead Calculator
animation
fundamentals
protocols