Aircoookie / WLED

Control WS2812B and many more types of digital RGB LEDs with an ESP8266 or ESP32 over WiFi!
https://kno.wled.ge
MIT License
15.16k stars 3.28k forks source link

Change LED colors from another PC in LAN #13

Closed pete111 closed 6 years ago

pete111 commented 6 years ago

Hello, I would like to constantly send string of colors for let's say LEDs to esp8266 from another computer in my network (so not just use predefined effects in esp, but my own values for LED strip). How this can be done?

P.S. also some kind of "smoothing" would be great between original colors on LED strip to newly sent colors for LED strip (I mean smoothing effect for customly set frequency probably 10-100ms - just to prevent choppy fast unpleasant changing of colors from old colors to new colors).

Aircoookie commented 6 years ago

Hi,

both the things you'd like to achieve should be possible with the current version of the software. To set new colors automatically from another computer, there is the HTTP API: https://github.com/Aircoookie/WLED/wiki/HTTP-request-API This solution only works if you want to update the WLED colors, effects, etc.

If you instead want to send each LEDs individual color constantly (i think this is what you'd like to do), you can do so with an UDP packet: https://github.com/Aircoookie/WLED/wiki/UDP-Realtime-Control-(WARLS) There are 3 different protocols you can choose depending on your use case.

The "smoothing" is supported when changing colors normally (via the API, for example). You can toogle it and set its duration in LED Settings -> Transition. With the UDP control, the aim is realtime LED control as fast as possible. Therefore, no smoothing is possible because you are expected to send 20-60 UDP packets per second, which creates a fluid animation by itself. However, if you require such a solution (say you only send a new UDP packet every 10 seconds), I could try to add that, however it would be difficult.

Let me know if those solutions work for you or if you'd like me to help you with anything else!

pete111 commented 6 years ago

thanks @Aircoookie for perfect answer! I didn't know that it is possible via WARLS, thank you for pointing me the right direction, I will try it with ESP-01. I would appreciate some sample code for UDP communication (how "string" with colors for LEDs should look like and should be chained e.g. for 20 leds via one udp message) - because of newbies like me :)

Aircoookie commented 6 years ago

Ok, I'll try to offer some basic advice, however I can't give you a comprehensive example since I don't know which programming language you want to use and what exactly you'd like to achieve. In many cases there are already programs available (like for an ambilight) or it would be way simpler to add the animation/feature you want into the WLED code itself :)

First of all, for every major desktop programming language there should be a library for sending UDP network packets (UDP client). A UDP packet consists of a header (the library does that for you) and your data, which is an array of bytes (values from 0-255). If you want to upate each of your LEDs with a packet, i'd recommend the DRGB protocol, since it's the simplest. For that, you need to send a UDP packet to the ESP8266s IP address with the port set in the WLED settings (the default is 21324). The first byte has the value 2, the second one is how many seconds after the packet is received before returning to normal mode (try 5 as a value). The third byte is the Red color value for the first LED, the fourth the Green value and the fifth the Blue value. Byte 6 is the Red value of the second LED, and so on.

I hope we can work together to make WLED working the way you want it to :)

pete111 commented 6 years ago

Many thanks Aircoookie! I think I understood it a bit better after your clarification. I am really interested in the thinks like ambiligt as you mentioned - could you advice me some existing programs for it? In few hours I will experiment ith my ESP01 a bit.

Aircoookie commented 6 years ago

Thank you, always happy to help :)

For Ambilight, there is a cool Windows program called AmbiBox. It is in fact compatible with WLED in the current version, but requires an USB serial connection (Adalight protocol). I'm actively working on a solution to make it work via WiFi. The Linux/Raspberry Pi program called "Hyperion" is excellent and also compatible via USB, and soon via WiFi. If you want a music visualisation, you can try audio-reactive-led-strip: https://github.com/Aircoookie/audio-reactive-led-strip . It only works via WiFi.

pete111 commented 6 years ago

hi @Aircoookie, perfect, I am experimenting with Hyperion, hopefully soon it will be compatible via Wifi. By the way, I stuck on one problem - when I am trying to upload WLED_0.6.4_ESP8266.bin over OTA, it shows me error on my esp8266-01 /Arduino IDE: 512K (No SPIFFS)/: Update error: ERROR[4]: Not Enough Space

/with Arduino IDE: 4M (1M SPIFFS)/ i am getting: Update error: ERROR[8]: Flash config wrong real: 1048576 IDE: 4194304

Update: I tried to flash it via Arduino IDE. It seems it is flashed, I set apSSID but after start just blue LED is blinking. :(

Any idea please?

Aircoookie commented 6 years ago

Hi @pete111 , I'll try to make Hyperion (via WiFi UDP) compatible in the next version!

About the esp8266-01, it's difficult maintaining support for it because it only has got 512K of flash memory. WLED is almost too complex to work with that little memory, but it should just work with ESP8266 Arduino core version 2.3.0 (uses less memory than 2.4.0) with the setting 512K (64K SPIFFS). No SPIFFS doesn't work because WLED needs some 4kB to save configuration like WiFi data. The binaries will never work since they are compiled for for the ESP-12E models (NodeMCU, Wemos D1) and require 4MB of memory.

What do you mean by "you set apSSID"? Did you just change the value in the code or could you in fact connect to the access point "WLED-AP" and changed some setting there? I hope you can get it to work, however I can't promise esp8266-01 will work because of its limited memory.

pete111 commented 6 years ago

Hi @Aircoookie, thanks for prompt reply. I am going to try it as you described. By apSSID - I change it in wled00.ino file I will let you know once I have something new.

Aircoookie commented 6 years ago

Great :) If you can't get it to work, you could also try this binary that should work on esp8266-01 wled064-esp01.zip

pete111 commented 6 years ago

bingo! I was able to upload flash it with Arduino IDE with 2.3.0. The next step is to connect LEDs. I left your bin as last rescue :) Thanks for that. I keep you informed!

pete111 commented 6 years ago

wohooo, it works! :-) I can experiment with it now :-D Thank you milliontimes!

pete111 commented 6 years ago

Today I had time to try it with python - UDP data, something like - it was just my first attempt with no luck:

import socket
import pickle

UDP_IP = "192.168.1.59"
UDP_PORT = 21324
#MESSAGE = "2,5,5,5,5"       
arr = ([2],[5],[255,255,255])
MESSAGE = arr
MESSAGE = pickle.dumps(MESSAGE)

print "UDP target IP:", UDP_IP
print "UDP target port:", UDP_PORT
print "message:", MESSAGE

sock = socket.socket(socket.AF_INET, # Internet
                     socket.SOCK_DGRAM) # UDP
sock.sendto(MESSAGE, (UDP_IP, UDP_PORT))
pete111 commented 6 years ago

I tried to use Packet Sender (portable program for sending UDP packets) for Windows but I did not have luck to control LEDs via UDP. Which ASCII/HEX values should I send please?

Aircoookie commented 6 years ago

Hi, sorry that I didn't respond earlier. For testing you could try and send a 5-byte packet: 2,5,255,0,0 (hex: 02 05 FF 00 00) which would set the first LED to red.

Also please try and go to the Sync settings menu and ensure that the UDP port is the same you used in Packet Sender. In the line below the UDP port ("Receive") at least one of the three options Brightness, Color and effects must be checked for it to work. Try checking all of them for testing. Also please check if the sync arrow icon next to the settings cog in the web UI is yellow. If not, click on it until the top part of the icon or the entire icon is yellow. Now it should work.

If this doesn't work, your home network may have a firewall that prevents some UDP traffic, although that is unlikely. You could try a different UDP port or check the router configuration, though!

pete111 commented 6 years ago

Hi @Aircoookie, no need to apologize. Before I wrote you I tried exactly the same packet. All the settings were the same as you described. I found out that there must be some bad hex value (coming out from my computer). Because once I tried not ASCII but just HEX value from Android UDP sender app, it worked. Perfect, now I know it works and I am proceeding to the next step to find our why it was not working via my computer. :) Many thanks again

Aircoookie commented 6 years ago

Closing since Hyperion is now working :)