UDP + broadcast support
- Support for broadcast (discovering all devices and mass commands)
- Support for UDP communication (works just as well as TCP, minus UDP being UDP)
- Configurable UDP timeout, and source address (for both TCP and UDP)
- Only json output sent to stdout, rest to stderr, to get clean json for scripting etc.
- Readme.md updated accordingly, added my name to Python source, hope you don't mind
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.
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!