Milight (limitless led) control via UDP [esp standalone] pi server

Just got control of my Milight RGBW 11w led bulbs using Blynk…

maybe of use to someone.

I found the codes at https://raw.githubusercontent.com/stoman/milight-api/master/doc/limitlessled-documentation.txt, and found that communication is via UDP and port 8899.

I managed to cobble together (with my limited knowledge) a program that allows me to have faster /easier control (on/off and colour) than the app that comes with it. So now I can control my surround sound volume (spi digital pot) my talktalk YouView common commands plus(ir) and control the lights with one app and one dashboard.
Happy man.

Anyway UDP control was quite simple in the end …
First add

 #include <WifiUdp.h>

Then add

const intUDP_PACKET_SIZE = 3;
byte packetBuffer[UDP_PACKET_SIZE];
unsigned int localPort = 8899; // Milight port     
int milight; //data to send to milight
IPAddress udpServer(255, 255, 255, 255);
WiFiUDP Udp;

And in setup() add
// v22 button lamps on, button v23 lamps off, slider v25(0-255) is colour. (group1)

 BLYNK_WRITE(V22)
  {
   
   memset(packetBuffer,0,UDP_PACKET_SIZE);
   packetBuffer[0]=0x45;
   packetBuffer[1]=0x00;
   packetBuffer[2]=0x55;
   Udp.beginPacket(udpServer, 8899);
   Udp.write(packetBuffer,UDP_PACKET_SIZE);
   Udp.endPacket();  
  }
 BLYNK_WRITE(V23)
  {
   memset(packetBuffer,0,UDP_PACKET_SIZE);
   packetBuffer[0]=0x46;
   packetBuffer[1]=0x00;
   packetBuffer[2]=0x55;
   Udp.beginPacket(udpServer, 8899);
   Udp.write(packetBuffer,UDP_PACKET_SIZE);
   Udp.endPacket();  
  }

  BLYNK_WRITE(V25) // colour slider
{
   unsigned int colData = param.asInt();
   
   memset(packetBuffer,0,UDP_PACKET_SIZE);
   packetBuffer[0]=0x40; //command change colour
   packetBuffer[1]=colData; //0x00; // colour number 0-255
   packetBuffer[2]=0x55;
   Udp.beginPacket(udpServer, 8899);
   Udp.write(packetBuffer,UDP_PACKET_SIZE);
   Udp.endPacket();  
  }
1 Like

Hey! Thank for sharing! This is a very good Blynk application example! Love it!
I was doing something similar quite some time ago, I got Hubsan X4 quadcopter controlled by Blynk.
I think this shows very good perspective and potential of our platform. Cheers! :wink:

Hello, I’m new to all this, I have milight and want to set up a bunch of other home automation stuff.
The attraction of blynk is it looks like a way to tie everything together with one app to control them all.

So the code you have posted is for a raspberry pi? I’m assuming that’s your “central server” for everything?

I’ve done stuff with arduino before and only just ordered some esp8266 modules from ebay.

Is the best way to go to have a pi and can I get that to control other things so it’s all on the one screen?

Sorry for the newb questions.

Marty

Hi,

Yes, I use a pi to run the ‘local server’. It is wired into my home wireless network, rather than being a standalone wireless ap. (I do use a wireless ap pi server at work though, as it is convenient when I do my semi-retirement days of development). I use the local server mode so that I am not restricted in terms of speed etc.
The wired mode has the advantage of fast outside access if I want it.

I used the pi initially as an mqtt broker, when I was first playing with iot along with B4A for android development.This format is good, no doubt, but initially relied on using a windows espressif SDK and a lot of C programming for the esp’s. Node red etc etc.

Then along comes the arduino esp environment and Blynk. At £2 a piece for esp12’s (ali express) who wouldn’t use them? If I want extra I just add STM8s discovery boards at £6 a shot. (You, no doubt would use smaller arduino boards.)

You don’t have to use a pi if you want to start with the Blynk. Cloud access provides for easy entry into the learning curve. (You can even set the local server up on a Windows machine, and if the PC allows set that up as an individual ap!)

The Arduino esp environment is really useful for me ( Use 1.6.5 as 1.6.6 is not favoured with the esp - read the forum - wish I had before I installed it! lots of wtf’s!). There are so many clever guys out there writing libraries etc, there’s not a lot you can’t get to work.

The Blynk app provides an exceptionally easy and professional looking format for control and communication.
Bear in mind that continual development is taking place with the Blynk app, ( at least it actually is, whereas other apps seemed to fall by the wayside on that).
At the moment you might find there is not enough room on one dashboard for all the buttons and sliders you would like, but that will change. There are ways around this, as has been described in this forum, where you apply several auth codes to one board, and switch between them.

One of my dashboards controls my common YouView buttons, a digital pot for my surround separates, and controls on/off Milights. Other dashboards display various temp/humidty, etc.
The Milight udp control is virtually instant compared to the actual milight app, which can be really annoying at times.

So, after all that yes, I think it will do what you want without any problems at all. Everything can be frustrating, of course, but stick with it and you should have some fun.