tinytuya
tinytuya copied to clipboard
Scanning inside WSL
When using tinytuya inside a WSL (Windows subsystem for Linux) Machine, scanning does not work, as the WSL machine uses a virtual network that has a different IP range than the host windows machine, due to this, having a possibility to manually set the ip range to scan, or to manually define the IP of devices, would be useful
Hi @amahlaka , thanks for opening this issue!
Two things:
-
If you are talking about using
python -m tinytuya scan
, the scanning term is actually a bit misleading, in reality it is just "listening" for UDP broadcast packets on your network. Tuya devices emit a discovery broadcast via UDP. The code in the 'scanner' opens up UDP ports 6666 and 6667 for listening on 0.0.0.0 (all interfaces) on your host to hear those discovery packets. If that is not working in WSL, that means there is something blocking UDP protocol packets coming in to the VM. -
There is an optional
python -m tinytuya scan -force
command that attempts to also scan your network block for TCP port 6668 being open (a Tuya device) and builds a map of those IP/mac addresses to test. You are correct that for-force
TinyTuya assumes just a local network and the WSL is giving it the wrong netblock. That could be a feature addition to prompt the user for the netblock before continuing. If this is what you are raising, and you are interested in helping with the code to do that, take a look at this code block and feel free to submit a Pull Request (otherwise I'll add this to my TODO): https://github.com/jasonacox/tinytuya/blob/3f17b13ab75c349fdaac991b9d31831419374d7f/tinytuya/scanner.py#L185-L227