tinytuya icon indicating copy to clipboard operation
tinytuya copied to clipboard

Scanning inside WSL

Open amahlaka opened this issue 2 years ago • 1 comments

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

amahlaka avatar Jul 09 '22 17:07 amahlaka

Hi @amahlaka , thanks for opening this issue!

Two things:

  1. 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.

  2. 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

jasonacox avatar Jul 09 '22 18:07 jasonacox