viewof blBatteryCapacity = Inputs.range([100, 10000], {
value: 1000,
step: 100,
label: "Battery capacity (mAh):"
})
viewof blTransmitInterval = Inputs.range([1, 1440], {
value: 360,
step: 1,
label: "Transmit interval (minutes):"
})
viewof blTxCurrent = Inputs.range([10, 200], {
value: 80,
step: 5,
label: "Radio TX current (mA):"
})
viewof blSleepCurrent = Inputs.range([1, 100], {
value: 5,
step: 1,
label: "Sleep current (uA):"
})
// CoAP: ~6ms radio time, MQTT: ~23ms, HTTP: ~25ms per transmission
blCoAPRadioMs = 6
blMQTTRadioMs = 23
blHTTPRadioMs = 25
blTxPerDay = 1440 / blTransmitInterval
blCoAPActiveHrs = (blTxPerDay * blCoAPRadioMs) / (1000 * 3600)
blMQTTActiveHrs = (blTxPerDay * blMQTTRadioMs) / (1000 * 3600)
blHTTPActiveHrs = (blTxPerDay * blHTTPRadioMs) / (1000 * 3600)
blSleepHrs = 24 // approximately all day is sleep
blCoAPDaily = (blCoAPActiveHrs * blTxCurrent) + (blSleepHrs * blSleepCurrent / 1000)
blMQTTDaily = (blMQTTActiveHrs * blTxCurrent) + (blSleepHrs * blSleepCurrent / 1000)
blHTTPDaily = (blHTTPActiveHrs * blTxCurrent) + (blSleepHrs * blSleepCurrent / 1000)
blCoAPDays = blBatteryCapacity / blCoAPDaily
blMQTTDays = blBatteryCapacity / blMQTTDaily
blHTTPDays = blBatteryCapacity / blHTTPDaily
blCoAPYears = blCoAPDays / 365
blMQTTYears = blMQTTDays / 365
blHTTPYears = blHTTPDays / 365
blSavingsVsMQTT = ((blMQTTDaily - blCoAPDaily) / blMQTTDaily * 100)
html`<div style="background: #f8f9fa; border-left: 4px solid #E67E22; padding: 15px; margin-top: 15px; font-family: Arial, sans-serif;">
<p style="color: #2C3E50; margin-top: 0; font-weight: 700;">Battery Life Estimates (${blTxPerDay.toFixed(1)} transmissions/day)</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: 2px solid #16A085;">
<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;">${blCoAPYears >= 1 ? blCoAPYears.toFixed(1) + ' years' : blCoAPDays.toFixed(0) + ' days'}</div>
<div style="color: #7F8C8D; font-size: 11px; margin-top: 3px;">${blCoAPDaily.toFixed(4)} mAh/day</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;">${blMQTTYears >= 1 ? blMQTTYears.toFixed(1) + ' years' : blMQTTDays.toFixed(0) + ' days'}</div>
<div style="color: #7F8C8D; font-size: 11px; margin-top: 3px;">${blMQTTDaily.toFixed(4)} mAh/day</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;">${blHTTPYears >= 1 ? blHTTPYears.toFixed(1) + ' years' : blHTTPDays.toFixed(0) + ' days'}</div>
<div style="color: #7F8C8D; font-size: 11px; margin-top: 3px;">${blHTTPDaily.toFixed(4)} mAh/day</div>
</div>
</div>
<div style="margin-top: 12px; padding: 10px; background: #e8f5e9; border-radius: 4px; font-size: 13px; color: #2C3E50;">
<strong>CoAP advantage:</strong> ${blSavingsVsMQTT.toFixed(1)}% less daily consumption vs MQTT. ${blCoAPYears >= 2 ? 'Meets the typical 2-year battery life target.' : 'Consider increasing battery capacity or reducing transmit frequency to meet 2-year target.'}
</div>
</div>`IoT Battery Life Estimator
IoT Battery Life Estimator
animation
rest
protocols
Try Change "Transmit interval (minutes):" while keeping "Battery capacity (mAh):" unchanged. Then press Calculate battery life.
Observe After pressing Calculate battery life, watch CoAP / UDP and MQTT / TCP mAh/day as "Transmit interval (minutes):" changes.
Explain Explain why "Sleep current (uA):" changes daily consumption for all protocols after you press Calculate battery life.
Technical boundaries. Radio time per transmission is fixed at 6ms for CoAP, 23ms for MQTT, and 25ms for HTTP. Sleep consumption assumes approximately 24 hours per day.
IoT Battery Life Estimator
Estimate battery life based on protocol choice, transmission frequency, and battery capacity.