Skip to content

Conversation

Arcitec
Copy link
Contributor

@Arcitec Arcitec commented Aug 3, 2025

Update: Replaced with a different PR instead: #4844


Simplifies device setup by being able to configure the desired Sync button behavior at compile-time.

Usage:

  -D SYNC_SEND_DIRECT=1
  -D SYNC_SEND_BUTTON=1

Summary by CodeRabbit

  • Chores
    • Improved configurability of notification synchronization settings, allowing default behaviors to be customized during compilation. No changes to user-facing features or application logic.

Simplifies device setup by being able to configure the desired sync behavior at compile-time.
Copy link
Contributor

coderabbitai bot commented Aug 3, 2025

Walkthrough

The update modifies the initialization of global boolean variables controlling notification synchronization in wled00/wled.h. Hardcoded true/false initializations are replaced with preprocessor macros, allowing their default values to be set at compile time. No logic, control flow, or public API signatures are changed.

Changes

Cohort / File(s) Change Summary
Macro-based Notification Sync Initialization
wled00/wled.h
Replaces direct boolean initializations for notification sync flags with conditionally-defined preprocessor macros, enabling compile-time configurability of default values. No logic or API changes.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~7 minutes

Note

⚡️ Unit Test Generation is now available in beta!

Learn more here, or try it out under "Finishing Touches" below.


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 93e011d and 11296e8.

📒 Files selected for processing (1)
  • wled00/wled.h (1 hunks)
🧰 Additional context used
🧠 Learnings (8)
📓 Common learnings
Learnt from: blazoncek
PR: wled/WLED#4482
File: wled00/udp.cpp:147-149
Timestamp: 2025-02-19T12:43:34.199Z
Learning: ESP8266 and ESP32 platforms have different maximum segment name lengths in WLED, which can cause truncation when syncing segment names between devices. This platform difference affects the user experience when using the segment name sync feature.
Learnt from: KrX3D
PR: wled/WLED#4664
File: wled00/syslog.cpp:50-51
Timestamp: 2025-04-26T12:51:04.993Z
Learning: In the WLED codebase, syslog configuration variables (syslogHost, syslogPort, syslogProtocol, syslogFacility, syslogSeverity) are defined as global variables in wled.h and are accessed directly in the SyslogPrinter implementation, rather than being class members.
Learnt from: blazoncek
PR: wled/WLED#4658
File: wled00/const.h:140-141
Timestamp: 2025-04-26T19:19:07.600Z
Learning: In WLED, the WLED_MAX_PANELS macro is intentionally defined as a fixed constant value (18) with no redefinition mechanism, making it "unoverridable" - there's no need for a static assertion to check its maximum value.
Learnt from: blazoncek
PR: wled/WLED#4700
File: wled00/wled_server.cpp:409-414
Timestamp: 2025-05-26T16:09:34.325Z
Learning: In wled00/wled_server.cpp, the OTA update access control logic intentionally allows OTA updates from different subnets when otaSameSubnet is true AND a PIN is set. This was a conscious design decision by blazoncek to provide flexibility for remote OTA updates with PIN protection, though they acknowledged it may not be the optimal security model.
Learnt from: KrX3D
PR: wled/WLED#4585
File: usermods/seven_segment_display_reloaded_v2/seven_segment_display_reloaded_v2.cpp:430-435
Timestamp: 2025-04-28T20:51:29.773Z
Learning: In WLED, `bri` is a global variable used for brightness control.
Learnt from: willmmiles
PR: wled/WLED#4623
File: usermods/word-clock-matrix/word-clock-matrix.cpp:332-332
Timestamp: 2025-03-29T01:22:54.617Z
Learning: In the WLED project, hardcoded usermod IDs (like 500 in the WordClockMatrix's getId() method) are intentionally used as part of a strategy to avoid modifying core code. There are plans to remove numeric usermod IDs entirely in the future.
Learnt from: DedeHai
PR: wled/WLED#4793
File: wled00/file.cpp:481-513
Timestamp: 2025-07-31T18:21:49.868Z
Learning: In WLED, essential configuration files that require backup have short, controlled names (like "/cfg.json", "/presets.json") that are well within a 32-character buffer limit. The file naming is controlled by developers, making buffer overflow in backup filename construction highly unlikely.
Learnt from: blazoncek
PR: wled/WLED#4658
File: wled00/led.cpp:90-91
Timestamp: 2025-04-24T09:31:06.879Z
Learning: In the WLED codebase, the `getSegment()` function guards against out-of-bounds segment IDs, and `getFirstSelectedSegId()` falls back to `getMainSegmentId()` if no segments are selected, ensuring no crashes when used through the `setValuesFromFirstSelectedSeg()` macro.
Learnt from: blazoncek
PR: wled/WLED#4658
File: wled00/led.cpp:90-91
Timestamp: 2025-04-24T09:31:06.879Z
Learning: In the WLED codebase, the `getSegment()` function guards against out-of-bounds segment IDs, and `getFirstSelectedSegId()` falls back to `getMainSegmentId()` if no segments are selected, ensuring no crashes when used through the `setValuesFromFirstSelectedSeg()` macro.
Learnt from: KrX3D
PR: wled/WLED#4585
File: usermods/seven_segment_display_reloaded_v2/seven_segment_display_reloaded_v2.h:121-136
Timestamp: 2025-04-27T09:37:28.415Z
Learning: Using PROGMEM for the seven-segment font array (umSSDRNumbers) in the WLED SSDR usermod causes compilation problems, so it should be left as a regular array.
📚 Learning: in the wled codebase, syslog configuration variables (sysloghost, syslogport, syslogprotocol, syslog...
Learnt from: KrX3D
PR: wled/WLED#4664
File: wled00/syslog.cpp:50-51
Timestamp: 2025-04-26T12:51:04.993Z
Learning: In the WLED codebase, syslog configuration variables (syslogHost, syslogPort, syslogProtocol, syslogFacility, syslogSeverity) are defined as global variables in wled.h and are accessed directly in the SyslogPrinter implementation, rather than being class members.

Applied to files:

  • wled00/wled.h
📚 Learning: in wled, the wled_max_panels macro is intentionally defined as a fixed constant value (18) with no r...
Learnt from: blazoncek
PR: wled/WLED#4658
File: wled00/const.h:140-141
Timestamp: 2025-04-26T19:19:07.600Z
Learning: In WLED, the WLED_MAX_PANELS macro is intentionally defined as a fixed constant value (18) with no redefinition mechanism, making it "unoverridable" - there's no need for a static assertion to check its maximum value.

Applied to files:

  • wled00/wled.h
📚 Learning: in wled, `bri` is a global variable used for brightness control....
Learnt from: KrX3D
PR: wled/WLED#4585
File: usermods/seven_segment_display_reloaded_v2/seven_segment_display_reloaded_v2.cpp:430-435
Timestamp: 2025-04-28T20:51:29.773Z
Learning: In WLED, `bri` is a global variable used for brightness control.

Applied to files:

  • wled00/wled.h
📚 Learning: esp8266 and esp32 platforms have different maximum segment name lengths in wled, which can cause tru...
Learnt from: blazoncek
PR: wled/WLED#4482
File: wled00/udp.cpp:147-149
Timestamp: 2025-02-19T12:43:34.199Z
Learning: ESP8266 and ESP32 platforms have different maximum segment name lengths in WLED, which can cause truncation when syncing segment names between devices. This platform difference affects the user experience when using the segment name sync feature.

Applied to files:

  • wled00/wled.h
📚 Learning: in wled, essential configuration files that require backup have short, controlled names (like "/cfg....
Learnt from: DedeHai
PR: wled/WLED#4793
File: wled00/file.cpp:481-513
Timestamp: 2025-07-31T18:21:49.868Z
Learning: In WLED, essential configuration files that require backup have short, controlled names (like "/cfg.json", "/presets.json") that are well within a 32-character buffer limit. The file naming is controlled by developers, making buffer overflow in backup filename construction highly unlikely.

Applied to files:

  • wled00/wled.h
📚 Learning: in wled's fx.h, mode_count represents the highest fx_mode_ id + 1, not the total count of fx_mode_ d...
Learnt from: netmindz
PR: wled/WLED#4728
File: wled00/FX.h:378-378
Timestamp: 2025-06-15T09:59:52.720Z
Learning: In WLED's FX.h, MODE_COUNT represents the highest FX_MODE_ ID + 1, not the total count of FX_MODE_ definitions. This is because some effects may have been removed but their IDs are not reused, creating gaps in the numbering sequence. MODE_COUNT is used for array bounds and range checking.

Applied to files:

  • wled00/wled.h
📚 Learning: in wled, maximum segment name length varies by platform: - esp8266: 32 characters (wled_max_segname_...
Learnt from: blazoncek
PR: wled/WLED#4482
File: wled00/udp.cpp:147-149
Timestamp: 2025-02-19T12:43:34.200Z
Learning: In WLED, maximum segment name length varies by platform:
- ESP8266: 32 characters (WLED_MAX_SEGNAME_LEN = 32)
- ESP32: 64 characters (WLED_MAX_SEGNAME_LEN = 64)
This platform difference can cause truncation when syncing longer names from ESP32 to ESP8266. Additionally, the WLED UI has limitations regarding modified maximum segment name lengths.

Applied to files:

  • wled00/wled.h
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (19)
  • GitHub Check: wled_build / Build Environments (usermods)
  • GitHub Check: wled_build / Build Environments (nodemcuv2_compat)
  • GitHub Check: wled_build / Build Environments (esp32_wrover)
  • GitHub Check: wled_build / Build Environments (esp32s3dev_16MB_opi)
  • GitHub Check: wled_build / Build Environments (esp32_eth)
  • GitHub Check: wled_build / Build Environments (esp32s3_4M_qspi)
  • GitHub Check: wled_build / Build Environments (esp32s3dev_8MB_opi)
  • GitHub Check: wled_build / Build Environments (esp32dev)
  • GitHub Check: wled_build / Build Environments (lolin_s2_mini)
  • GitHub Check: wled_build / Build Environments (esp32c3dev)
  • GitHub Check: wled_build / Build Environments (esp01_1m_full_160)
  • GitHub Check: wled_build / Build Environments (esp32dev_V4)
  • GitHub Check: wled_build / Build Environments (esp01_1m_full_compat)
  • GitHub Check: wled_build / Build Environments (esp8266_2m_160)
  • GitHub Check: wled_build / Build Environments (esp8266_2m_compat)
  • GitHub Check: wled_build / Build Environments (esp8266_2m)
  • GitHub Check: wled_build / Build Environments (esp01_1m_full)
  • GitHub Check: wled_build / Build Environments (nodemcuv2_160)
  • GitHub Check: wled_build / Build Environments (nodemcuv2)
🔇 Additional comments (2)
wled00/wled.h (2)

730-763: LGTM! Well-structured compile-time configuration approach.

The conditional macro definitions follow best practices:

  • Consistent naming convention with clear SYNC_RECV_* and SYNC_SEND_* prefixes
  • Proper use of #ifndef guards to allow external override
  • Sensible default values that preserve existing behavior
  • Clean separation between receive and send configurations

This approach enables compile-time customization while maintaining backward compatibility.


764-775: LGTM! Proper macro-based initialization.

The global variable declarations correctly utilize the compile-time configurable macros:

  • Consistent use of WLED_GLOBAL and _INIT() patterns
  • Preserved variable names and semantics maintain API compatibility
  • Clear mapping between each variable and its corresponding macro
  • Descriptive comments explain the purpose of each sync option

The implementation successfully achieves the PR objective of making sync modes configurable at compile-time.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@netmindz
Copy link
Member

netmindz commented Aug 9, 2025

We should not be adding compile flags for configuration, if you want your device to have a certain config after you flash it, then flash a filesystem with suitable config file, we need to reduce the number of build flags, not adding more

@netmindz netmindz closed this Aug 9, 2025
@Arcitec
Copy link
Contributor Author

Arcitec commented Aug 10, 2025

@netmindz The issue with WLED's code is that the "Sync" button in WLED's main UI does absolutely nothing whatsoever since WLED 0.15 and newer. Activate "Sync" = Nothing happens. No code runs. Nothing gets activated.

My preferred fix would literally be:

  • Disable Philips Hue's sync sending flag (why is that on by default in the code? typo, I bet, or someone decided to sneak a personal setting into the main WLED code).
  • Enable the "send direct" and "send button" flags by default, so that all changes on the device are detected.

That's a two-line change and it makes the Sync button work as users expect it: Clicking the Sync button will make their other WLED devices on the network sync with the master's settings. It's also a harmless change since nothing is sent/processed unless the user clicks the main UI's "Sync" button.

What do you think about solving it that way?

Old:

WLED/wled00/wled.h

Lines 737 to 740 in 3f90366

WLED_GLOBAL bool notifyDirect _INIT(false); // send notification if change via UI or HTTP API
WLED_GLOBAL bool notifyButton _INIT(false); // send if updated by button or infrared remote
WLED_GLOBAL bool notifyAlexa _INIT(false); // send notification if updated via Alexa
WLED_GLOBAL bool notifyHue _INIT(true); // send notification if Hue light changes

New:

WLED_GLOBAL bool notifyDirect _INIT(true);                       // send notification if change via UI or HTTP API
WLED_GLOBAL bool notifyButton _INIT(true);                       // send if updated by button or infrared remote
WLED_GLOBAL bool notifyAlexa  _INIT(false);                       // send notification if updated via Alexa
WLED_GLOBAL bool notifyHue    _INIT(false);                        // send notification if Hue light changes

@Arcitec Arcitec deleted the configurable-sync-settings branch August 10, 2025 23:18
@Arcitec
Copy link
Contributor Author

Arcitec commented Aug 10, 2025

Flashing a filesystem has several issues:

  • It gets wiped during factory resets. This is the biggest issue.
  • Includes all settings, meaning the "first setup" wizard to choose WiFi network etc won't run.

So I'd prefer to fix the Sync button issue in WLED's code instead, either via compile-flags if there's no agreement on what the defaults should be (hence this PR), or alternatively by fixing WLED to have sane defaults for the Sync button. :)

Defaults should be something that matches the vast majority of users and how they are likely to use WLED. With syncing, and pressing the "Sync" button, the majority of users expect that it begins syncing with other WLED devices on the network. That can be fixed by improving the defaults.

And obviously, while I've fixed this issue personally, I want it to work out of the box for everyone who visits wled.me and downloads a binary, because that puts the project in a better light. Having a non-functional "Sync" button by default in the main UI doesn't really make sense.

I'd be happy to make the PR to fix the defaults to make the Sync UI button work. ❤️

@netmindz
Copy link
Member

I agree that users have found the new behaviour confusing, there have been several reports of if being "broken" but I'm still confused as to why it was changed and what the expected new behaviour is (out of the box)

@Arcitec
Copy link
Contributor Author

Arcitec commented Aug 13, 2025

@netmindz Yeah. While I was investigating this and talking to people, @blazoncek said that the original pre-0.15 behavior was that clicking on "Sync" in the UI automatically enabled the relevant sync flags internally.

The latest WLED code uses a two-tier system:

Tier 1:

  • The UI "Sync" button. Clicking this button toggles the master "send notifications" flags here:

WLED/wled00/wled.h

Lines 662 to 663 in 3f90366

WLED_GLOBAL bool sendNotifications _INIT(false); // master notification switch
WLED_GLOBAL bool sendNotificationsRT _INIT(false); // master notification switch (runtime)

  • If that flag is false (it's always off by default at startup unless the user changes a settin for that), then notifications (syncing) is never sent. It's the master on/off switch. So all the tier 2 settings are slaves under the tier 1 master switch.

Tier 2:

  • The settings then chooses what actually gets sent when the master switch is on. Those defaults no longer make any sense (all syncing is off except to send Philips Hue signals, which is a bit "wtf"):

WLED/wled00/wled.h

Lines 737 to 740 in 3f90366

WLED_GLOBAL bool notifyDirect _INIT(false); // send notification if change via UI or HTTP API
WLED_GLOBAL bool notifyButton _INIT(false); // send if updated by button or infrared remote
WLED_GLOBAL bool notifyAlexa _INIT(false); // send notification if updated via Alexa
WLED_GLOBAL bool notifyHue _INIT(true); // send notification if Hue light changes

My proposal is to change those flag values to something that makes sense by default:

  • Sync direct + button-induced changes to WLED.
  • Do not send notifications to Amazon Alexa and Philips Hue. People who have such extra devices can enable those manually.
WLED_GLOBAL bool notifyDirect _INIT(true);                       // send notification if change via UI or HTTP API
WLED_GLOBAL bool notifyButton _INIT(true);                       // send if updated by button or infrared remote
WLED_GLOBAL bool notifyAlexa  _INIT(false);                       // send notification if updated via Alexa
WLED_GLOBAL bool notifyHue    _INIT(false);                        // send notification if Hue light changes

With that change, the WLED UI's "Sync" button would make sense to users again. When people's master "Sync" device changes its settings, other WLED devices in the network would then follow it as users expect.

I think it should be improved like this, so that WLED is pre-configured to sync with other WLED devices whenever a user clicks on "Sync".

I have not created a pull request to change the defaults because I wasn't sure if you want to do that, but I honestly think the change above should be made so that WLED is pre-configured to work out of the box. The current situation where people ask "is it broken?" isn't ideal. :)

I can make a quick PR if it helps, or anyone can commit the change directly. I think the improvement should also happen in 0.15.2.

@blazoncek
Copy link
Collaborator

I'm still confused as to why it was changed and what the expected new behaviour is

Previous behaviour was tied to "notify on direct change". So if you wanted to "notify" other "stuff" you were always notifying everything (aka sync).

I agree to set "notify on direct change" to true by default as it will no longer also trigger sync behaviour.

@Arcitec
Copy link
Contributor Author

Arcitec commented Aug 17, 2025

@blazoncek Ahh that makes sense. So in the past, setting them to "true" would have made the devices always sync by default. When things were refactored to have the master on/off switch and granular control, this flag's default was simply forgotten.

I was sick for a few days. I am preparing the pull requests to fix this for 0.16 and 0.15.2 now, since it's a "major" user-facing bug in expected behavior, and it would make user's lives easier if Sync just works. :)

Edit: Pull requests are ready:

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.

3 participants