From 565df7df4a46f1bb965decc51c1225600b699926 Mon Sep 17 00:00:00 2001 From: MGJ <62177301+MGJ520@users.noreply.github.com> Date: Fri, 20 Feb 2026 23:02:22 +0800 Subject: [PATCH] Fix the bug where no information can be received the first time after reconfiguring the radio --- examples/companion_radio/MyMesh.cpp | 3 +++ examples/simple_repeater/MyMesh.cpp | 6 ++++++ examples/simple_room_server/MyMesh.cpp | 6 ++++++ examples/simple_sensor/SensorMesh.cpp | 6 ++++++ src/Dispatcher.h | 2 ++ 5 files changed, 23 insertions(+) diff --git a/examples/companion_radio/MyMesh.cpp b/examples/companion_radio/MyMesh.cpp index 99b14952f..95b843f1a 100644 --- a/examples/companion_radio/MyMesh.cpp +++ b/examples/companion_radio/MyMesh.cpp @@ -1259,6 +1259,9 @@ void MyMesh::handleCmdFrame(size_t len) { savePrefs(); radio_set_params(_prefs.freq, _prefs.bw, _prefs.sf, _prefs.cr); + //You need to clear the old registers, otherwise the LoRa module won't receive any information the first time. + _radio->onSendFinished(); + _radio->startRecv(); MESH_DEBUG_PRINTLN("OK: CMD_SET_RADIO_PARAMS: f=%d, bw=%d, sf=%d, cr=%d", freq, bw, (uint32_t)sf, (uint32_t)cr); diff --git a/examples/simple_repeater/MyMesh.cpp b/examples/simple_repeater/MyMesh.cpp index b6d855f68..fdb29dbd6 100644 --- a/examples/simple_repeater/MyMesh.cpp +++ b/examples/simple_repeater/MyMesh.cpp @@ -1253,12 +1253,18 @@ void MyMesh::loop() { if (set_radio_at && millisHasNowPassed(set_radio_at)) { // apply pending (temporary) radio params set_radio_at = 0; // clear timer radio_set_params(pending_freq, pending_bw, pending_sf, pending_cr); + //You need to clear the old registers, otherwise the LoRa module won't receive any information the first time. + _radio->onSendFinished(); + _radio->startRecv(); MESH_DEBUG_PRINTLN("Temp radio params"); } if (revert_radio_at && millisHasNowPassed(revert_radio_at)) { // revert radio params to orig revert_radio_at = 0; // clear timer radio_set_params(_prefs.freq, _prefs.bw, _prefs.sf, _prefs.cr); + //You need to clear the old registers, otherwise the LoRa module won't receive any information the first time. + _radio->onSendFinished(); + _radio->startRecv(); MESH_DEBUG_PRINTLN("Radio params restored"); } diff --git a/examples/simple_room_server/MyMesh.cpp b/examples/simple_room_server/MyMesh.cpp index 598b14de6..c12db17c3 100644 --- a/examples/simple_room_server/MyMesh.cpp +++ b/examples/simple_room_server/MyMesh.cpp @@ -870,12 +870,18 @@ void MyMesh::loop() { if (set_radio_at && millisHasNowPassed(set_radio_at)) { // apply pending (temporary) radio params set_radio_at = 0; // clear timer radio_set_params(pending_freq, pending_bw, pending_sf, pending_cr); + //You need to clear the old registers, otherwise the LoRa module won't receive any information the first time. + _radio->onSendFinished(); + _radio->startRecv(); MESH_DEBUG_PRINTLN("Temp radio params"); } if (revert_radio_at && millisHasNowPassed(revert_radio_at)) { // revert radio params to orig revert_radio_at = 0; // clear timer radio_set_params(_prefs.freq, _prefs.bw, _prefs.sf, _prefs.cr); + //You need to clear the old registers, otherwise the LoRa module won't receive any information the first time. + _radio->onSendFinished(); + _radio->startRecv(); MESH_DEBUG_PRINTLN("Radio params restored"); } diff --git a/examples/simple_sensor/SensorMesh.cpp b/examples/simple_sensor/SensorMesh.cpp index f05fb245c..afc677b19 100644 --- a/examples/simple_sensor/SensorMesh.cpp +++ b/examples/simple_sensor/SensorMesh.cpp @@ -882,12 +882,18 @@ void SensorMesh::loop() { if (set_radio_at && millisHasNowPassed(set_radio_at)) { // apply pending (temporary) radio params set_radio_at = 0; // clear timer radio_set_params(pending_freq, pending_bw, pending_sf, pending_cr); + //You need to clear the old registers, otherwise the LoRa module won't receive any information the first time. + _radio->onSendFinished(); + _radio->startRecv(); MESH_DEBUG_PRINTLN("Temp radio params"); } if (revert_radio_at && millisHasNowPassed(revert_radio_at)) { // revert radio params to orig revert_radio_at = 0; // clear timer radio_set_params(_prefs.freq, _prefs.bw, _prefs.sf, _prefs.cr); + //You need to clear the old registers, otherwise the LoRa module won't receive any information the first time. + _radio->onSendFinished(); + _radio->startRecv(); MESH_DEBUG_PRINTLN("Radio params restored"); } diff --git a/src/Dispatcher.h b/src/Dispatcher.h index 25a41d82c..6bd4f3abb 100644 --- a/src/Dispatcher.h +++ b/src/Dispatcher.h @@ -61,6 +61,8 @@ class Radio { */ virtual void loop() { } + virtual void startRecv() { } + virtual int getNoiseFloor() const { return 0; } virtual void triggerNoiseFloorCalibrate(int threshold) { }