jangxx / node-magichome

An incomplete implementation of the functionality of the "Magic Home" app. Partially a port of https://github.com/Danielhiversen/flux_led to Node.js
ISC License
124 stars 26 forks source link

Scanning does not work #15

Closed martynaskre closed 5 years ago

martynaskre commented 5 years ago

I have a Magic Home led controller, but scanning does not work. If I specify correct IP address I can control LEDs with this package, but scanning somehow does not work.

jangxx commented 5 years ago

The scanning works by sending a broadcast packet to all devices in your network, which causes the controllers to send an answer back to you. Sometimes this broadcast packet gets lost or the answer arrives too late (default timeout is 500ms), so you could either try the discovery multiple times or increase the timeout or both.

I think if you're running on Windows, there might also be some problems sending UDP broadcasts in some cases, but since I don't use Windows, I can't help you with that.

martynaskre commented 5 years ago

Yea, scanning works on MacOS. I'll check whats wrong on Windows and maybe I'll create some sort of fix.

jangxx commented 5 years ago

You may take a look at this issue and the linked ServerFault thread. Apparently you can't send an UDP packet on the 255.255.255.255 broadcast address on windows.

You probably have to do some workaround, by working with the output of os.networkInterfaces() and replacing the last bytes of the IP addresses or something. If you want to write an OS-specific workaround feel free to send a PR, but I would personally consider this low-priority or even a non-issue, since it's just Windows being Windows. Simply running node in the WSL might even fix your problem on Windows without writing any additional code.

martynaskre commented 5 years ago

17

jangxx commented 5 years ago

I implemented a fix in the new_features branch. Please check if the discovery works now, in which case I would merge it into the master branch and release it.

martynaskre commented 5 years ago

Everything works now. Nice 👍