Hello, I am trying to get UDP stuff to work with an ESP32.
This is the code I currently have:
# Set the IP address and port of the WLED controller
controller_ip = "10.0.0.233" (my ESP IP)
controller_port = 21324
# Create a socket to send data to the controller
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
# Define the LED data
led_data = bytearray([0, 0, 255, 0, 0]) # LED 0, red color (255, 0, 0)
# Send the LED data to the controller
sock.sendto(led_data, (controller_ip, controller_port))
In my mind, this should turn the first LED red. however nothing happens. Am I not understanding this code correctly?
I got the UDP port # in the sync tab, next to UDP port.
Sadly the JSON API is too slow for my needs, so perhaps I should restate my question;
Could someone assist me by giving me a piece of code that would change the color of the first LED in WLED to red. I dont need any of the backend stuff, but I just cannot understand how UDP connections work with WLED.
I have made some progress since my first post! After spending a lot of today working on trying to understand this. But I still have some questions for any dev reading this.
So, I want to use the DNRGB protocol, which means my byte stream needs to start with a 4 (in binary 00000100),
My second value is how long I want the LEDs to stay on, in my case this doesn’t matter since im hopping to ping em like 30 times a second, so lets say 1. (00000001).
My third and fourth value are a mystery to me, in the docs they are simply referred to as “start index low byte and start index high byte”. My assumption is this is 16 bits allowing you to set an index between 1 and 2^16. (please do confirm if this is correct).
My fifth, sixth, and seventh values are the RGB values of the next pixel, and this repeats until my packet ends after 489 LEDs.
So for example, if I wanted to simply turn the first LED to red, I would send the following data as far as I understand;
00000100 00000001 00000000 00000000 11111111 00000000 00000000
4 1 0 255 0 0
Protocol 4 | 1 second | Index 0 | R = 255 | B=0 | G= 0
2 questions then:
how does the third and fourth byte need to be formatted (technically 2nd and 3rd if we start counting from 0)?
Does the byte stream need to be terminated. IE; DMX has these flags bytes they specify at the end of packages to tell the driver software to “display everything now”, or are my last 3 bytes just the RGB value of the 489th led in that packet.
Hopefully my question makes sense, and thanks to anyone who takes the time to answer this.
I have gotten the JSON API stuff to work, enough to realize I cant get 45 FPS with 1764 LEDs unfortunately. the advantage of UDP is it s lower level. I will take a look at the source code and see if I can figure out the combination of bytes to get this to work. Thanks!