GadgetReactor / pyHS100

Python Library to control TPLink Switch (HS100 / HS110)
Other
409 stars 128 forks source link

Discover not working after period of time #158

Closed ElliotReeve closed 4 years ago

ElliotReeve commented 5 years ago

I am using a raspberry pi to read temperature of the room once an hour. If it’s too cold I turn on the plug which has a heater attached.

The approach I took was to discover the devices first to grab the IP address dynamically then use that to connect to the plug.

However, I have noticed that the discover functionality fails to work after say 6 or so hours.

Any ideas?

kirichkov commented 5 years ago

Have you checked whether your plug is working at all? I had problems with my HS110 simply crashing when the line voltaged dropped. I never figurred out how significant the drop should be for it to crash, but I assume something like 180V (from 220-240V) just make the plug to crash. It's not accessible via the TP-Link either, doesn't respond to pings, etc. Only plugging it out of the socked and plugging it back in fixed it - i.e. restarting it.

I'd suggest whenever this happens next time you try pinging it and report back.

ElliotReeve commented 5 years ago

Yeah so if I run discover I get nothing back.

But if i manually put in the IP that I no the plug is connected to I get the full info.

for dev in Discover.discover().values():
    print(dev)

Returns nothing

plug = SmartPlug("192.168.1.4")
print(plug.get_sysinfo())

Returns

{'sw_ver': '1.5.8 Build 180815 Rel.135935', 'hw_ver': '2.0', 'type': 'IOT.SMARTPLUGSWITCH', 'model': 'HS100(UK)', 'mac': 'AC:84:.......

kirichkov commented 5 years ago

Can you use discover but increasing the timeout and setting it to 10, 20 or even 60? Perhaps your plug is not responding in the 3 seconds allocated for timeout?

You can try sniffing with WireShark whether the plug is responding to the discovery requests - they should be sent from your raspberry to IP 255.255.255.255 port 9999. tcpdump/ngrep will also work.

sylvandb commented 5 years ago

Also consider, does your raspberry pi have two network connections (e.g. ethernet and WiFi)?

Discovery with two network connections needs to use the appropriate network broadcast address, not the global broadcast. The global broadcast is not network specific and will only go out one network, maybe not the correct one.

For example, if you have 192.168.0.X/24 (netmask 255.255.255.0) then a broadcast of 192.168.0.255 will discover on that network. If you also have 172.30.123.45/24 then broadcast 172.30.123.255 to discover.

avanshee commented 5 years ago

Can you use discover but increasing the timeout and setting it to 10, 20 or even 60? Perhaps your plug is not responding in the 3 seconds allocated for timeout?

You can try sniffing with WireShark whether the plug is responding to the discovery requests - they should be sent from your raspberry to IP 255.255.255.255 port 9999. tcpdump/ngrep will also work.

Could specify where this timeout can be changed, I changed it in discover.py but this change is not being reflected

kirichkov commented 5 years ago

Could specify where this timeout can be changed, I changed it in discover.py but this change is not being reflected

E.g. --timeout 60 on the command line.

javed0863 commented 5 years ago

tried increasing the timeout to 30 seconds but still unable to discover the device. But if IP of the device is provided then it works. /opt/pyHS100/pyHS100 # python cli.py --plug --debug discover Discovering devices for 30 seconds DEBUG:pyHS100.discover:Sending discovery to 255.255.255.255:9999 DEBUG:pyHS100.discover:Waiting 30 seconds for responses... DEBUG:pyHS100.discover:Got socket timeout, which is okay. DEBUG:pyHS100.discover:Found 0 devices: {}

usproptrader commented 4 years ago

Python 3.8.1 discover works fine on one win10 and hs100 turns on off ok. On another pc same network,same python etc discover doesnt work. no win defender . Very strange. will try a few more things, add time etc.

rytilahti commented 4 years ago

We are closing this repository for new changes in favor of a new, asyncio-enabled continuation project: https://github.com/python-kasa/python-kasa

If the issue is still present in the new project, please feel free to open an issue there, thanks!