Repository navigation
Description
esp32 boards with PSRAM have MAX_NUM_SEGMENTS=64, while normal esp32 builds use MAX_NUM_SEGMENTS=32, and esp8266 uses MAX_NUM_SEGMENTS=16.
The UDP notifier (WLED SYNC) does not work as expected in the 64 segment configuration. It always sends WLEDPACKETSIZE (2345 bytes for all 64 segments) notification data, for example when changing brightness or activating a preset.
Unfortunately, the arduino-esp32 core automatically splits the UDP datagram at byte 1460, and the notification receiver cannot re-assemble the split message. The second datagram usually contains random junk (uninitialized memory). Depending on pure coincidence, handleNotifications() will either ignore the data, parse it as a second change notification that supersedes the first, treat it as hyperion / raw RGB, or handle it as a HTTP or JSON API request.
The problem occurs whenever MAX_NUM_SEGMENTS > 39, and was confirmed during testing in PR #5932.
PR #5932 will provide a partial fix by ensuring that the second packet only contains valid data, and the content will be ignored unless users have more than 39 active segments. However, a full solution that properly syncs all 64 segments is not available yet.
Line 9 in fce41f2
| static constexpr size_t WLEDPACKETSIZE = 41+(WS2812FX::getMaxSegments()*UDP_SEG_SIZE); // make sure this is known at compile-time |
Line 40 in fce41f2
| byte udpOut[WLEDPACKETSIZE]; //TODO: optimize size to use only active segments |
Lines 196 to 199 in fce41f2
| IPAddress broadcastIp = ~uint32_t(WLEDNetwork.subnetMask()) | uint32_t(WLEDNetwork.gatewayIP()); | |
| notifierUdp.beginPacket(broadcastIp, udpPort); | |
| notifierUdp.write(udpOut, WLEDPACKETSIZE); // TODO: add actual used buffer size | |
| notifierUdp.endPacket(); |
File NetworkUDP.cpp, NetworkUDP::write(), line ~277
size_t NetworkUDP::write(uint8_t data) {
if (tx_buffer_len == 1460) {
endPacket();
tx_buffer_len = 0;
}
tx_buffer[tx_buffer_len++] = data;
return 1;
}
size_t NetworkUDP::write(const uint8_t *buffer, size_t size) {
size_t i;
for (i = 0; i < size; i++) {
write(buffer[i]);
}
return i;
}the split at 1460 is hard-coded inside arduino-esp32 !!
Activity
[-]esp32: UDP SYNC (notifer) sends second packet with random data when MAX_NUM_SEGMENTS > 39[/-][+]esp32: UDP SYNC (notifier) sends second packet with random data when MAX_NUM_SEGMENTS > 39[/+]softhack007 commentedon Nov 3, 2026
It seems that AsyncUDP has a similar problem - see espressif/arduino-esp32#12162
softhack007 commentedon Nov 3, 2026
@coderabbitai please scan the current source code for other locations where UDP messages of > 1460 bytes can be created and might get spit by the framework UDP class (WiFiUDP, maybe AsyncUDP too). Provide a short answer, listing the WLED features that might be affected by the problem.
coderabbitai commentedon Nov 3, 2026
Analysis chain
Script executed:
Length of output: 10089
Script executed:
#!/bin/bash gh issue view 5951 --repo wled/WLED --json title,body,comments gh issue view 12162 --repo espressif/arduino-esp32 --json title,body,commentsLength of output: 9819
Script executed:
Length of output: 19369
Script executed:
Length of output: 59049
@softhack007I scanned the current source (fce41f26), including usermods.notify()sends41 + 36 × maxSegmentsbytes. This exceeds 1460 bytes at 40 segments and reaches 2345 bytes at 64 segments (wled00/udp.cpp, Line 198).WLED_DEBUG_HOST): One additional potential case.NetworkDebugPrinter::write()passes the full buffer toWiFiUDPwithout a size limit (wled00/net_debug.cpp, Line 42). Long debug messages, such as logged MQTT payloads or HTTP Pull Light Control JSON responses, can exceed 1460 bytes.No other oversized transmit path found. DDP output uses at most 1450 bytes, including its header. Art-Net output uses at most 530 bytes. Audio sync, NTP, discovery, Alexa discovery, and segment-name sync use smaller packets.
The current source uses AsyncUDP only for reception. The linked upstream issue describes transmit truncation, not splitting, so I found no current WLED transmit path exposed to that AsyncUDP problem.
This was source inspection only, not a device test.
Learnings used
You are interacting with an AI system.
softhack007 commentedon Nov 3, 2026
@coderabbitai please check if we have other cases in WLED where a buffer with partly uninitialized data can be sent by UDP.
coderabbitai commentedon Nov 3, 2026
Analysis chain
Script executed:
Length of output: 13729
Script executed:
Length of output: 53451
Script executed:
Length of output: 15878
Script executed:
Length of output: 6441
@softhack007I checked the UDP transmit paths atfce41f26, including usermods. I found one additional case: Art-Net discovery replies (ArtPollReply).wled00/e131.cpp, Line 387 declaresArtPollReply artnetPollReply;without initialization.strlcpy()forreply_short_nameandreply_long_name. Bytes after the string terminators remain uninitialized.reply_node_reportbut also leaves its unused bytes uninitialized.Clear the complete object before filling its fields. For example, at the start of
prepareArtnetPollReply():I found no additional cases in the other inspected transmit paths. NTP and audio sync clear their buffers. Segment-name sync and Alexa discovery send only initialized string data. DDP and Art-Net pixel output use a zero-initialized pixel buffer.
The known WLED Sync case also sends uninitialized bytes when fewer than the maximum segments are active, even when the packet stays below 1460 bytes.
This was source inspection only, not a device test. I followed your supplied guidance to distinguish inspected findings from test results.
Learnings used
You are interacting with an AI system.
Update udp-notifier.md with packet size details (wled/WLED#5951)
softhack007 commentedon Dec 1, 2026
bugfix is in #5932, un-linking this bug report from 16.1 to remove a duplicate toDo entry.