Skip to content

Conversation

@1technophile
Copy link
Owner

Description:

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 [email protected]
Co-authored-by: Odyno [email protected]

🤖 Generated with Claude Code

Checklist:

  • The pull request is done against the latest development branch
  • Only one feature/fix was added per PR and the code change compiles without warnings
  • I accept the DCO.

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 <[email protected]>
Co-authored-by: Odyno <[email protected]>

🤖 Generated with [Claude Code](https://claude.ai/code)
@1technophile 1technophile merged commit e01b226 into development Jan 6, 2026
161 checks passed
@1technophile 1technophile deleted the claude/issue-2264-20260106-1134 branch January 6, 2026 11:47
@claude
Copy link

claude bot commented Jan 6, 2026

PR Review: [RF] Fix CC1101 initialization on boot with saved RF config

Summary

This PR fixes issue #2264 where the CC1101 RF module wasn't properly initialized on boot when a saved RF configuration existed in NVS. The root cause was that loadFromStorage() loaded the config but never called iRFReceiver.enable() to initialize the hardware.

Code Quality ✅

Good aspects:

  • Clean solution with minimal changes (15 additions, 7 deletions)
  • Well-documented parameter with clear docstring updates in both .cpp and .h files
  • Uses a sensible default (reinitReceiver = true) that ensures backwards compatibility
  • The fix correctly addresses the root cause identified in the issue

Design choice:
The approach of adding a reinitReceiver parameter with a default of true is appropriate. This ensures:

  1. Boot-time initialization (setupCommonRF() at main/commonRF.cpp:92) gets proper hardware initialization
  2. MQTT message handling (loadFromMessage()) avoids double initialization since it already calls disable()/enable() after fromJson()

Correctness Analysis ✅

The logic is sound:

  1. Boot path (setupCommonRFloadFromStorage()):

    • reinitReceiver defaults to true
    • Receiver is disabled then enabled, triggering initCC1101()
  2. MQTT message path (loadFromMessageloadFromStorage(false)):

    • Passes false to avoid double initialization
    • loadFromMessage() already calls disable()/enable() at lines 207-208
  3. Non-ESP32 platforms: The receiver initialization now happens unconditionally (outside the #ifdef ESP32 block), which is actually an improvement - previously non-ESP32 platforms only called enable() but never disable() first, and now they consistently get the disable/enable cycle when reinitReceiver is true.

Potential Concerns ⚠️

  1. Early return paths in ESP32 block: When deserialization fails (line 153) or config is null (line 157), the function returns early before the reinitReceiver block. This means if there's a corrupted config in NVS, the receiver won't be initialized at boot.

    Suggestion: Consider whether the receiver should still be initialized in these error cases:

    if (error) {
      Log.error(F("RF Config deserialization failed: %s, buffer capacity: %u" CR), error.c_str(), jsonBuffer.capacity());
      // Still initialize receiver with defaults on error?
      if (reinitReceiver) {
        iRFReceiver.disable();
        iRFReceiver.enable();
      }
      return;
    }
  2. Order of operations: Calling disable() before enable() is good practice for ensuring clean state. The current implementation correctly does this.

Performance ✅

No performance concerns - the disable/enable cycle only happens once at boot or on explicit config reload.

Security ✅

No security implications in this change.

Test Coverage 📝

The PR description mentions the fix was validated against the specific scenario in #2264 (boot with saved config). Manual testing appears to have confirmed the CC1101 now receives signals after boot without requiring WebUI toggle.

Recommendation: If the project has unit tests for RFConfiguration, consider adding test cases for:

  • loadFromStorage(true) - verify receiver is re-initialized
  • loadFromStorage(false) - verify receiver is not touched
  • Error paths (deserialization failure, null config)

Overall Assessment ✅

Approve - This is a well-crafted fix that addresses the reported issue with minimal, targeted changes. The code is clean, well-documented, and follows the project's existing patterns.

The one minor suggestion above (handling error paths) is optional and can be addressed in a follow-up if desired.


🤖 Review generated with Claude Code

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

Successfully merging this pull request may close these issues.

Changes between 1.8.1 and development breaks CC1101 (rcswitch / smartrc-cc1101-driver) default behaviour

2 participants