samuraitruong/yeelight

Commands are not being send using the TCP server set in setMusic()

Opened this issue · 2 comments

As far as I've tested/checked, it seems like the music mode is being correctly set, but using the lib's functions like setRGB() are not being sent through the TCP server.

Is there any workaround for that? Besides writing the raw commands and sending them using my own TCP server. Maybe a function to extract a raw command so we can just use that instead of writing by hand?

It would be nice if the lib could start it's own TCP server for each device and send the commands directly through it, if the device is in music mode.

can you share your code snipet?

@samuraitruong here's a simple test I made using net:
Starting the TCP Server

const server = net.createServer();
server.listen(port, host, () => {
    console.log('TCP Server is running');
});
server.on('connection', function(sock) {
    console.log('CONNECTED: ' + sock.remoteAddress + ':' + sock.remotePort);

    sock.on('data', function(data) {
        console.log('DATA ' + sock.remoteAddress + ': ' + data);
    });
});

Starting the music mode

discover.on("deviceAdded", async (device: IDevice) => {
    console.log(`new yeelight device found: ${device.host}:${device.port}`);
    let yeelight = new Yeelight({
        lightIp: device.host,
        lightPort: device.port
    });

    await yeelight.connect();
    await yeelight.setMusic(1, host, port);
});
discover.start();