MariusRumpf / node-lifx

Node.js implementation of the LIFX LAN protocol :bulb:
MIT License
144 stars 28 forks source link

Lights no longer controllable after IP address change? #36

Closed sinnottj closed 7 years ago

sinnottj commented 8 years ago

Hi,

I've been observing an issue over the last few days were if a light is powered off for sufficient time that it loses its IP address, once it is powered on again it is no longer controllable by node-lifx.

Specifically:

1) A light is initially discovered, and can be controlled via node-lifx 2) The light is powered off for a significant period of time (long enough to lose its IP address) 3) The light is powered on again and is issued a new IP address 4) The light is rediscovered by node-lifx. However, the light is no longer controllable

I can recreate this issue using the interactive_cli.js test program.

Regards,

James.

MariusRumpf commented 8 years ago

Shoul be fixed with d6d66df

sinnottj commented 8 years ago

Hi,

I've finally had a chance to test this out and unfortunately it doesn't quite fix the problem - bulbs still become inaccessible when their IP address changes.

Having taken a look at the code, I think it's because the internal record of the bulb's IP address isn't being updated.

I tried tweaking the processDiscoveryPacket method in client.js so that, in the case of an already discovered light, it updates the device address:

  this.emit('light-new', lightDevice);
} else {
  this.devices[msg.target].address = rinfo.address;
  if (this.devices[msg.target].status === 'off') {
    this.devices[msg.target].status = 'on';
    this.emit('bulb-online', this.devices[msg.target]); // deprecated
    this.emit('light-online', this.devices[msg.target]);
  }

This change seems to have solved the issue for me.

Regards,

James.

MariusRumpf commented 8 years ago

Thanks for your help, I added that in commit ec2d8ed.

sinnottj commented 8 years ago

I've been running the development branch for 5 days and everything is working perfectly. I haven't lost access to any of my lights.

I think it's fixed!

MariusRumpf commented 7 years ago

The fix was release in v0.7.0.