Add "local_ip_address" option when discovering devices #2
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This update added a "local_ip_address" option just as in the python-broadlink api . This option is quite useful if multiple network interfaces exist and the one connecting to the target device is not the first. Also node's os.networkInterfaces cannot find all interfaces in some cases where providing a binding address may become a must (issue nodejs/node#498).
Use/test case with homebridge-broadlink-platform:
My raspberry pi connected to a router via eth0 along with my iphone. The raspberry pi also has a wireless interface wlan0 which I set as an AP. The network on eth0 has ip 192.168.0.10 and the network on wlan0 has ip 192.168.42.1. An SP1 device connected to wlan0.
Now if without the "local_ip_address" option, when sending the broadcast message to 255.255.255.255, the packet will be sent through only one (random) interface (see https://stackoverflow.com/questions/683624/udp-broadcast-on-all-interfaces) and perhaps under the network 192.168.0. Thus , it will not reach my SP1. By this update we can provide local_ip_address as 192.168.42.1 to solve the problem.
To achieve the above the homebridge-broadlink-platform package also has to be updated. I will submitted a pull request there: smka/homebridge-broadlink-platform#9.
Changes
This update only add a conditional branch. Otherwise the only change is that the socket is bound to the calculated address instead of the default (0.0.0.0), which is a rational change in my opinion.