Music_mode not working

So I’ve finally got the light bulbs on hand in my app and can change brightness etc… However when I link the brightness to my music variable, it flashes according to my music for about 5 seconds and then it just doesn’t respond.

So I look through the documentation and it says to have an unlimited amount of commands send to the bulbs I need to activate music mode. But after sending in the command to activate music_mode it has the same issue as before.

Basically it works for 4-5 seconds and then I’m unable to control the bulb even with my brightness slider as if it lost connection to the bulb.
My while loop with a delay of 50ms is changing brightness based on the value of my music variable.

Is there a bug with music mode or am I not sending the command correctly?

Basically I’m sending in this command:
{“id”:,“method”:“set_music”,“params”:[1, “", 54321]}

The IP Address is my computer’s IP and the port is a random number I simply typed in. Have checked if that port is being used and it isn’t.

I’ve even tried sending the music stop command before activating the music mode just to make sure it doesn’t try to activate music mode if it’s already activated or glitch out:

Am I suppose to key in the bulb’s ip address instead? Or am I not suppose to key in my computer’s ip address? Do I need to configure anything in windows for the port to work?

After I’ve sent in the set_music command I start the loop with this:
{“id”:,“method”:“set_bright”,“params”:[musicVariable, “smooth”, 70]}

And then like I said it works for around 5 seconds (with or without activating the music mode") and then it just stops responding.

Help appreciated

Before using muic mode you need to turn your computer into a server so the bulb can connect to it. That’s why the bulb stops responding, music mode is not in use.
Everything is stated in the documentation.

I think the server port must be 55440. And yes, you need to be running the server on your PC on that port.

The music mode basically tells the bulb to receive commands from a server without replying, it just listens to the server IP and port, and reads the commands.

Thanks for clearing it up dalanik/jordi,
but how do I turn my computer into a server?
Do I have to code something similar to this?

Yes. You are sending commands to the bulb, if you use the API. You need a server and you must to send it colors which it will change to.

Damn… I’m this close in getting my music analyzer integration to work… And now I’ve got to dig deeper into this tcp server stuffs which I have no clue about just to activate music mode. Is there an easier straight forward way to do this like another app that automatically turns the computer into a server? Or do you mind posting a sample code on calling the functions to create the server?

It is not only about making a server; that is the easy part, but you need to send COLORS to the bulb. so you’d need also software to analyze music data and convert it to colors…

I’ve already done the music analyzation/data part and for colors I can just use the set color command and hook the r b g params to my music spectrum data am I right?
Everything relating to music data I’ve done it and have tested it on non music mode which is working perfectly as I want it to… just that it only works for 5 seconds before losing connection…

I just left this music server setting up part which I find it much more difficult to learn then the music data part.

EDIT: By “send “COLORS”” you mean the command way right? Basically once my music server is set up I would still be using the api’s commands to control the light bulb right?

Yes, standard API commands.

What language are you using? It shouldn’t be too hard to find example of server somewhere. I did it in Python.

I’m using C# and .NET Framework 4.5

I got my server started as you can see below:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using YeelightClient;
using TcpLib;

namespace Sound.TCPServer
class MusicServiceProvider : TcpLib.TcpServiceProvider
Form1 form1 = Sound_Analytics.ActiveForm as Form1;

    public override object Clone()
        return new MusicServiceProvider();

    public override void OnAcceptConnection(ConnectionState state)
        Console.WriteLine("Received Connection");
        throw new NotImplementedException();         //  form1.MusicMode();

    public override void OnDropConnection(ConnectionState state)
        throw new NotImplementedException();

    public override void OnReceiveData(ConnectionState state)
        throw new NotImplementedException();


I’m basically using these 4 server scripts:

My MusicMode method gets called, and I’ve checked via CMD Telnet, music mode on the bulb is set to 1.
That being said, the bulb flashes to the beat of my music for 3-5 secs and still loses the connection after that…

Any idea? Am i not running the right server scripts? I mean the OnAcceptConnection(ConnectionState state) should only call when there is a connection, this means it did picked up something right?

EDIT: Oh wait must I send in my commands through the server script’s Write method instead of my tcpDeviceIO write method?

Here’s the server’s write method:

/// Sends Data to the remote host.

public bool Write(byte[] buffer, int offset, int count)
_conn.Send(buffer, offset, count, SocketFlags.None);
return true;
return false;

Should I be sending my commands through this instead of my other non-server class write method?

Yes, you have to send them through the server

Yes, you do. And don’t forget there is no reply from the bulb when it is in music mode.

Thank you dalanik/jordi, I managed to get it to work. No more disconnections after 5 seconds. Now the think is I need to buy more bulbs to start working on multiple bulbs support but I do not want to end up buying a 2nd bulb just to find out that I can’t precisely control more then one bulb simultaneously (each doing different patterns of pulsing).

If I were to send in 2 different commands while on music mode to bulb 1 and bulb2 and maybe in future 3-5 more bulbs, am I right to say there won’t be any issue? I’m guessing I’ll have to code a method to hook up with all bulbs in my vicinity and then control from there?

Just so I’m on the same page does this sentence:
NOTE: Currently WiFi smart device support up to 4 simultaneous TCP connections, any further
connect attempt will be rejected.


  1. a maximum of 4 APPS is capable of simultaneously linking to 1 bulb?
  2. 1 APP is capable of sending commands to a maximum of 4 bulbs?

If it means option no.1, then is there a limit as to how many bulbs an app is able to handle simultaneously?

Also I know music mode doesn’t have a quota to the bulbs, but is spamming commands say like per 10ms to a bulb harmful in anyway?

Oh and there’s nothing we can do about the response time for each command to the bulb right? I’m noticing the pulse is roughly about 100-200ms slower than audio.

It means a maximum of 4 clients can control the bulb at one time in LOCAL mode.

I don’t think there’s a limit.

Please don’t worry about it, there’s no harmful to bulb if you know how the LED bulbs works with PWM.

Thanks for the clarification dinyichen. I’ll go ahead and purchase a couple more bulbs to attempt adding multi bulbs support. As for the latency/50-100ms delay from the bulb reacting to the commands, there’s no way to reduce this delay? If there’s no other way then I guess figuring out how to send the audio signals 50-100ms earlier before the signal reaches the speakers may be the solution (if it’s even possible)

Would you mind sharing your code on something like GitHub?