Skip to content

Commit e01b226

Browse files
[RF] Fix CC1101 initialization on boot with saved RF config (#2269)
When a saved RF configuration exists in NVS, loadFromStorage() was loading the config but not calling iRFReceiver.enable(), which meant initCC1101() was never invoked during boot. This caused the CC1101 to not receive signals until the user manually toggled the RF receiver via the WebUI. This fix adds a reinitReceiver parameter to loadFromStorage() that controls whether to disable/enable the receiver after loading config. By default it's true (for boot-time initialization), but loadFromMessage() passes false to avoid double initialization when loading config from MQTT messages. Fixes #2264 Co-authored-by: Florian <1technophile@users.noreply.github.com> Co-authored-by: Odyno <odyno@users.noreply.github.com> 🤖 Generated with [Claude Code](https://claude.ai/code) Co-authored-by: claude[bot] <41898282+claude[bot]@users.noreply.github.com>
1 parent 0c2884c commit e01b226

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

main/rf/RFConfiguration.cpp

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -134,11 +134,14 @@ void RFConfiguration::saveOnStorage() {
134134
* is not found, a notice is logged, and the RF receiver is enabled with
135135
* default settings.
136136
*
137+
* @param reinitReceiver If true (default), disables and re-enables the receiver.
138+
* If false, only loads the configuration without reinitialization.
139+
*
137140
* @note This function has specific behavior for ESP32 platforms. On ESP32,
138141
* it uses the Preferences library to access stored configuration data.
139142
* For other platforms, it directly enables the active receiver.
140143
*/
141-
void RFConfiguration::loadFromStorage() {
144+
void RFConfiguration::loadFromStorage(bool reinitReceiver) {
142145
#ifdef ESP32
143146
StaticJsonDocument<JSON_MSG_BUFFER> jsonBuffer;
144147
preferences.begin(Gateway_Short_Name, true);
@@ -159,11 +162,13 @@ void RFConfiguration::loadFromStorage() {
159162
} else {
160163
preferences.end();
161164
Log.notice(F("RF Config not found using default" CR));
162-
iRFReceiver.enable();
163165
}
164-
#else
165-
iRFReceiver.enable();
166166
#endif
167+
// Disable and re-enable the receiver to ensure proper initialization
168+
if (reinitReceiver) {
169+
iRFReceiver.disable();
170+
iRFReceiver.enable();
171+
}
167172
}
168173

169174
/**
@@ -193,8 +198,8 @@ void RFConfiguration::loadFromMessage(JsonObject& RFdata) {
193198
// Restore the default (initial) configuration
194199
reInit();
195200
} else if (RFdata.containsKey("load") && RFdata["load"].as<bool>()) {
196-
// Load the saved configuration, if not initialised
197-
loadFromStorage();
201+
// Load the saved configuration from storage (without receiver reinitialization)
202+
loadFromStorage(false);
198203
}
199204

200205
fromJson(RFdata);

main/rf/RFConfiguration.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,14 @@ class RFConfiguration {
4949
/**
5050
* Loads the RF configuration from persistent storage and applies it.
5151
*
52+
* @param reinitReceiver If true (default), disables and re-enables the receiver.
53+
* If false, only loads the configuration without reinitialization.
54+
*
5255
* @note This function has specific behavior for ESP32 platforms. On ESP32,
5356
* it uses the Preferences library to access stored configuration data.
5457
* For other platforms, it directly enables the active receiver.
5558
*/
56-
void loadFromStorage();
59+
void loadFromStorage(bool reinitReceiver = true);
5760

5861
/**
5962
* Loads the RF configuration from a JSON object and applies it.

0 commit comments

Comments
 (0)