meshcore_fw_ota: OTA firmware update of a meshcore-tth repeater, over RF or its BLE console
ci / test (push) Successful in 2m21s

Picks the package of a release that fits the image `fw status` reports
(changed=false when the node runs it already, no_package when none fits or
the node has no `fw`), transfers it -- over RF as binary chunks with a
bitmap of the missing ones and text chunks as the fallback, inside an
airtime budget; over the BLE console as text, a full image too -- then
verifies and applies. Port of tools/ota_mesh_push.py / ota_push.py of
meshcore-tth; radio-free parts in module_utils/meshcore_ota.py with unit
tests (the airtime formula they caught is fixed in the tool as well).
Link.cli takes retries, timeout, quiet and a before_send hook.

Tested on two live repeaters forced onto their current image (BLE console;
RF through a companion: 'current', 0.6 s airtime) and with a package of
another base (no_package).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
tthandClaude Opus 5.5 committed 2026-11-14 20:54:29 +01:00
1 parent d6f2d5cf28
commit 891be3afbe
7 files changed
+966 -5

No files matched your search

+13 -4
View File
@@ -187,29 +187,38 @@ class Link:
pfx = (msg.get("pubkey_prefix") or "").lower()
return bool(pfx) and self.target_pk.startswith(pfx)
async def cli(self, cmd, expect):
async def cli(self, cmd, expect, retries=None, timeout=None, quiet=False, before_send=None):
"""Send one CLI command and return the reply text that matches `expect` (regex).
A reply that does not match (a late answer to an earlier command, or
another node) is drained and the command is resent, up to `retries`.
quiet: no trace line on success (hundreds of firmware chunks).
before_send: awaited before every attempt (the OTA airtime budget).
"""
retries = self.retries if retries is None else retries
timeout = self.reply_timeout if timeout is None else timeout
# never log a secret the command carries (the trace is returned to Ansible)
shown = cmd
for secret_cmd in ("password ", "ble pin "):
if cmd.startswith(secret_cmd):
shown = secret_cmd + "***"
for attempt in range(1 + self.retries):
if quiet and len(shown) > 24:
shown = shown[:24] + "..."
for attempt in range(1 + retries):
self.inbox.clear()
if before_send is not None:
await before_send()
if self.companion:
await self.send_cli_command(cmd)
else:
await self.mc.commands.send_cmd(self.contact, cmd)
deadline = time.monotonic() + self.reply_timeout
deadline = time.monotonic() + timeout
while time.monotonic() < deadline:
for msg in list(self.inbox):
text = (msg.get("text") or "").strip()
if self._from_target(msg) and re.search(expect, text):
self.log.append(f"$ {shown} -> {self._redact(text)}")
if not quiet:
self.log.append(f"$ {shown} -> {self._redact(text)}")
# The reply carries the NODE's clock: what fw_facts reports as skew.
self.last_reply_ts = msg.get("sender_timestamp")
self.last_reply_at = time.time()