Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

also sync segment name through udp #4482

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

Liliputech
Copy link

@Liliputech Liliputech commented Jan 12, 2025

This commit solves this issue : #4468

Summary by CodeRabbit

  • New Features
    • Enhanced configuration options now support segment names.
    • The synchronization settings interface has an additional checkbox to enable or disable segment name reception.
    • UDP notifications are updated to include segment name details, improving segment management.
    • The system’s settings now offer robust handling of segment names for a more flexible and informative configuration experience.
    • New parameter added for segment name handling in synchronization settings.

@netmindz
Copy link
Member

Should this be an optional sync attribute, like the existing ones are?

@Liliputech
Copy link
Author

as of now its not optional but I can make it optional if needed.
I was not sure in which category to add this (effects, segment bounds, options?), or if I should create a new category.
The name sometime is used by the effect for the effect configuration (see GIF image branch).

@blazoncek
Copy link
Collaborator

This is a breaking change. Old devices may crash or behave incorrectly due to message containing unexpected content.
Please rework so older devices will behave correctly.

@Liliputech
Copy link
Author

This is to be tested but since the "segment packet size" is sent in the UDP packet and read by the receiver it may be backward compatible.

@netmindz
Copy link
Member

I'd suggest a new checkbox called Segment Name

@Liliputech
Copy link
Author

Ok, I'll work on this and will push some new commits to reflect this change

@Liliputech
Copy link
Author

one new commit is available with option to enable or disable segment name sync (disabled by default like Segment Options).

@netmindz
Copy link
Member

What testing have you done so far with regards to @blazoncek 's comments about compatibility testing between systems using your new packet format and without?

@Liliputech
Copy link
Author

Unfortunately didn't had the opportunity to run such tests yet. I will do ASAP
My idea of how to test this : flash one board with my branch and another board with main branch without packet format change.
then enable sync on both boards and see if everything is fine (color/segment options change).
Also see change the segment name on the board with my branch, trigger an update and see if the other board don't crash.

@netmindz
Copy link
Member

Unfortunately didn't had the opportunity to run such tests yet. I will do ASAP My idea of how to test this : flash one board with my branch and another board with main branch without packet format change. then enable sync on both boards and see if everything is fine (color/segment options change). Also see change the segment name on the board with my branch, trigger an update and see if the other board don't crash.

When you mean sync on both, do you mean making one the sender and one the receiver and then doing the same the other way round? We need to ensure we cover both "forward" and "backwards" compatibility

@Liliputech
Copy link
Author

Ok, as far as I can tell, this modification is both forward and backward compatible.
I've tried with 2 distinct wled instances, one flashed with main branch, the other one with my name sync instance.
Tried to sync both way and surprisingly everything seems to work fine!
Only have a small issue since the UI doesn't reflect the "Segment name" option status (have to fix this).
Will provide a small patch to fix this.
Also, since I made some changes to the UI should I commit the changes in the generated .h files? I think those are gitignore and generated upon compilation anyway.

this option is disabled by default.
When enabled, the segment name is applied when received from another
WLED instance.
@Liliputech
Copy link
Author

just push a new commit to fix the issue previously mentioned + rebased on latest main

@netmindz
Copy link
Member

Do not commit the html .h files as those are built on demand

@netmindz
Copy link
Member

Please do not use force push

@Liliputech
Copy link
Author

arf, too late. but commits didn't changed, only rebased on main

@netmindz
Copy link
Member

If you force push it means we have to start the code review process again. Are you able to take a look again @blazoncek ?

Copy link
Collaborator

@blazoncek blazoncek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are some things that need to be addressed before this is ready for merge.

I am not very fond of segment name syncing but if some users need that, so be it.
I should add that (even though not yet working as intended) ESP-NOW packet needs to be checked if segment name will overflow it.

@@ -647,18 +647,20 @@ typedef class Receive {
bool Color : 1;
bool Effects : 1;
bool SegmentOptions : 1;
bool SegmentName : 1;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's why there is reserved. Use that if possible.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm sorry but i don't understand how I'm supposed to use reserved... to me it looks like it is a variable to hold the sum of all boolean define above, which is then not to be changed by hand?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should have not "resolved" this as you did not address my comment.
reservedis a placeholder for future enhancement as this PR so replace it with SegmentNameoption.

@netmindz
Copy link
Member

netmindz commented Feb 7, 2025

Looks like the wrong branch was merged into this branch

Merge remote-tracking branch 'blazoncek/parallel-I2S' into udp_name_sync

@blazoncek
Copy link
Collaborator

@netmindz it will be ok once #4484 is merged.

Copy link

coderabbitai bot commented Feb 19, 2025

Walkthrough

The changes add support for handling segment names throughout the system. A new configuration parameter is introduced in the JSON deserialization and setting handler functions. The web interface now includes an additional checkbox to enable or disable the segment name functionality, and the corresponding JavaScript is updated. The UDP notification mechanism has been modified to accommodate the segment name by updating packet size definitions and integrating the name into UDP messages. Additionally, the Receive class has been updated to accept the new segment name parameter along with an associated macro.

Changes

File(s) Change Summary
wled00/cfg.cpp, wled00/set.cpp, wled00/wled.h Added support for a new segment name parameter: deserializeConfig in cfg.cpp now extracts receiveSegmentName; set.cpp checks for the SN request argument; wled.h updates the Receive constructor and adds the receiveSegmentName macro.
wled00/data/settings_sync.htm, wled00/xml.cpp Updated the web settings by adding a new checkbox input (SN) to the HTML form in settings_sync.htm and including the same option in the JavaScript settings form generated in xml.cpp.
wled00/udp.cpp Modified UDP packet handling to incorporate segment names: updated constants (UDP_SEG_SIZE, WLEDPACKETSIZE) to calculate sizes using the segment name length, added code to copy segment names into UDP notifications, and adjusted logic for segment handling in packets.

📜 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 84857de and 26081bf.

📒 Files selected for processing (1)
  • wled00/udp.cpp (6 hunks)
🧰 Additional context used
🧠 Learnings (1)
wled00/udp.cpp (4)
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.
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: blazoncek
PR: wled/WLED#4482
File: wled00/udp.cpp:343-347
Timestamp: 2025-02-19T12:41:22.676Z
Learning: The setName() method in WLED's Segment class (FX_fcn.cpp) handles all necessary validation internally, including:
1. Null pointer checks
2. Length validation against WLED_MAX_SEGNAME_LEN
3. Memory allocation/reallocation
No additional validation or name clearing is needed before calling setName().
Learnt from: blazoncek
PR: wled/WLED#4482
File: wled00/udp.cpp:343-347
Timestamp: 2025-02-19T12:41:22.676Z
Learning: The setName() method in WLED handles segment name validation internally. No additional length checks or name clearing is needed before calling setName().
🔇 Additional comments (2)
wled00/udp.cpp (2)

165-167: LGTM! Appropriate handling of segment name in ESP-NOW packets.

The code correctly handles the segment name size limitation by allowing only one segment in the first packet.


7-9:

❓ Verification inconclusive

Verify ESP-NOW packet size limitations.

The updated UDP_SEG_SIZE includes WLED_MAX_SEGNAME_LEN, which could exceed ESP-NOW's 250-byte packet size limit, especially on ESP32 where WLED_MAX_SEGNAME_LEN is 64 bytes.


🏁 Script executed:

#!/bin/bash
# Calculate total packet size for ESP-NOW
echo "Checking ESP-NOW packet size..."
rg "WLED_MAX_SEGNAME_LEN" -A 2

Length of output: 1785


Action Required: Verify ESP-NOW Packet Size Calculations

The updated definition in wled00/udp.cpp now computes the segment size as UDP_SEG_SIZE = (36 + WLED_MAX_SEGNAME_LEN). Since WLED_MAX_SEGNAME_LEN is defined as 64 for ESP32 (and 32 for ESP8266 according to wled00/const.h), on ESP32 each segment contributes 100 bytes. When multiplied by MAX_NUM_SEGMENTS (and after adding the SEG_OFFSET), the overall packet size can potentially breach ESP-NOW’s typical 250-byte packet size limit.

  • Location: wled00/udp.cpp (lines 7-9)
  • Concern: On ESP32 configurations, ensuring the computed WLEDPACKETSIZE stays within ESP-NOW’s allowed limits.
  • Recommendation: Double-check the maximum number of segments (MAX_NUM_SEGMENTS) and overall packet size to confirm that the adjustments for the segment name length do not cause packet overflow. If necessary, implement additional bounds-checking logic to handle cases where the packet size may exceed ESP-NOW constraints.
✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ 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.
    • Generate unit testing code for this file.
    • 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 generate unit testing code for this file.
    • @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 generate unit testing code.
    • @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.

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. (Beta)
  • @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.

@Liliputech
Copy link
Author

hi, just solved conflict after merge of #4484 :) hope this one can be merged!

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Nitpick comments (3)
wled00/data/settings_sync.htm (1)

104-104: Consider improving UI layout for better readability.

The current layout could be improved by grouping related options together.

Apply this diff to improve the UI layout:

-<input type="checkbox" name="SO"> Segment options, <input type="checkbox" name="SN"> name, <input type="checkbox" name="SG"> bounds
+<input type="checkbox" name="SO"> Segment options (<input type="checkbox" name="SN"> name, <input type="checkbox" name="SG"> bounds)
wled00/wled.h (2)

653-654: Consider using reserved field for future expansion.

The reserved field could be used for future features instead of adding new boolean fields.

Consider using bit fields from the reserved field for future features to maintain backward compatibility.


661-669: Improve parameter ordering in constructor.

The parameter order could be more logical by grouping related parameters together.

Apply this diff to improve parameter ordering:

-    Receive(bool b, bool c, bool e, bool sO, bool sN, bool sB, bool p)
+    Receive(bool b, bool c, bool e, bool p, bool sO, bool sN, bool sB)
     : Brightness(b)
     , Color(c)
     , Effects(e)
+    , Palette(p)
     , SegmentOptions(sO)
     , SegmentName(sN)
     , SegmentBounds(sB)
-    , Palette(p)
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between a2de3d3 and 84857de.

📒 Files selected for processing (6)
  • wled00/cfg.cpp (2 hunks)
  • wled00/data/settings_sync.htm (2 hunks)
  • wled00/set.cpp (1 hunks)
  • wled00/udp.cpp (6 hunks)
  • wled00/wled.h (3 hunks)
  • wled00/xml.cpp (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (18)
  • GitHub Check: wled_build / Build Enviornments (esp32_wrover)
  • GitHub Check: wled_build / Build Enviornments (esp32s3_4M_qspi)
  • GitHub Check: wled_build / Build Enviornments (esp32s3dev_8MB_opi)
  • GitHub Check: wled_build / Build Enviornments (esp32s3dev_16MB_opi)
  • GitHub Check: wled_build / Build Enviornments (esp32c3dev)
  • GitHub Check: wled_build / Build Enviornments (lolin_s2_mini)
  • GitHub Check: wled_build / Build Enviornments (esp32_eth)
  • GitHub Check: wled_build / Build Enviornments (esp32dev_V4)
  • GitHub Check: wled_build / Build Enviornments (esp32dev)
  • GitHub Check: wled_build / Build Enviornments (esp01_1m_full_compat)
  • GitHub Check: wled_build / Build Enviornments (esp8266_2m_compat)
  • GitHub Check: wled_build / Build Enviornments (nodemcuv2_compat)
  • GitHub Check: wled_build / Build Enviornments (esp01_1m_full_160)
  • GitHub Check: wled_build / Build Enviornments (esp8266_2m_160)
  • GitHub Check: wled_build / Build Enviornments (nodemcuv2_160)
  • GitHub Check: wled_build / Build Enviornments (esp01_1m_full)
  • GitHub Check: wled_build / Build Enviornments (esp8266_2m)
  • GitHub Check: wled_build / Build Enviornments (nodemcuv2)
🔇 Additional comments (4)
wled00/xml.cpp (1)

420-420: LGTM!

The JavaScript setting for the segment name sync checkbox is correctly implemented.

wled00/udp.cpp (1)

7-9:

❓ Verification inconclusive

Verify ESP-NOW packet size limit.

The increased UDP segment size could exceed ESP-NOW's 250-byte packet limit. This might cause issues with ESP-NOW communication.

Run this script to check the total packet size:


🏁 Script executed:

#!/bin/bash
# Description: Calculate total packet size and verify against ESP-NOW limit
echo "UDP segment size = 36 + $(rg -N "WLED_MAX_SEGNAME_LEN" | head -n1)"
echo "Total packet size = 41 + (number_of_segments * UDP_SEG_SIZE)"

Length of output: 415


Review: Validate computed ESP-NOW packet size remains below 250 bytes.

The current computation of the UDP segment size—UDP_SEG_SIZE = 36 + WLED_MAX_SEGNAME_LEN—pulls the definition of WLED_MAX_SEGNAME_LEN from code in wled00/FX_fcn.cpp rather than providing a clear numeric constant. As a result, the total packet size defined by

WLEDPACKETSIZE = SEG_OFFSET + (MAX_NUM_SEGMENTS * UDP_SEG_SIZE)

remains ambiguous relative to ESP-NOW’s 250-byte limit. The script output confirms that we’re capturing the reference line instead of an evaluated numeric value.

Please manually verify that:

  • The actual numeric value of WLED_MAX_SEGNAME_LEN is correctly constrained.
  • The computed UDP_SEG_SIZE and resultant WLEDPACKETSIZE do not exceed ESP-NOW’s limit.

If necessary, adjust these constants to ensure that the UDP packet size stays safely within the 250-byte cap.

wled00/cfg.cpp (1)

446-446: LGTM! The new configuration parameter is well-integrated.

The addition of receiveSegmentName follows the established pattern for sync receive settings and is correctly placed in the synchronization settings section.

wled00/set.cpp (1)

382-382: LGTM! The new setting handler is well-integrated.

The addition of the "SN" argument handler follows the established pattern for sync receive settings and is correctly placed in the synchronization settings section.

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
@Liliputech Liliputech requested a review from blazoncek February 19, 2025 14:07
Copy link
Collaborator

@blazoncek blazoncek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know there is a desire to sync segment names across devices (though I can't find justification) but this implementation is "wasteful" in terms of needed bytes to transmit a name (i.e. if I name segment "A" it will still transmit 32/64 bytes for name instead of only 2 - 'A' and '\0').

@@ -647,18 +647,20 @@ typedef class Receive {
bool Color : 1;
bool Effects : 1;
bool SegmentOptions : 1;
bool SegmentName : 1;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should have not "resolved" this as you did not address my comment.
reservedis a placeholder for future enhancement as this PR so replace it with SegmentNameoption.

@@ -338,6 +340,13 @@ static void parseNotifyPacket(const uint8_t *udpIn) {
selseg.check1 = (udpIn[31+ofs]>>7) & 0x1;
}
}
if (receiveSegmentName) {
const char* name = (char *) &udpIn[36+ofs];
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can pass udpIn[...]directly to setName() no need to check for length or content.
You also do not need to clearName() prior to setName().

Also, indentation is off.

bool SegmentBounds : 1;
bool Direct : 1;
bool Palette : 1;
uint8_t reserved : 1;
};
};
Receive(int i) { Options = i; }
Receive(bool b, bool c, bool e, bool sO, bool sB, bool p)
Receive(bool b, bool c, bool e, bool sO, bool sN, bool sB, bool p)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Normally one would add new additions at the end to increase compatibility. Just a personal opinion.

packetSize += UDP_SEG_SIZE;
s0++;
}
// since we sync the name, only one segment can fit in the first packet
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a waste of packet space. Do not forget that the same packet is re-used in ESP-NOW sync.
ESP-NOW packet can only contain 250 bytes so "compression" of data is a must.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants