Skip to content

Fix: CC1101 radio stays permanently disabled after an init hang (radioInit stuck false) - #679

Open
bledrunner wants to merge 3 commits into
rstrouse:mainfrom
bledrunner:fix/radio-init-stuck-recovery
Open

Fix: CC1101 radio stays permanently disabled after an init hang (radioInit stuck false)#679
bledrunner wants to merge 3 commits into
rstrouse:mainfrom
bledrunner:fix/radio-init-stuck-recovery

Conversation

@bledrunner

Copy link
Copy Markdown

Problem

After the ESP reboots while the CC1101 radio is being initialized (e.g. a WDT reset mid-init), the web UI and the Home Assistant websocket keep working, but shades stop responding to any command from the UI or HA. Rebooting does not help — every boot behaves the same. Only the original Somfy remote still works, and only a /saveRadio POST brings the radio back.

Matches user reports such as #535 ("not responding after some times").

Root cause — transceiver_config_t::apply() in Somfy.cpp

radioInit = pref.getBool("radioInit", true);
pref.putBool("radioInit", false);   // marked in-progress
this->radioInit = false;
pref.end();
if(!radioInit) return;              // <-- returns WITHOUT resetting the flag
... CC1101 init ...
pref.putBool("radioInit", true);    // only reached on a completed init

The flag is written false before init and back to true after, so that a hang during init is detected on the next boot. But the detection path (if(!radioInit) return;) never writes the flag back to true. Once it is false, every subsequent boot reads false and skips radio init forever. The radio stays dead until a manual /saveRadio.

Fix

  • Retry init for up to 3 consecutive incomplete boots (tracked in a new initCrashes NVS counter) and only then give up — booting cleanly with the radio off to avoid a hard boot loop with genuinely dead hardware. The counter resets on a successful init or a /saveRadio POST.
  • SomfyRemote::getNextRollingCode() no longer advances the stored rolling code while radioInit is false, so commands issued during the dead window don't drift the code ahead of the motor and desync the remote once the radio recovers.

Notes

  • Reproduced/diagnosed against a live device running v2.4.7 (= this commit).
  • Not compile-tested (no ESP32 toolchain available at the time of writing); the change is localized to the two functions in the diff.

bledrunner and others added 3 commits July 24, 2026 15:43
When the CC1101 init hangs and the watchdog reboots the ESP, the NVS
"radioInit" flag is left false. transceiver_config_t::apply() then did
"if(!radioInit) return;" on every subsequent boot without ever resetting
the flag, so the radio was never re-initialized again. The web UI and the
HA websocket keep working, but no RF is transmitted and shades stop
responding - a reboot does not help because each boot reads false again.
Only a /saveRadio POST recovered it.

This retries init for up to 3 consecutive incomplete boots and only then
gives up (booting cleanly with the radio off to avoid a hard boot loop).
The counter resets on a successful init or a /saveRadio POST.

Also stop advancing the rolling code while the radio is not initialized,
otherwise commands issued during the dead window drift the stored code
ahead of the motor and desync the remote once the radio recovers.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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.

1 participant