# Sending Multi Segment UDP Packets to WLED

**URL:** <https://wled.discourse.group/t/sending-multi-segment-udp-packets-to-wled/6378>\
**Category:** Integrations\
**Created:** [November 17, 2022, 10:11pm UTC](https://wled.discourse.group/t/sending-multi-segment-udp-packets-to-wled/6378 "2022-11-17T22:11:26Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![beatKeeper](https://yyz2.discourse-cdn.com/free1/user_avatar/wled.discourse.group/beatkeeper/32/3866_2.png) [@beatKeeper](https://wled.discourse.group/u/beatKeeper)\
**Post date:** [November 17, 2022, 10:11pm UTC](https://wled.discourse.group/t/sending-multi-segment-udp-packets-to-wled/6378/1 "2022-11-17T22:11:26Z")

</div>

Hello! I’m trying to be able to send UDP packets at a WLED instance by way of a Python script. I can get this to work to an extent. If a segment is selected, it will be affected by the UDP packet I send, but if it’s not, I can’t figure out how to control the segment - or even change what’s selected via UDP.

Using Wireshark I’ve scoped the packets that are sent out to notify other instances, but they don’t seem to have multi segment component information.

I see how this is possible using the JSON API , I’ve looked over the udp.cpp code on GitHub and I am using WLED 0.13.1. Any pointers about the structure of the UDP packet would be super helpful, thanks!

---

<div class="post-metadata">

**Author:** ![gbd](https://avatars.discourse-cdn.com/v4/letter/g/b5ac83/32.png) [@gbd](https://wled.discourse.group/u/gbd)\
**Post date:** [November 18, 2022, 1:38am UTC](https://wled.discourse.group/t/sending-multi-segment-udp-packets-to-wled/6378/2 "2022-11-18T01:38:19Z")

</div>

@beatKeeper, First things first, I am no authority in WLED internals. That said:

- A few `#defines` and constants to note (from `udp.cpp`):

- Consider the following 2-segment preset JSON:

- Hook up a _ **receiver-ESP32** _ to your computer’s USB-serial

- Add the following hack in `udp.cpp`, compile and upload to the receiver-ESP32:

- Enable `Sync` on your sender-ESP32. Assuming you sent the 2-segment JSON preset shown above to the sender-ESP32, it should “forward” (and the receiver-ESP32 should print out) a UDP sync packet similar to this [dump](https://www.dropbox.com/s/dvmc9a6kewbcfhs/wled-udp-sync-preset-dump.txt?dl=0)…I used Linux CLI `screen -L -Logfile log.txt /dev/ttyUSB0 115200` to grab this serial log.

- Comparing the UDP packet dump and the preset JSON, along with the comments in `udp.cpp::notify()`, things should be quite self-explanatory:

Hope this helps!  
Gbd

---

<div class="post-metadata">

**Author:** ![beatKeeper](https://yyz2.discourse-cdn.com/free1/user_avatar/wled.discourse.group/beatkeeper/32/3866_2.png) [@beatKeeper](https://wled.discourse.group/u/beatKeeper)\
**Post date:** [November 18, 2022, 3:20am UTC](https://wled.discourse.group/t/sending-multi-segment-udp-packets-to-wled/6378/3 "2022-11-18T03:20:21Z")

</div>

@gbd This is a great strategy. Generally jives with what I was trying but I love the serial print hack for feedback. Gonna give this a whirl. Thanks!

---

<div class="post-metadata">

**Author:** ![beatKeeper](https://yyz2.discourse-cdn.com/free1/user_avatar/wled.discourse.group/beatkeeper/32/3866_2.png) [@beatKeeper](https://wled.discourse.group/u/beatKeeper)\
**Post date:** [November 18, 2022, 8:21am UTC](https://wled.discourse.group/t/sending-multi-segment-udp-packets-to-wled/6378/4 "2022-11-18T08:21:32Z")

</div>

Got this working full boat now. The main catch for me was UdpIn[36]. This has to be set to 1 for the segment stuff to actually work. Then everything works as expected.

FYI - the incoming packet is variable length. First part is 41 bytes - each add’l segment you want to take to is another 36 bytes. You tell WLED how many segments you’re talking to in UdpIn[39] and leave UdpIn[40] set to 36 (0x24). So for talking to two segments your packet length is (41 + 36 + 36) 113 bytes.

Super appreciate how you jumped in to help @gbd !

Please hit me up if anyone needs any help sorting out something similar with the UDP notify.

---

<div class="post-metadata">

**Author:** ![gbd](https://avatars.discourse-cdn.com/v4/letter/g/b5ac83/32.png) [@gbd](https://wled.discourse.group/u/gbd)\
**Post date:** [November 18, 2022, 9:44am UTC](https://wled.discourse.group/t/sending-multi-segment-udp-packets-to-wled/6378/5 "2022-11-18T09:44:58Z")

</div>

@beatKeeper, Nice. I might just use this setup in the near future. Thank you too.

---

<div class="post-metadata">

**Author:** ![vancleavrs](https://avatars.discourse-cdn.com/v4/letter/v/53a042/32.png) [@vancleavrs](https://wled.discourse.group/u/vancleavrs)\
**Post date:** [March 19, 2024, 7:55pm UTC](https://wled.discourse.group/t/sending-multi-segment-udp-packets-to-wled/6378/6 "2024-03-19T19:55:54Z")

</div>

@beatKeeper Hello! I’m working on the exact same problem, and this is the only post I could find with relevant information. I apologize in advance if it’s bad manners to reply to a two year old topic!

I’ve read through this several times, but I must be missing something small but crucial in order to get it to work. If you could provide some more explicit information it would be very appreciated! I’m able to send UDP commands that affect all of the segments that are checked in the UI, but I’m not able to control them individually directly through UDP. I have made sure to enable segment options in the Sync Setup menu on the web UI.

My packet setup is as follows:  
UDP[0 - 23] are as outlined in the 24 byte UDP packet in the [notifier protocol](https://mm.kno.wled.ge/interfaces/udp-notifier/). I was pretty easily able to get this working properly, but the rest of the packet seems to be ignored entirely.

UDP[24-35] looking at `udp.cpp`, this seems to be for time syncing between units. I’m not sure if I’d need to pass anything here, so I’ve left these at 0x00.

UDP[36] I’ve set to 0x01 as you noted.  
UDP[39] is set to 0x02, as I’m working with two segments.  
UDP[40] is set to 36 (0x24)  
UDP[41-76] is info for my first segment.  
UDP[77-113] is info for my second segment.

Just to be very explicit with where I’m at, here’s the structure of my segment packets. I based these again off of the ‘udp.cpp’ file.  
UDP[0] - Segment number (0x00 for my first segment, 0x01 for my second segment).  
UDP[1-2] - Start LED  
UPD[3-4] - Stop LED  
UDP[5] - Grouping  
UDP[6] - Spacing  
UDP[7-8] - Offset  
UDP[9] - Options  
UDP[10] - Opacity  
UDP[11] - Mode  
UDP[12] - Speed  
UDP[13] - Intensity  
UDP[14] - Palette  
UDP[15-18] RGBW Primary  
UDP[19-22] RGBW Secondary  
UDP[23-26] RGBW Tertiary  
UDP[27] - CCT  
UDP[28-35] - All set to 0x00

Please let me know if there is anything I’m overlooking.

---

<div class="post-metadata">

**Author:** ![blazoncek](https://yyz2.discourse-cdn.com/free1/user_avatar/wled.discourse.group/blazoncek/32/1886_2.png) [@blazoncek](https://wled.discourse.group/u/blazoncek)\
**Post date:** [March 20, 2024, 7:54am UTC](https://wled.discourse.group/t/sending-multi-segment-udp-packets-to-wled/6378/7 "2024-03-20T07:54:18Z")

</div>

FYI you can always send JSON API (and even HTTP API) via UDP in the same way as HTTP.  
It may be inefficient for many segments, but simpler if you are dealing with only one segment.

---

<div class="post-metadata">

**Author:** ![vancleavrs](https://avatars.discourse-cdn.com/v4/letter/v/53a042/32.png) [@vancleavrs](https://wled.discourse.group/u/vancleavrs)\
**Post date:** [March 20, 2024, 1:36pm UTC](https://wled.discourse.group/t/sending-multi-segment-udp-packets-to-wled/6378/8 "2024-03-20T13:36:08Z")

</div>

Thanks @blazoncek . For my use case, I’m working with a Productivity 1000 PLC so my tools for communication protocols are very limited. There is unfortunately not an easy way to build the strings required for JSON, but HTTP might be a bit more manageable. I’ll see if I that works as an alternative, though sending the byte array (however tedious to set up) is probably still ideal.

---

<div class="post-metadata">

**Author:** ![beatKeeper](https://yyz2.discourse-cdn.com/free1/user_avatar/wled.discourse.group/beatkeeper/32/3866_2.png) [@beatKeeper](https://wled.discourse.group/u/beatKeeper)\
**Post date:** [March 20, 2024, 2:23pm UTC](https://wled.discourse.group/t/sending-multi-segment-udp-packets-to-wled/6378/9 "2024-03-20T14:23:00Z")

</div>

Hey there - sorry to say I’ve been off of this project for a good long time now so it’s all a bit fuzzy for me. I know WLED has moved through some versions over that time so the first place I’d look is to see if the specifiers for segment size and quantity have moved. Then I’d make sure that segments are still expecting the same length (36). I wonder if extra options have changed any of that stuff. I’ll dig around in my IDE and see if I can find anything more helpful.

---

<div class="post-metadata">

**Author:** ![blazoncek](https://yyz2.discourse-cdn.com/free1/user_avatar/wled.discourse.group/blazoncek/32/1886_2.png) [@blazoncek](https://wled.discourse.group/u/blazoncek)\
**Post date:** [March 20, 2024, 7:57pm UTC](https://wled.discourse.group/t/sending-multi-segment-udp-packets-to-wled/6378/10 "2024-03-20T19:57:00Z")

</div>

anything UDP related is in udp.cpp

and make sure you use 0\_15 branch or you’ll have headache down the road

---

<div class="post-metadata">

**Author:** ![vancleavrs](https://avatars.discourse-cdn.com/v4/letter/v/53a042/32.png) [@vancleavrs](https://wled.discourse.group/u/vancleavrs)\
**Post date:** [March 21, 2024, 5:26pm UTC](https://wled.discourse.group/t/sending-multi-segment-udp-packets-to-wled/6378/11 "2024-03-21T17:26:19Z")

</div>

I’ve got the HTTP setup working pretty nicely! Thanks again @blazoncek for the suggestion.

Just in case anybody else from the PLC world stumbles upon this, here’s the implementation I went with for building the string in Productivity.

 ![image](https://global.discourse-cdn.com/free1/uploads/wled/original/2X/e/ea4ab06f254234f7fca741673877b7f761e9f3a5.png)

@beatKeeper thanks for looking into it. I’d still love to get the byte array working, as addressing more than 10 segments would be useful for future applications. As far as I can tell, the info that you and gbd provided matches up with the latest udp.cpp file.
