plasticrake / tplink-smarthome-api

TP-Link Smarthome WiFi API
MIT License
1.02k stars 141 forks source link

Search results different per device #105

Closed z571 closed 2 years ago

z571 commented 4 years ago

I ran into an issue with homebridge recently losing connection to a few HS103 plugs, so I did some investigation. I found that the discovery search results are different on different devices.

Here are some results from my homebridge on a Raspberry Pi Zero W running homebridge-raspbian.

pi@homebridge:/usr/local/lib/node_modules $ tplink-smarthome-api search
Searching...
startDiscovery({
  discoveryInterval: 2000,
  discoveryTimeout: 10000,
  breakoutChildren: true
})
HS103(US) plug IOT.SMARTPLUGSWITCH 192.168.0.36 9999 1C3BF385AEFA 80066E89071D6ACEB62D7A1B610047751CC77C6F Raspberry Pi
HS103(US) plug IOT.SMARTPLUGSWITCH 192.168.0.15 9999 1C3BF385AB62 8006DA88FD800EEBD2CED9550DC2B4DA1CC7EB4B Amplifier

And running the same command on my Macbook Pro:

○ → tplink-smarthome-api search
Searching...
startDiscovery({ discoveryInterval: 2000,
  discoveryTimeout: 10000,
  breakoutChildren: true })
HS103(US) plug IOT.SMARTPLUGSWITCH 192.168.0.36 9999 1C3BF385AEFA 80066E89071D6ACEB62D7A1B610047751CC77C6F Raspberry Pi
HS103(US) plug IOT.SMARTPLUGSWITCH 192.168.0.15 9999 1C3BF385AB62 8006DA88FD800EEBD2CED9550DC2B4DA1CC7EB4B Amplifier
HS103(US) plug IOT.SMARTPLUGSWITCH 192.168.0.34 9999 D847321AE79F 80060165615462190D5031815BAB05C61D040A38 Floor lamp
HS103(US) plug IOT.SMARTPLUGSWITCH 192.168.0.14 9999 D847321B36D0 8006D388B1CCB8E812ECF700D1C059A01D04A9BA Spot lamp
HS103(US) plug IOT.SMARTPLUGSWITCH 192.168.0.32 9999 D847321B0B39 8006D2CCDED87D74DA69FA4B97C9C24D1D0479EE Hanging Lamp

And again the same on an older iMac I have at home:

○ → tplink-smarthome-api search
Searching...
startDiscovery({ discoveryInterval: 2000,
  discoveryTimeout: 10000,
  breakoutChildren: true })
HS103(US) plug IOT.SMARTPLUGSWITCH 192.168.0.36 9999 1C3BF385AEFA 80066E89071D6ACEB62D7A1B610047751CC77C6F Raspberry Pi
HS103(US) plug IOT.SMARTPLUGSWITCH 192.168.0.15 9999 1C3BF385AB62 8006DA88FD800EEBD2CED9550DC2B4DA1CC7EB4B Amplifier
HS103(US) plug IOT.SMARTPLUGSWITCH 192.168.0.34 9999 D847321AE79F 80060165615462190D5031815BAB05C61D040A38 Floor lamp
HS103(US) plug IOT.SMARTPLUGSWITCH 192.168.0.14 9999 D847321B36D0 8006D388B1CCB8E812ECF700D1C059A01D04A9BA Spot lamp
HS103(US) plug IOT.SMARTPLUGSWITCH 192.168.0.32 9999 D847321B0B39 8006D2CCDED87D74DA69FA4B97C9C24D1D0479EE Hanging Lamp

I did some preliminary troubleshooting like factory reseting all the devices, restarting the router and unplugging the rPi and the amp plug switches, removing them from my network but the homebridge OS never sees the lamps anymore. Another search on the homebridge returned an empty result, while the other devices still showed the lamps. The only apparent difference is the sendDiscovery happens on a different port.

plasticrake commented 3 years ago

Hi @z571, Can you see if the new v3.1.0 version of tplink-smarthome-api still has this issue? The discovery process was changed as it was causing certain devices to reset when they received the discovery command. Not sure if it would help in your case. Also a new option has been added to the CLI, --broadcast, you can override the default address of '255.255.255.255' with one more specific to your network. For example: tplink-smarthome-api search --broadcast 192.168.0.255

If a more specific broadcast address works for you, you can set the configuration option in the homebridge plugin.

The discovery process sends out a command via UDP Broadcast and waits for responses from the devices. The issue could be a firewire rule on your router/switch or local device (although it would be odd that only some work if this was the cause), also some users have said rebooting their router or changing some router settings fixes their issues.