softScheck / tplink-smartplug

TP-Link WiFi SmartPlug Client and Wireshark Dissector
Apache License 2.0
1.14k stars 296 forks source link

UDP + broadcast support #45

Open wowczarek opened 6 years ago

wowczarek commented 6 years ago
wowczarek commented 6 years ago

The TP-Link Kasa app uses broadcast UDP probes to discover devices (the "info" JSON cmd, also on port 9999, all-ones IP address). They reply to the sender via unicast UDP. It turned out that all commands work via UDP unicast (and broadcast), the only difference in terms of the protocol is the lack of the 4-byte padding. The broadcast operation is quite useful - you can for example send "off" to all devices, etc.

Recently (on Android at least) either the Kasa app got "smarter" deliberately to force people to use their cloud solution, or introduced a bug and stopped sending discovery unless you are on wi-fi - which breaks the operation over VPNs and such. So I decided to ditch it as my devices never have nor will they ever be allowed to reach the cloud while on my network.

I am planning some more work e.g. to dump the discovered data into a file where IDs can be mapped to MACs, so you can refer to those rather than IPs - and you can keep the configured device names intact. Or to reconfigure the devices en masse.

tonsmets commented 6 years ago

I used your broadcast functionality and it is a great addition! Since the latest firmware upgrade I was scared I could not use this script anymore but by using UDP/broadcast I can query information from my device!