diff --git a/src/Mesh.cpp b/src/Mesh.cpp index 6443c2441..5423fa3d3 100644 --- a/src/Mesh.cpp +++ b/src/Mesh.cpp @@ -5,16 +5,22 @@ #include "helpers/ota/OtaProtocol.h" // decode_adv -> the `ota neighbors` discovery table #include "helpers/ota/OtaSelf.h" // ota_self_firmware -> auto-advertise our own image #ifndef OTA_ANNOUNCE_BOOT_MS -#define OTA_ANNOUNCE_BOOT_MS 30000UL // first self-advert ~30 s after boot (let the node settle) +#define OTA_ANNOUNCE_BOOT_MS 8000UL // first self-advert ~8 s after boot (settled, but quick to discover) #endif #ifndef OTA_ANNOUNCE_BURST #define OTA_ANNOUNCE_BURST 4 // a few closely-spaced boot adverts so co-booting peers catch one #endif #ifndef OTA_ANNOUNCE_BURST_MS -#define OTA_ANNOUNCE_BURST_MS 45000UL // spacing during the boot burst (~3 min total), then ... +#define OTA_ANNOUNCE_BURST_MS 20000UL // spacing during the boot burst (~1 min total), then ... #endif -#ifndef OTA_ANNOUNCE_INTERVAL_MS -#define OTA_ANNOUNCE_INTERVAL_MS 86400000UL // ... every 24 h — all lowest priority, duty-gated +// ... then re-announce at a RANDOM interval in [MIN, MAX] so a long-running node stays discoverable +// (a fresh `ota ls` neighbour sees it within minutes, not at boot only) without all nodes beaconing in +// lockstep. The beacon is tiny + lowest-priority + duty-gated, so a few-minute cadence is cheap. +#ifndef OTA_ANNOUNCE_INTERVAL_MIN_MS +#define OTA_ANNOUNCE_INTERVAL_MIN_MS 180000UL // 3 min +#endif +#ifndef OTA_ANNOUNCE_INTERVAL_MAX_MS +#define OTA_ANNOUNCE_INTERVAL_MAX_MS 600000UL // 10 min #endif #endif @@ -88,9 +94,12 @@ void Mesh::loop() { // beacon (announce) advertises our served set and peers can QUERY + fetch it. if (!oc.serving) oc.serving = ota::ota_serve_self(oc, 0); oc.manager.announce(); - // boot burst (a few closely-spaced adverts so a co-booting peer catches one), then settle to daily - _next_ota_announce = futureMillis(_ota_announce_count < OTA_ANNOUNCE_BURST - ? OTA_ANNOUNCE_BURST_MS : OTA_ANNOUNCE_INTERVAL_MS); + // boot burst (a few closely-spaced adverts so a co-booting peer catches one), then a random + // few-minute cadence so a node stays discoverable long after boot (not just at boot). + uint32_t gap = (_ota_announce_count < OTA_ANNOUNCE_BURST) + ? OTA_ANNOUNCE_BURST_MS + : _rng->nextInt(OTA_ANNOUNCE_INTERVAL_MIN_MS, OTA_ANNOUNCE_INTERVAL_MAX_MS); + _next_ota_announce = futureMillis(gap); if (_ota_announce_count < 250) _ota_announce_count++; } { // auto-install (once per COMPLETE fetch): only signed images, and apply_fetched enforces trust diff --git a/src/helpers/ota/OtaCli.cpp b/src/helpers/ota/OtaCli.cpp index b5cb34067..e35955b55 100644 --- a/src/helpers/ota/OtaCli.cpp +++ b/src/helpers/ota/OtaCli.cpp @@ -141,13 +141,16 @@ bool handle_ota_command(const char* command, char* reply, mesh::MainBoard& board bool on = cur && memcmp(cur, h->mid, 4) == 0; uint32_t age = (now - h->last_ms) / 1000; if (age > 99999) age = 99999; char ver[20]; ver_str(ver, sizeof ver, h->fw_version); - // What is this update for? "yours" if same hw+role as us; else the target's env name when we know it - // (named locally from its 4-byte target_id — no string travels on the wire); else other hw / '?'. + // What is this update for? "yours" if same target (hw+role) as us; else the target's env name when we + // know it (named locally from its 4-byte target_id — no string travels on the wire); else the raw + // target_id hex (an env this build's OtaTargets.h table doesn't know) or '?' for an unset target. + char hwbuf[16]; const char* fit; const char* env = ota_target_env_name(h->target_id); if (myt && h->target_id == myt) fit = "yours"; else if (env) fit = env; - else fit = (h->target_id == 0) ? "?" : "other hw"; + else if (h->target_id == 0) fit = "?"; + else { snprintf(hwbuf, sizeof hwbuf, "hw %08X", (unsigned)h->target_id); fit = hwbuf; } n += snprintf(reply + n, CAP - n, "\n %d) %s %s [%s] %un %us%s", shown + 1, ver, codec_kind(h->codec), fit, (unsigned)h->n_seeders, (unsigned)age, on ? " [downloading]" : "");