From a3e47b93cf9cbe59ac9dfd35935e30b8b9b99f60 Mon Sep 17 00:00:00 2001 From: "Enot (ded) Skelly" Date: Fri, 17 Apr 2026 13:26:11 -0700 Subject: [PATCH] load radio settings from prefs for repeaters --- zephcore/src/main_repeater.cpp | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/zephcore/src/main_repeater.cpp b/zephcore/src/main_repeater.cpp index 3dc483b..6aea6a7 100644 --- a/zephcore/src/main_repeater.cpp +++ b/zephcore/src/main_repeater.cpp @@ -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) {