load radio settings from prefs for repeaters

This commit is contained in:
Enot (ded) Skelly
2026-04-17 13:26:11 -07:00
parent d2cec84100
commit a3e47b93cf
+30
View File
@@ -470,9 +470,39 @@ int main(void)
self_identity.pub_key[4], self_identity.pub_key[5],
self_identity.pub_key[6], self_identity.pub_key[7]);
/* Pre-load persisted prefs into radio_prefs BEFORE repeater_mesh.begin().
*
* Rationale: lora_radio was constructed at static-init time with a pointer
* to radio_prefs (see line ~286). When repeater_mesh.begin() runs, it
* calls Mesh::begin() -> Dispatcher::begin() -> _radio->begin(), which
* reads freq/bw/sf/cr through that pointer to configure the hardware.
*
* Without this pre-load, the radio boots on the compile-time defaults
* from initNodePrefs() (freq=869.618, EU ISM band) regardless of what the
* user configured. RepeaterMesh::begin() then loads the persisted prefs
* into its own _prefs member, so CLI/UI readback shows the correct saved
* values — but the hardware is already configured on the stale defaults
* and never gets reconfigured. The result: device appears operational on
* the configured frequency but is physically tuned to 869.618 MHz, so
* transmissions are not heard and no packets can be received.
*
* This went unnoticed in the EU because 869.618 happens to match the
* default; US/CA users on 910.525 (and any other non-default freq) hit it.
*
* Mirrors the temp_prefs pattern in main_companion.cpp. The subsequent
* setPrefs() rebind (after begin()) points the radio at the live prefs in
* RepeaterMesh so CLI `set radio` changes take effect on reconfigure(). */
data_store.loadPrefs(radio_prefs);
/* Start mesh with data store - this loads prefs, ACL, regions */
repeater_mesh.begin(&data_store);
/* Rebind radio prefs pointer to the live prefs inside repeater_mesh.
* radio_prefs above was a one-time copy for static init; from here on,
* the radio must read from the same struct RepeaterMesh mutates so that
* CLI-driven reconfigure() calls see current values. */
lora_radio.setPrefs(repeater_mesh.getNodePrefs());
/* Generate default node name from hardware device ID if not set */
NodePrefs* prefs = repeater_mesh.getNodePrefs();
if (strlen(prefs->node_name) == 0 || strcmp(prefs->node_name, "Repeater") == 0) {