Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LoRa: set frequency from settings #24

Open
rhaamo opened this issue Jun 21, 2022 · 1 comment
Open

LoRa: set frequency from settings #24

rhaamo opened this issue Jun 21, 2022 · 1 comment

Comments

@rhaamo
Copy link

rhaamo commented Jun 21, 2022

Instead of having to rebuild the firmware on each update

@xopr
Copy link

xopr commented Aug 12, 2022

I haven't tested this yet, but I think if the following patch is applied to the source upstream, one could add the following segment to
configs.ini (which might make it a valuable addition):

[lora]
lora_freq=868.0

lora.patch:

diff --git a/lora.cpp b/lora.cpp
index 6b03536..ae1833b 100644
--- a/lora.cpp
+++ b/lora.cpp
@@ -43,7 +43,20 @@ void Lora::setup() {
   loraSPI->setPins(HSPI_MISO, HSPI_MOSI, HSPI_SCLK);
   pinMode(RFM95_RST, OUTPUT);
   rf95->init();
-  rf95->setFrequency(RF95_FREQ);
+
+
+  float freq = RF95_FREQ;
+  // Load phone configs
+  {
+    CriticalFile ini(Storage::ConfigsFile);
+    if ((ini.load() || ini.restore()) && !ini.isEmpty()) {
+      if (ini[0].hasKey("v") && !strcmp(ini[0]["v"], "1")) {    // check version of the file format
+        if ( ini.hasSection("lora") )
+          freq = ini["lora"].getFloatValueSafe("lora_freq", RF95_FREQ);
+      }
+    }
+  }
+  rf95->setFrequency(freq);
   rf95->setTxPower(23, false);
 
   log_v("Free memory after LoRa: %d %d", ESP.getFreeHeap(), heap_caps_get_free_size(MALLOC_CAP_32BIT));

Note that it might need better orchestration of the ini file parsing; it's a bit inline-hacky.
Also: it is only applied after reboot: for full functionality, the setFrequency() needs to be taken out of the setup() function.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants