diff --git a/README.md b/README.md index 8cc660050..039978d04 100644 --- a/README.md +++ b/README.md @@ -167,6 +167,8 @@ Každá úspora proti upstreamu s naměřeným proudem a vlivem na příjem je v tabulce: [docs/power.md](docs/power.md#summary-every-option-against-stock-firmware). Změřeno proti upstreamu na stejné desce (XIAO, 3,3 V): náš repeater **6,87 mA**, upstream v1.19.0, jak ho dostanete, **10,13 mA** (−32 %; [protokol](docs/measurements/2026-12-04-stock-vs-tth/protocol.md)). +Kolik to dá pro váš uzel (deska, firmware, nastavení, provoz, baterie, panel): +[kalkulačka spotřeby](docs/power-calculator.md#cs). * GPS duty cycle (`gps duty`), i na T1000-E, kde nebyl: přijímač běží jen kolem synchronizace hodin (jednou denně, po neúspěšném okně znovu za 6 h). @@ -540,6 +542,8 @@ Every saving against upstream, with the measured current and its effect on reception, is in one table: [docs/power.md](docs/power.md#summary-every-option-against-stock-firmware). Measured against upstream on the same board (XIAO, 3.3 V): our repeater **6.87 mA**, upstream v1.19.0 as shipped **10.13 mA** (−32 %; [protocol](docs/measurements/2026-12-04-stock-vs-tth/protocol.md)). +What that means for your node (board, firmware, settings, traffic, battery, +panel): [power calculator](docs/power-calculator.md). * GPS duty cycle (`gps duty`), also on the T1000-E, which had none: the receiver runs only around a clock sync (once a day, after a window without diff --git a/docs/_js/power-calculator.js b/docs/_js/power-calculator.js new file mode 100644 index 000000000..fb6daf980 --- /dev/null +++ b/docs/_js/power-calculator.js @@ -0,0 +1,406 @@ +/* Power calculator of the docs site (docs/power-calculator.md, issue #48). + Plain JS, no framework, no build step. Loaded on every page through + extra_javascript in mkdocs.tth.yml; does nothing unless the page has +
. Every number comes from docs/power-data.json, this file + holds only the method (baseline + deltas + LoRa airtime) and the UI text. */ +(function () { + 'use strict'; + var script = document.currentScript; + + var T = { + en: { + title: 'Inputs', node: 'Node', settings: 'Settings', traffic: 'Traffic (estimate)', + battery: 'Battery and solar', result: 'Result', values: 'All values of the data file', + board: 'board', firmware: 'firmware', + powersaving: 'powersaving (MCU sleep)', rxps: 'radio.rxps (RX duty cycle)', + rxgain: 'radio.rxgain (boosted RX gain)', ble: 'BLE', gps: 'GPS', + rx_per_h: 'received packets / h', tx_per_h: 'transmitted packets / h (incl. forwarded)', + payload: 'packet length (bytes)', sf: 'SF', bw: 'BW (kHz)', cr: 'CR (4/x)', + preamble: 'preamble (symbols)', tx_dbm: 'TX power (dBm)', + tx_ma: 'TX current at that power (mA) - ESTIMATE', rx_extra: 'extra current while receiving (mA) - ESTIMATE', + mah: 'battery capacity (mAh)', usable_pct: 'usable capacity (%)', voltage: 'battery voltage (V)', + panel_w: 'solar panel (W, 0 = none)', sun_h: 'full-sun hours per day', charge_eff_pct: 'charging efficiency (%) - ESTIMATE', + measured: 'measured', estimate: 'ESTIMATE', unavailable: 'not in this firmware', + base: 'whole node', borrowed: 'taken from', fwoffset: 'firmware difference measured on', + nofwoffset: 'no measurement of this firmware on this board: the baseline of another firmware is used as is', + txline: 'transmitting', rxline: 'receiving', airtime: 'airtime of one packet', + avg: 'average current', perday: 'per day', autonomy: 'autonomy without sun', + days: 'days', solar: 'solar gain per day', balance: 'daily balance', + positive: 'the battery charges on such days', emptyin: 'battery empty in', + cost: 'reception cost', range: 'range', voltnote: 'currents of the measurement rig at', + battnote: 'Battery figures assume the node draws the same current from the cell (linear regulator).', + src: 'source', kind: 'kind', option: 'option', value: 'value', date: 'date', + loadfail: 'Could not load power-data.json: ', lang: 'Česky' + }, + cs: { + title: 'Vstupy', node: 'Uzel', settings: 'Nastavení', traffic: 'Provoz (odhad)', + battery: 'Baterie a solár', result: 'Výsledek', values: 'Všechny hodnoty datového souboru', + board: 'deska', firmware: 'firmware', + powersaving: 'powersaving (spánek MCU)', rxps: 'radio.rxps (střídání příjmu)', + rxgain: 'radio.rxgain (zesílený příjem)', ble: 'BLE', gps: 'GPS', + rx_per_h: 'přijatých paketů / h', tx_per_h: 'odvysílaných paketů / h (vč. přeposlaných)', + payload: 'délka paketu (bajty)', sf: 'SF', bw: 'BW (kHz)', cr: 'CR (4/x)', + preamble: 'preambule (symboly)', tx_dbm: 'vysílací výkon (dBm)', + tx_ma: 'proud při vysílání (mA) - ODHAD', rx_extra: 'proud navíc při příjmu (mA) - ODHAD', + mah: 'kapacita baterie (mAh)', usable_pct: 'využitelná kapacita (%)', voltage: 'napětí baterie (V)', + panel_w: 'solární panel (W, 0 = žádný)', sun_h: 'hodin plného slunce za den', charge_eff_pct: 'účinnost nabíjení (%) - ODHAD', + measured: 'změřeno', estimate: 'ODHAD', unavailable: 'tento firmware nemá', + base: 'celý uzel', borrowed: 'převzato z', fwoffset: 'rozdíl firmwarů změřený na', + nofwoffset: 'tento firmware na této desce změřený není: použit základ jiného firmwaru tak, jak je', + txline: 'vysílání', rxline: 'příjem', airtime: 'doba vysílání jednoho paketu', + avg: 'průměrný proud', perday: 'za den', autonomy: 'výdrž bez slunce', + days: 'dní', solar: 'zisk ze soláru za den', balance: 'denní bilance', + positive: 'v takové dny se baterie nabíjí', emptyin: 'baterie prázdná za', + cost: 'cena v příjmu', range: 'rozsah', voltnote: 'proudy měřicí sestavy při', + battnote: 'Výpočet baterie předpokládá, že uzel bere z článku stejný proud (lineární regulátor).', + src: 'zdroj', kind: 'druh', option: 'volba', value: 'hodnota', date: 'datum', + loadfail: 'Nepodařilo se načíst power-data.json: ', lang: 'English' + } + }; + + function el(tag, attrs, kids) { + var e = document.createElement(tag); + Object.keys(attrs || {}).forEach(function (k) { + if (k === 'text') e.textContent = attrs[k]; + else e.setAttribute(k, attrs[k]); + }); + (kids || []).forEach(function (c) { + if (c != null) e.appendChild(typeof c === 'string' ? document.createTextNode(c) : c); + }); + return e; + } + + function start() { + var root = document.getElementById('pcalc'); + if (!root || !script) return; + var base = new URL('../', script.src); // the script lives in /_js/ + fetch(new URL('power-data.json', base)) + .then(function (r) { + if (!r.ok) throw new Error('HTTP ' + r.status); + return r.json(); + }) + .then(function (d) { new Calc(root, d, base); }) + .catch(function (e) { root.textContent = T.en.loadfail + e.message; }); + } + + function Calc(root, d, base) { + this.root = root; + this.d = d; + this.base = base; + var h = location.hash.replace('#', ''); + this.lang = h === 'cs' || h === 'en' ? h : + (navigator.language || '').slice(0, 2) === 'cs' ? 'cs' : 'en'; + var td = d.traffic.defaults, b = d.battery; + this.s = { + board: d.boards[0].id, firmware: d.firmwares[0].id, + rx_per_h: td.rx_per_h, tx_per_h: td.tx_per_h, payload: td.payload, + sf: td.sf, bw: td.bw, cr: td.cr, preamble: td.preamble, tx_dbm: td.tx_dbm, + rx_extra: d.traffic.rx_extra.value, + mah: b.mah, usable_pct: b.usable_pct, voltage: b.voltage, + panel_w: b.panel_w, sun_h: b.sun_h, charge_eff_pct: b.charge_eff_pct + }; + this.s.tx_ma = this.txCurrent(this.s.tx_dbm); + this.applyDefaults(); + this.build(); + } + + var P = Calc.prototype; + + P.t = function (k) { return T[this.lang][k] || k; }; + P.n = function (o) { return o[this.lang] || o.en; }; // localized name of a data object + P.fmt = function (x, dec) { + var s = x.toFixed(dec == null ? 2 : dec); + return this.lang === 'cs' ? s.replace('.', ',') : s; + }; + P.board = function () { var s = this.s; return this.d.boards.filter(function (b) { return b.id === s.board; })[0]; }; + P.fw = function () { var s = this.s; return this.d.firmwares.filter(function (f) { return f.id === s.firmware; })[0]; }; + P.available = function (opt) { + if (opt === 'gps' && !this.board().gps) return false; + return this.fw().options.indexOf(opt) >= 0; + }; + + // board defaults, then what the firmware ships with; options it lacks are pinned off + P.applyDefaults = function () { + var self = this, def = Object.assign({}, this.board().defaults, this.fw().defaults); + Object.keys(this.d.settings).forEach(function (k) { + var vals = self.d.settings[k]; + if (!self.available(k)) self.s[k] = vals.indexOf('off') >= 0 ? 'off' : vals[0]; + else if (def[k] != null) self.s[k] = def[k]; + else if (vals.indexOf(self.s[k]) < 0) self.s[k] = vals[0]; + }); + }; + + // radio current in TX, linear between the points of the data file + P.txCurrent = function (dbm) { + var pts = this.d.traffic.tx_current.points.slice().sort(function (a, b) { return a.dbm - b.dbm; }); + if (dbm <= pts[0].dbm) return pts[0].value; + for (var i = 1; i < pts.length; i++) { + if (dbm <= pts[i].dbm) { + var a = pts[i - 1], b = pts[i]; + return Math.round(a.value + (b.value - a.value) * (dbm - a.dbm) / (b.dbm - a.dbm)); + } + } + return pts[pts.length - 1].value; + }; + + // LoRa time on air, Semtech SX1262 datasheet / AN1200.13: explicit header, CRC on + P.airtime = function () { + var s = this.s, sf = +s.sf, bw = +s.bw * 1000, cr = +s.cr - 4; + var tsym = Math.pow(2, sf) / bw; + var de = tsym > 0.016 ? 1 : 0; + var num = 8 * s.payload - 4 * sf + 28 + 16; + var nPay = 8 + Math.max(Math.ceil(num / (4 * (sf - 2 * de))) * (cr + 4), 0); + return (+s.preamble + 4.25) * tsym + nPay * tsym; + }; + + P.range = function (v) { return Array.isArray(v) ? [Math.min(v[0], v[1]), Math.max(v[0], v[1])] : [v, v]; }; + + P.pickBaseline = function () { + var s = this.s, keys = Object.keys(this.d.settings); + var rows = this.d.values.filter(function (v) { return v.kind === 'baseline' && v.board === s.board; }); + var same = rows.filter(function (v) { return v.firmware === s.firmware; }); + var pool = same.length ? same : rows; + function diff(v) { return keys.filter(function (k) { return v.settings[k] !== s[k]; }).length; } + pool.sort(function (a, b) { + return diff(a) - diff(b) || (b.measured - a.measured) || (a.firmware === 'tth' ? -1 : 1); + }); + return { row: pool[0], borrowed: !same.length }; + }; + + // delta rows of one option between two values, best match first: + // same board and firmware, same board, any board + P.findDelta = function (opt, from, to) { + var s = this.s, best = null; + this.d.values.forEach(function (v) { + if (v.kind !== 'delta' || v.option !== opt) return; + var sign = v.from === from && v.to === to ? 1 : v.from === to && v.to === from ? -1 : 0; + if (!sign) return; + var fwOk = v.firmware === '*' || v.firmware === s.firmware; + var rank = (v.board === s.board ? 0 : 2) + (fwOk ? 0 : 1); + if (!best || rank < best.rank) best = { row: v, sign: sign, rank: rank }; + }); + return best; + }; + + P.compute = function () { + var self = this, s = this.s, d = this.d, lines = []; + var pb = this.pickBaseline(), b = pb.row; + var u = b.uncertainty || 0, bmeas = b.measured && !pb.borrowed; + var bnote = b.firmware !== s.firmware ? this.t('borrowed') + ' ' + this.n(this.fwById(b.firmware)) : null; + lines.push({ label: this.t('base') + ' (' + this.settingsText(b) + ')', lo: b.value - u, hi: b.value + u, + approx: b.approx, measured: bmeas, row: b, note: bnote || (b['note_' + this.lang] || b.note_en) }); + + if (pb.borrowed) { // offset between the two firmwares, measured on another board + var off = this.fwOffset(b); + if (off) lines.push({ label: this.t('fwoffset') + ' ' + this.n(this.boardById(off.board)), lo: off.value, hi: off.value, measured: false, row: off.row }); + else lines.push({ label: this.t('nofwoffset'), lo: 0, hi: 0, measured: false, row: null, nonum: true }); + } + + Object.keys(d.settings).forEach(function (k) { + var from = b.settings[k], to = s[k]; + if (from === to || from == null) return; + var path = [], dd = self.findDelta(k, from, to); + if (dd) path.push(dd); + else d.settings[k].some(function (mid) { // one step through an intermediate value + var a = self.findDelta(k, from, mid), c = a && self.findDelta(k, mid, to); + if (a && c) { path.push(a, c); return true; } + return false; + }); + if (!path.length) { + lines.push({ label: k + ': ' + from + ' → ' + to, nonum: true, measured: false, row: null, lo: 0, hi: 0, note: '?' }); + return; + } + path.forEach(function (p) { + var r = self.range(p.row.value).map(function (x) { return x * p.sign; }); + var meas = p.row.measured && p.rank === 0; + var note = p.rank ? self.t('borrowed') + ' ' + self.n(self.boardById(p.row.board)) + + (p.row.firmware !== '*' ? ' / ' + self.n(self.fwById(p.row.firmware)) : '') : null; + lines.push({ label: k + ': ' + (p.sign > 0 ? p.row.from + ' → ' + p.row.to : p.row.to + ' → ' + p.row.from), + lo: Math.min(r[0], r[1]), hi: Math.max(r[0], r[1]), approx: p.row.approx, measured: meas, row: p.row, + note: note || (p.row['note_' + self.lang] || p.row.note_en), cost: self.cost(k, to) }); + }); + }); + + var at = this.airtime(); + var tx = s.tx_per_h * at / 3600 * s.tx_ma, rx = s.rx_per_h * at / 3600 * s.rx_extra; + lines.push({ label: this.t('txline') + ' (' + s.tx_per_h + '/h × ' + this.fmt(at * 1000, 0) + ' ms × ' + s.tx_ma + ' mA)', lo: tx, hi: tx, measured: false, row: null }); + lines.push({ label: this.t('rxline') + ' (' + s.rx_per_h + '/h × ' + this.fmt(at * 1000, 0) + ' ms × ' + s.rx_extra + ' mA)', lo: rx, hi: rx, measured: false, row: null }); + + var lo = 0, hi = 0, allMeas = true; + lines.forEach(function (l) { lo += l.lo; hi += l.hi; if (!l.measured) allMeas = false; }); + return { lines: lines, lo: lo, hi: hi, allMeasured: allMeas, airtime: at, voltage: b.voltage }; + }; + + P.fwById = function (id) { return this.d.firmwares.filter(function (f) { return f.id === id; })[0] || { en: id }; }; + P.boardById = function (id) { return this.d.boards.filter(function (f) { return f.id === id; })[0] || { en: id }; }; + P.settingsText = function (row) { + var self = this; + return Object.keys(row.settings).filter(function (k) { + return k !== 'gps' || self.board().gps; + }).map(function (k) { return k + ' ' + row.settings[k]; }).join(', '); + }; + + // (chosen firmware) - (baseline's firmware) with identical settings on another board + P.fwOffset = function (b) { + var s = this.s, vals = this.d.values, found = null; + vals.forEach(function (a) { + if (found || a.kind !== 'baseline' || a.firmware !== s.firmware || a.board === b.board) return; + vals.forEach(function (c) { + if (found || c.kind !== 'baseline' || c.board !== a.board || c.firmware !== b.firmware) return; + if (JSON.stringify(a.settings) === JSON.stringify(c.settings)) found = { board: a.board, value: a.value - c.value, row: a }; + }); + }); + return found; + }; + + P.cost = function (opt, to) { + return this.d.values.filter(function (v) { return v.kind === 'reception' && v.option === opt && v.to === to; })[0]; + }; + + P.srcLink = function (key) { + var src = this.d.sources[key]; + if (!src) return document.createTextNode(key || ''); + if (!src.url) return document.createTextNode(this.n(src)); + var parts = src.url.split('#'), p = parts[0]; + // mkdocs directory URLs: power.md -> power/, a/index.md -> a/ + p = p.replace(/(^|\/)index\.md$/, '$1').replace(/\.md$/, '/'); + var href = new URL(p, this.base).href + (parts[1] ? '#' + parts[1] : ''); + return el('a', { href: href, text: this.n(src) }); + }; + + P.badge = function (m) { + return el('span', { 'class': m ? 'pc-m' : 'pc-e', text: m ? this.t('measured') : this.t('estimate') }); + }; + + P.build = function () { + var self = this, s = this.s, d = this.d; + this.root.textContent = ''; + var langBtn = el('button', { type: 'button', 'class': 'pc-lang', text: this.t('lang') }); + langBtn.addEventListener('click', function () { self.lang = self.lang === 'cs' ? 'en' : 'cs'; self.build(); }); + this.root.appendChild(langBtn); + + function sel(key, opts, disabled) { + var e = el('select', { name: key }); + opts.forEach(function (o) { + var op = el('option', { value: o.v, text: o.t }); + if (String(s[key]) === String(o.v)) op.selected = true; + e.appendChild(op); + }); + if (disabled) e.disabled = true; + return e; + } + function num(key, step) { return el('input', { type: 'number', name: key, value: s[key], step: step || 'any', min: key === 'tx_dbm' ? '-9' : '0' }); } + function row(key, input, extra) { + return el('div', { 'class': 'pc-row' }, [el('label', { text: self.t(key) }), input, extra || null]); + } + + var form = el('form', { 'class': 'pc-form' }); + form.appendChild(el('h3', { text: this.t('node') })); + form.appendChild(row('board', sel('board', d.boards.map(function (b) { return { v: b.id, t: self.n(b) }; })))); + form.appendChild(row('firmware', sel('firmware', d.firmwares.map(function (f) { return { v: f.id, t: self.n(f) }; })))); + form.appendChild(el('h3', { text: this.t('settings') })); + Object.keys(d.settings).forEach(function (k) { + if (k === 'gps' && !self.board().gps) return; + var on = self.available(k); + var c = self.cost(k, s[k]); + var extra = !on ? el('span', { 'class': 'pc-note', text: self.t('unavailable') }) : + c ? el('span', { 'class': 'pc-cost' }, [self.t('cost') + ': ' + self.n(c) + ' ', self.badge(c.measured)]) : null; + form.appendChild(row(k, sel(k, d.settings[k].map(function (v) { return { v: v, t: v }; }), !on), extra)); + }); + form.appendChild(el('h3', { text: this.t('traffic') })); + ['rx_per_h', 'tx_per_h', 'payload'].forEach(function (k) { form.appendChild(row(k, num(k, 1))); }); + form.appendChild(row('sf', sel('sf', [7, 8, 9, 10, 11, 12].map(function (v) { return { v: v, t: v }; })))); + form.appendChild(row('bw', sel('bw', [62.5, 125, 250].map(function (v) { return { v: v, t: v }; })))); + form.appendChild(row('cr', sel('cr', [5, 6, 7, 8].map(function (v) { return { v: v, t: '4/' + v }; })))); + form.appendChild(row('preamble', num('preamble', 1))); + form.appendChild(row('tx_dbm', num('tx_dbm', 1))); + form.appendChild(row('tx_ma', num('tx_ma'), this.badge(false))); + form.appendChild(row('rx_extra', num('rx_extra'), this.badge(false))); + form.appendChild(el('h3', { text: this.t('battery') })); + ['mah', 'usable_pct', 'voltage', 'panel_w', 'sun_h', 'charge_eff_pct'].forEach(function (k) { form.appendChild(row(k, num(k))); }); + + form.addEventListener('input', function (ev) { + var t = ev.target, k = t.name; + if (!k) return; + var v = t.tagName === 'SELECT' && isNaN(+t.value) ? t.value : +t.value; + if (t.type === 'number' && t.value === '') return; + s[k] = v; + if (k === 'tx_dbm') s.tx_ma = self.txCurrent(v); + if (k === 'board' || k === 'firmware') self.applyDefaults(); + if (t.tagName === 'SELECT' || k === 'tx_dbm') self.build(); // dependent fields + else self.render(); + }); + form.addEventListener('submit', function (ev) { ev.preventDefault(); }); + + this.out = el('div', { 'class': 'pc-out' }); + this.root.appendChild(el('div', { 'class': 'pc-grid' }, [ + el('div', {}, [el('h2', { text: this.t('title') }), form]), + el('div', {}, [el('h2', { text: this.t('result') }), this.out]) + ])); + this.table = el('div', { 'class': 'pc-values' }); + this.root.appendChild(el('details', {}, [el('summary', { text: this.t('values') }), this.table])); + this.renderValues(); + this.render(); + }; + + P.render = function () { + var self = this, s = this.s, r = this.compute(), out = this.out; + out.textContent = ''; + var tb = el('tbody'); + r.lines.forEach(function (l) { + var val = l.nonum ? '' : (l.approx ? '~' : '') + (l.lo === l.hi ? self.fmt(l.lo) : self.fmt(l.lo) + ' … ' + self.fmt(l.hi)) + ' mA'; + var info = [self.badge(l.measured)]; + if (l.row && l.row.source) info.push(' ', self.srcLink(l.row.source)); + if (l.row && l.row.date) info.push(' (' + l.row.date + ')'); + if (l.note) info.push(el('div', { 'class': 'pc-note', text: l.note })); + if (l.cost) info.push(el('div', { 'class': 'pc-cost' }, [self.t('cost') + ': ' + self.n(l.cost) + ' ', self.badge(l.cost.measured)])); + tb.appendChild(el('tr', {}, [el('td', { text: l.label }), el('td', { 'class': 'pc-num', text: val }), el('td', {}, info)])); + }); + out.appendChild(el('table', { 'class': 'pc-lines' }, [tb])); + + var mid = (r.lo + r.hi) / 2, perDay = mid * 24, usable = s.mah * s.usable_pct / 100; + function kv(k, v, m) { + return el('tr', {}, [el('th', { text: k }), el('td', { 'class': 'pc-num', text: v }), el('td', {}, [m === undefined ? self.badge(r.allMeasured) : m])]); + } + var rng = r.lo === r.hi ? '' : ' (' + self.fmt(r.lo) + ' … ' + self.fmt(r.hi) + ')'; + var rows = [ + kv(this.t('avg'), this.fmt(mid) + ' mA' + rng), + kv(this.t('perday'), this.fmt(perDay, 0) + ' mAh'), + kv(this.t('autonomy'), this.fmt(usable / perDay, 1) + ' ' + this.t('days')) + ]; + if (s.panel_w > 0) { + var gain = s.panel_w * s.sun_h * (s.charge_eff_pct / 100) / s.voltage * 1000; + var bal = gain - perDay; + rows.push(kv(this.t('solar'), this.fmt(gain, 0) + ' mAh', this.badge(false))); + rows.push(kv(this.t('balance'), (bal >= 0 ? '+' : '') + this.fmt(bal, 0) + ' mAh', el('span', {}, [this.badge(false), ' ', + bal >= 0 ? this.t('positive') : this.t('emptyin') + ' ' + this.fmt(usable / -bal, 1) + ' ' + this.t('days')]))); + } + out.appendChild(el('table', { 'class': 'pc-sum' }, [el('tbody', {}, rows)])); + out.appendChild(el('p', { 'class': 'pc-note', text: this.t('airtime') + ': ' + this.fmt(r.airtime * 1000, 0) + ' ms. ' + + this.t('voltnote') + ' ' + this.fmt(r.voltage, 2) + ' V. ' + this.t('battnote') })); + }; + + P.renderValues = function () { + var self = this, d = this.d; + var head = el('tr', {}, ['kind', 'board', 'firmware', 'option', 'value', 'date', '', 'src'].map(function (k) { + return el('th', { text: k === 'kind' || k === 'board' || k === 'firmware' || k === 'option' || k === 'value' || k === 'date' || k === 'src' ? self.t(k) : '' }); + })); + var body = el('tbody'); + d.values.forEach(function (v) { + var what = v.kind === 'baseline' ? self.settingsAll(v) : v.option ? v.option + ': ' + (v.from ? v.from + ' → ' : '') + (v.to || '') : ''; + if (v.kind === 'reception' || v.kind === 'info') what += (what ? ' - ' : '') + self.n(v); + var val = v.value == null ? '' : (v.approx ? '~' : '') + (Array.isArray(v.value) ? self.fmt(v.value[0]) + ' … ' + self.fmt(v.value[1]) : self.fmt(v.value)) + + (v.uncertainty ? ' ± ' + self.fmt(v.uncertainty) : '') + ' ' + (v.unit || '') + (v.voltage ? ' @ ' + self.fmt(v.voltage, 2) + ' V' : ''); + body.appendChild(el('tr', {}, [ + el('td', { text: v.kind }), el('td', { text: v.board || '' }), el('td', { text: v.firmware || '' }), + el('td', { text: what }), el('td', { 'class': 'pc-num', text: val }), el('td', { text: v.date || '' }), + el('td', {}, [self.badge(v.measured)]), el('td', {}, [self.srcLink(v.source)]) + ])); + }); + this.table.appendChild(el('table', {}, [el('thead', {}, [head]), body])); + }; + P.settingsAll = function (v) { return Object.keys(v.settings).map(function (k) { return k + ' ' + v.settings[k]; }).join(', '); }; + + if (document.readyState === 'loading') document.addEventListener('DOMContentLoaded', start); + else start(); +})(); diff --git a/docs/_stylesheets/tth.css b/docs/_stylesheets/tth.css index 0a049724e..e8fdf7261 100644 --- a/docs/_stylesheets/tth.css +++ b/docs/_stylesheets/tth.css @@ -34,3 +34,18 @@ .admonition.important > .admonition-title { color: var(--primary-color); } + +/* power calculator (power-calculator.md) */ +.pc-grid { display: grid; grid-template-columns: minmax(18em, 28em) 1fr; gap: 2em; } +@media (max-width: 60em) { .pc-grid { grid-template-columns: 1fr; } } +.pc-row { display: grid; grid-template-columns: 14em 1fr; gap: 0.2em 0.6em; align-items: center; margin: 0.15em 0; } +.pc-row > span { grid-column: 2; font-size: 0.85em; } +.pc-row select, .pc-row input { width: 100%; } +.pc-num { text-align: right; white-space: nowrap; } +.pc-m, .pc-e { font-size: 0.8em; padding: 0 0.3em; border: 1px solid; } +.pc-m { color: var(--primary-color); } +.pc-e { color: #e5a50a; } +.pc-cost { color: #e5a50a; font-size: 0.85em; } +.pc-note { font-size: 0.85em; opacity: 0.8; } +.pc-lang { float: right; } +.pc-values { overflow-x: auto; } diff --git a/docs/power-calculator.md b/docs/power-calculator.md new file mode 100644 index 000000000..779e3f728 --- /dev/null +++ b/docs/power-calculator.md @@ -0,0 +1,49 @@ +# Power calculator / Kalkulačka spotřeby + +Pick a board, firmware, settings, traffic and battery; the page adds up the +expected average current, energy per day and autonomy. Every line says whether +its number was **measured** or is an **estimate**, and where it comes from. +Česky: tlačítko „Česky" na stránce (odkaz s `#cs` ji otevře rovnou česky). + +
+ +> [!NOTE] +> The page is interactive on the docs site, +> https://tth-pub.pages.rfa.cz/meshcore-tth/power-calculator/ (a repository +> browser shows only this text). + +## How it computes + +- **Baseline:** the measured whole-node current of the chosen board and + firmware whose settings are closest to yours (no traffic, radio in RX). +- **Options:** for every setting that differs from that baseline, the paired + A/B delta from [power.md](power.md#summary-every-option-against-stock-firmware). + A delta measured on another board or firmware is used, but shown as an + estimate ("taken from ..."). +- **Traffic:** LoRa time on air with the Semtech formula (explicit header, + CRC on) for the packet length, SF, BW, CR and preamble; transmissions cost + the TX current at the set power, receptions an extra current while the packet + is being received. Both currents are **estimates** you can overwrite: the + TX one is interpolated from the SX1262 datasheet (14 dBm 45 mA, 22 dBm + 118 mA), below 14 dBm a guess. The baseline already contains the radio in RX. +- **Battery:** usable mAh / (average mA × 24 h). The node is assumed to draw + the same current from the cell (linear regulator); the absolute currents + belong to the measurement rig (XIAO at 3.26 V on its 3V3 pin, P1-Pro on the + 5 V USB side). +- **Solar:** panel W × full-sun hours × charging efficiency / battery voltage. + +**rxps is not free.** `radio.rxps balanced` and `max` save about 2 mA but lose +13-28 % of weak packets (SNR −2..−8) against none without it (bench +4. 12. 2026, [details](power.md#rx-duty-cycle-rxps)); the page shows that cost +next to the option. Use it only where packets arrive strong, never on a mast. + +## Data + +All numbers live in one file, +[`power-data.json`](https://git.rfa.cz/tth-pub/meshcore-tth/src/branch/main/docs/power-data.json): +each value with board, value, unit, date, source and `measured`. A new +measurement (the planned overnight re-measurement of every option on the same +rig) is a new row there, without touching the page; the whole table is also at +the bottom of the calculator. diff --git a/docs/power-data.json b/docs/power-data.json new file mode 100644 index 000000000..fb5ed51bb --- /dev/null +++ b/docs/power-data.json @@ -0,0 +1,258 @@ +{ + "_comment": [ + "Data of the power calculator (docs/power-calculator.md). The ONE place for", + "its numbers: the page reads this file, the JS holds no value. Every row of", + "`values` carries board, value, unit, date, source and measured; a new", + "measurement is a new row (or an edited one), no code change.", + "kind baseline: whole-node current of a board + firmware with the given", + "settings, no traffic. kind delta: change of current when `option` goes", + "from `from` to `to` on that board/firmware ('*' = not tied to a firmware);", + "value is a number or [min, max]. kind reception: what an option costs in", + "reception, shown next to it. kind info: shown in the table only.", + "Settings start at the board's defaults, then the firmware's (as shipped).", + "The calculator picks the baseline whose settings are closest to the chosen", + "ones and adds the deltas of the rest; a delta borrowed from another board", + "or firmware is shown as an estimate." + ], + "schema": 1, + "sources": { + "protocol-2026-12-04": { + "url": "measurements/2026-12-04-stock-vs-tth/protocol.md", + "en": "measurement protocol 4. 12. 2026 (stock vs this fork, k = 2)", + "cs": "protokol měření 4. 12. 2026 (upstream vs tento fork, k = 2)" + }, + "bench-2026-12-04-czech": { + "url": "measurements/2026-12-04-stock-vs-tth/protocol.md", + "en": "bench 4. 12. 2026 (cells C and C2), protocol update pending", + "cs": "lavice 4. 12. 2026 (buňky C a C2), doplnění protokolu čeká" + }, + "power-summary": { + "url": "power.md#summary-every-option-against-stock-firmware", + "en": "docs/power.md, summary table", + "cs": "docs/power.md, souhrnná tabulka" + }, + "power-rxps": { + "url": "power.md#rx-duty-cycle-rxps", + "en": "docs/power.md, RX duty cycle (bench 4. 12. 2026, #46)", + "cs": "docs/power.md, RX duty cycle (lavice 4. 12. 2026, #46)" + }, + "power-gps": { + "url": "power.md#gps-is-the-whole-game", + "en": "docs/power.md, GPS", + "cs": "docs/power.md, GPS" + }, + "power-ble": { + "url": "power.md#ble-two-defaults-that-were-quietly-expensive", + "en": "docs/power.md, BLE", + "cs": "docs/power.md, BLE" + }, + "power-nrf52": { + "url": "power.md#nrf52-sleep-and-peripheral-fixes", + "en": "docs/power.md, nRF52 fixes", + "cs": "docs/power.md, opravy nRF52" + }, + "sx1262-datasheet": { + "url": "", + "en": "SX1262 datasheet (Semtech), not measured", + "cs": "datasheet SX1262 (Semtech), neměřeno" + }, + "estimate": { + "url": "", + "en": "rough estimate, not measured", + "cs": "hrubý odhad, neměřeno" + } + }, + "boards": [ + { + "id": "xiao", + "en": "XIAO nRF52840 + Wio-SX1262 (fed on 3V3)", + "cs": "XIAO nRF52840 + Wio-SX1262 (napájené na 3V3)", + "gps": false, + "defaults": { "ble": "off", "gps": "off" } + }, + { + "id": "p1pro", + "en": "SenseCAP Solar P1-Pro (nRF52840 + SX1262 + L76K GPS)", + "cs": "SenseCAP Solar P1-Pro (nRF52840 + SX1262 + GPS L76K)", + "gps": true, + "defaults": { "ble": "on", "gps": "duty" } + } + ], + "firmwares": [ + { + "id": "tth", + "en": "this fork (meshcore-tth public release)", + "cs": "tento fork (veřejný release meshcore-tth)", + "options": ["powersaving", "rxps", "rxgain", "ble", "gps"], + "defaults": { "powersaving": "on", "rxps": "off", "rxgain": "on" } + }, + { + "id": "stock", + "en": "upstream MeshCore v1.19.0", + "cs": "upstream MeshCore v1.19.0", + "options": ["powersaving", "rxgain", "ble", "gps"], + "defaults": { "powersaving": "off", "rxps": "off", "rxgain": "on" } + }, + { + "id": "czech", + "en": "MeshCore Czech v1.19.0.01", + "cs": "MeshCore Czech v1.19.0.01", + "options": ["powersaving", "rxps", "rxgain", "ble", "gps"], + "defaults": { "powersaving": "on", "rxps": "balanced", "rxgain": "on" } + } + ], + "settings": { + "powersaving": ["on", "off"], + "rxps": ["off", "balanced", "max"], + "rxgain": ["on", "off"], + "ble": ["off", "on"], + "gps": ["off", "duty", "on"] + }, + "values": [ + { + "kind": "baseline", "board": "xiao", "firmware": "tth", + "settings": { "powersaving": "on", "rxps": "off", "rxgain": "on", "ble": "off", "gps": "off" }, + "value": 6.87, "uncertainty": 0.08, "unit": "mA", "voltage": 3.26, + "date": "2026-12-04", "source": "protocol-2026-12-04", "measured": true + }, + { + "kind": "baseline", "board": "xiao", "firmware": "stock", + "settings": { "powersaving": "on", "rxps": "off", "rxgain": "on", "ble": "off", "gps": "off" }, + "value": 7.27, "uncertainty": 0.09, "unit": "mA", "voltage": 3.26, + "date": "2026-12-04", "source": "protocol-2026-12-04", "measured": true + }, + { + "kind": "baseline", "board": "xiao", "firmware": "stock", + "settings": { "powersaving": "off", "rxps": "off", "rxgain": "on", "ble": "off", "gps": "off" }, + "value": 10.13, "uncertainty": 0.12, "unit": "mA", "voltage": 3.26, + "date": "2026-12-04", "source": "protocol-2026-12-04", "measured": true + }, + { + "kind": "baseline", "board": "xiao", "firmware": "czech", + "settings": { "powersaving": "on", "rxps": "off", "rxgain": "on", "ble": "off", "gps": "off" }, + "value": 7.35, "unit": "mA", "voltage": 3.26, + "date": "2026-12-04", "source": "bench-2026-12-04-czech", "measured": true + }, + { + "kind": "baseline", "board": "xiao", "firmware": "czech", + "settings": { "powersaving": "on", "rxps": "balanced", "rxgain": "on", "ble": "off", "gps": "off" }, + "value": 5.45, "approx": true, "unit": "mA", "voltage": 3.26, + "date": "2026-12-04", "source": "bench-2026-12-04-czech", "measured": true + }, + { + "kind": "baseline", "board": "p1pro", "firmware": "tth", + "settings": { "powersaving": "on", "rxps": "off", "rxgain": "on", "ble": "on", "gps": "duty" }, + "value": 24, "approx": true, "unit": "mA", "voltage": 5.0, + "note_en": "mast configuration, 5 V USB side, charged cell", + "note_cs": "konfigurace stožáru, strana 5 V USB, nabitý článek", + "date": "2026-08", "source": "power-summary", "measured": true + }, + + { + "kind": "delta", "option": "powersaving", "from": "off", "to": "on", + "board": "xiao", "firmware": "stock", + "value": -2.86, "unit": "mA", "date": "2026-12-04", + "source": "protocol-2026-12-04", "measured": true + }, + { + "kind": "delta", "option": "powersaving", "from": "off", "to": "on", + "board": "xiao", "firmware": "tth", + "value": -2.7, "unit": "mA", "date": "2026-11", + "source": "power-summary", "measured": true + }, + { + "kind": "delta", "option": "rxps", "from": "off", "to": "balanced", + "board": "xiao", "firmware": "tth", + "value": [-2.0, -1.8], "unit": "mA", "date": "2026-11", + "source": "power-rxps", "measured": true + }, + { + "kind": "delta", "option": "rxps", "from": "off", "to": "max", + "board": "xiao", "firmware": "tth", + "value": [-2.5, -2.3], "unit": "mA", "date": "2026-11", + "source": "power-rxps", "measured": true + }, + { + "kind": "delta", "option": "rxgain", "from": "on", "to": "off", + "board": "xiao", "firmware": "tth", + "value": [-0.51, -0.45], "unit": "mA", "date": "2026-11", + "source": "power-nrf52", "measured": true + }, + { + "kind": "delta", "option": "ble", "from": "on", "to": "off", + "board": "p1pro", "firmware": "tth", + "value": -1, "approx": true, "unit": "mA", "date": "2026-08", + "source": "power-ble", "measured": true + }, + { + "kind": "delta", "option": "gps", "from": "duty", "to": "on", + "board": "p1pro", "firmware": "*", + "value": [42, 45], "unit": "mA", "date": "2026-08", + "note_en": "receiver 46 mA continuous; gps duty saves 42-45 mA of it", + "note_cs": "přijímač 46 mA trvale; gps duty z toho ušetří 42-45 mA", + "source": "power-gps", "measured": true + }, + { + "kind": "delta", "option": "gps", "from": "duty", "to": "off", + "board": "p1pro", "firmware": "*", + "value": [-4, -1], "unit": "mA", "date": "2026-08", + "note_en": "derived: 46 mA minus the 42-45 mA duty saves", + "note_cs": "dopočteno: 46 mA minus 42-45 mA, které ušetří duty", + "source": "power-gps", "measured": false + }, + + { + "kind": "reception", "option": "rxps", "to": "balanced", + "en": "loses 13-28 % of weak packets (SNR -2..-8) against 0 % without rxps; strong signal 0 lost. Not for a mast.", + "cs": "ztratí 13-28 % slabých paketů (SNR -2..-8) proti 0 % bez rxps; silný signál 0 ztrát. Ne na stožár.", + "date": "2026-12-04", "source": "power-rxps", "measured": true + }, + { + "kind": "reception", "option": "rxps", "to": "max", + "en": "as balanced or worse: 13-28 % of weak packets lost; on a live mast -16 % received. Not for a mast.", + "cs": "jako balanced nebo hůř: ztráta 13-28 % slabých paketů; na ostrém stožáru -16 % přijatých. Ne na stožár.", + "date": "2026-12-04", "source": "power-rxps", "measured": true + }, + { + "kind": "reception", "option": "rxgain", "to": "off", + "en": "costs ~1-3 dB of sensitivity (datasheet, not measured).", + "cs": "stojí ~1-3 dB citlivosti (datasheet, neměřeno).", + "source": "sx1262-datasheet", "measured": false + }, + + { + "kind": "info", "option": "dcdc", "board": "xiao", "firmware": "tth", + "en": "DC/DC regulator off (all firmwares have it on)", + "cs": "DC/DC regulátor vypnutý (všechny firmwary ho mají zapnutý)", + "value": 0.6, "unit": "mA", "voltage": 3.3, "date": "2026-11", + "source": "power-nrf52", "measured": true + } + ], + "traffic": { + "_comment": "Defaults of the traffic inputs and the current the radio adds while it transmits/receives. All of it is an ESTIMATE the reader can overwrite on the page.", + "defaults": { + "rx_per_h": 120, "tx_per_h": 60, "payload": 60, + "sf": 7, "bw": 62.5, "cr": 5, "preamble": 16, "tx_dbm": 22 + }, + "rx_extra": { + "value": 3, "unit": "mA", "measured": false, "source": "estimate", + "en": "extra current while a packet is being received (radio held in RX, MCU awake)", + "cs": "proud navíc po dobu příjmu paketu (rádio drženo v RX, MCU vzhůru)" + }, + "tx_current": { + "_comment": "radio current in TX by output power; the page interpolates linearly in dBm. 14 and 22 dBm are datasheet figures, the rest a guess.", + "unit": "mA", "voltage": 3.3, + "points": [ + { "dbm": -9, "value": 15, "measured": false, "source": "estimate" }, + { "dbm": 0, "value": 20, "measured": false, "source": "estimate" }, + { "dbm": 14, "value": 45, "measured": false, "source": "sx1262-datasheet" }, + { "dbm": 22, "value": 118, "measured": false, "source": "sx1262-datasheet" } + ] + } + }, + "battery": { + "_comment": "defaults of the battery and solar inputs; efficiency and voltage are assumptions", + "mah": 3000, "usable_pct": 80, "voltage": 3.7, + "panel_w": 0, "sun_h": 2, "charge_eff_pct": 70 + } +} diff --git a/docs/power.md b/docs/power.md index 1a5383957..089426225 100644 --- a/docs/power.md +++ b/docs/power.md @@ -15,6 +15,11 @@ release. Current is the paired delta of switching the option on (negative = saves). Reception is what another board counted on the bench, or the live mesh where it says so. +What it adds up to for your node (board, firmware, settings, traffic, battery, +panel): the [power calculator](power-calculator.md), which reads its numbers +from [`power-data.json`](power-data.json) -- update that file together with +this table. + | option | stock | here | current | reception / transmission | details | |---|---|---|---|---|---| | GPS `gps duty` (receiver powered only around a daily clock sync) | continuous (`gps on`) or `gps period` | `gps duty` on mast builds | **−42 to −45 mA** of 46 (P1-Pro) | no effect on the radio | [GPS](#gps-is-the-whole-game) | diff --git a/mkdocs.tth.yml b/mkdocs.tth.yml index 4c85e5cc6..304f471be 100644 --- a/mkdocs.tth.yml +++ b/mkdocs.tth.yml @@ -23,6 +23,11 @@ theme: extra_css: - _stylesheets/tth.css +# the power calculator (power-calculator.md, data power-data.json); the +# script does nothing on a page without
+extra_javascript: + - _js/power-calculator.js + plugins: - search @@ -46,6 +51,7 @@ nav: - Console commands: tth-commands.md - Firmware update by the admin (OTA): ota.md - Power saving: power.md + - Power calculator: power-calculator.md - Budka as a sensor: budka-sensor.md - BLE/LoRa coexistence: ble-lora-coexistence.md - MeshCore (upstream):