Closed MarcGodard closed 6 years ago
I tried the createDevice()
method for 2 LIFX bulbs as follows:
const Lifx = require('node-lifx-lan');
let dev1 = null;
let dev2 = null;
Lifx.createDevice({
mac: 'D0:73:D5:25:36:B0',
ip: '192.168.11.32'
}).then((dev) => {
dev1 = dev;
return Lifx.createDevice({
mac: 'D0:73:D5:25:A7:28',
ip: '192.168.11.40'
});
}).then((dev) => {
dev2 = dev;
// Turn on the 1st bulb
return dev1.turnOn({
color: { css: 'red' }
});
}).then(() => {
// Turn on the 2nd bulb
return dev2.turnOn({
color: { css: 'yellow' }
});
}).then(() => {
console.log('Done!');
}).catch((error) => {
console.error(error);
});
The code above works well. Is the code showing what you want to do?
I am using feathersJS, so they aren't in the same chain. That is the problem. I found a workaround that was easy enough without sacrificing anything major.
For chaining it works great, just not for multi-threads.
Feel free to close this if you don't intend on adding something for multi-threads.
Thank you for letting me know your situation. That's good.
So when I now use the createDevice more than one at a time...
So what my app does is scan my network, get all ip and mac addresses of all devices, then does mac look ups to know what device is what, then confirms that by connecting to them. (I have many smart devices and building a central script to control them all)
The problem is is that I have 2 lifx lights (and will be getting more). So it calls one after the other (as it discovers the IP / Mac / Company) so therefore, crashes because there is already an instance confirming the first one.
The solution I have seen for this before is using a different output port for each connection. Not sure if that would work for this.
I can rejig my app to discover using the other way of discovering and only caring of the first lifx device for now (but will return an incomplete list this way), however, a flag to know if there is already an instance, or maybe use a random open out port will work?
Sorry for the long post.