jasonacox / powermonitor

Monitor power usage through WiFi Smart Plug
MIT License
63 stars 7 forks source link

did not work on Gosung SP1 v2.4 #3

Open corgan2222 opened 5 years ago

corgan2222 commented 5 years ago

after the first run with docker i got this messages:

9b5ca1b7ed17: Pull complete Digest: sha256:a9c34fdb540a2d042197028cf3886123b7cc5e517359f4f6844b7275d78e122c Status: Downloaded newer image for jasonacox/powermonitor:latest ERROR:pytuya:Unexpected status() payload=b'3.3\x00\x00\x00\x00\x00\x00\x00\x0f\x00\x00\x00\x01\x19\xf9\xa2\x17%\xe6\xfek\xe8v-\x11\x86\x04@\xb5K\x866\x19\x97Oce\x8b+x\x88\xd6\x187\x8cI\xa7\x15(\x86/\xd0L\xc54\xf8\x92N+#z\xdf2V\xfea\xb4\x82n\x9f"\xea%\xc4\xd6\x89\x1din8\xfb\x8d\x0b\x92G\x93\xb3\xadq\x1f\xa3\x11l' ERROR:pytuya:Unexpected status() payload=b'3.3\x00\x00\x00\x00\x00\x00\x00\x10\x00\x00\x00\x01\x19\xf9\xa2\x17%\xe6\xfek\xe8v-\x11\x86\x04@\xb5K\x866\x19\x97Oce\x8b+x\x88\xd6\x187\x8c>(\x97\xf7\xbb1\x9d\x81\xb8\x96\xafb\xc7[\xec\xca3\x1a\xd2\xadN\xbe\xbf\x82\xf5\xfc-\xc4\x1a\xa1\xc1\x1fin8\xfb\x8d\x0b\x92G\x93\xb3\xadq\x1f\xa3\x11l' Polling Device 60020372840d8e6fa9d2 at 192.168.2.38 Dictionary b'3.3\x00\x00\x00\x00\x00\x00\x00\x0f\x00\x00\x00\x01\x19\xf9\xa2\x17%\xe6\xfek\xe8v-\x11\x86\x04@\xb5K\x866\x19\x97Oce\x8b+x\x88\xd6\x187\x8cI\xa7\x15(\x86/\xd0L\xc54\xf8\x92N+#z\xdf2V\xfea\xb4\x82n\x9f"\xea%\xc4\xd6\x89\x1din8\xfb\x8d\x0b\x92G\x93\xb3\xadq\x1f\xa3\x11l' Dictionary b'3.3\x00\x00\x00\x00\x00\x00\x00\x10\x00\x00\x00\x01\x19\xf9\xa2\x17%\xe6\xfek\xe8v-\x11\x86\x04@\xb5K\x866\x19\x97Oce\x8b+x\x88\xd6\x187\x8c>(\x97\xf7\xbb1\x9d\x81\xb8\x96\xafb\xc7[\xec\xca3\x1a\xd2\xadN\xbe\xbf\x82\xf5\xfc-\xc4\x1a\xa1\xc1\x1fin8\xfb\x8d\x0b\x92G\x93\xb3\xadq\x1f\xa3\x11l' ERROR: No response from plug 60020372840d8e6fa9d2 [192.168.2.38].

after that, i got no message from the script. testet on a synology docker and a raspi4 in python. greetz Stefan Gosung SP1 v2.4 https://github.com/arendst/Sonoff-Tasmota/issues/5323

jasonacox commented 5 years ago

This is interesting. The plug is responding, but it is sending back a binary string. Either the encryption is failing or the plug is not compatible. The payload we get back from pytuya should look something like this:

Dictionary {u'devId': u'031401333c4f2116ff61', u'dps': {u'1': True, u'2': 0, u'5': 12, u'4': 70, u'6': 1220}}

To verify that it is not the config, can you try running the script manually (not docker) and on a MacOS or Linux host?

jasonacox commented 5 years ago

I updated the pytuya library to the latest version and also added PLUGKEY as a user defined environmental value if you need to change it. I recommend pulling the latest and trying again. Please let me know your result.

codeclinic commented 4 years ago

@jasonacox I have 3 different types of Tuya sockets. 2 Of them work without issue with this library, however the Gosund SP1 's do not. I've done a port scan and it shows that port 6668 is open, however if I try connecting via telnet I get the following:

pi@hassbian:~ $ telnet 192.168.178.91 6668 Trying 192.168.178.91... Connected to 192.168.178.91. Escape character is '^]'. Connection closed by foreign host.

Likewise, powermonitor returns the following: {"result": "ERROR: No response from plug 533xxxxxxxxxxxxxxxx [192.168.178.91]."}

Under the update firmware section of Tuya I see that these Gosund SP1 devices have: Wi-Fi Module: 1.0.6 MCU Module: 1.0.6

wheras my other devices have : Wi-Fi Module: 1.0.2 MCU Module: 1.0.2

Perhaps there have been some changes with these newer models?

codeclinic commented 4 years ago

@jasonacox I don't know if this is of any help since I don't know exactly what your library does to extend Tuyapi but it seems that the ports and encryption on newer firmware is different to earlier firmware versions: https://github.com/codetheweb/tuyapi/issues/175

I had a look on wireshark and it does appear that these 2 devices on firmware 1.0.6 do do some outbound communication on port 6667. Not sure if that is of any help though.

codeclinic commented 4 years ago

I grabbed a copy of your latest files and now get a message about there being no handlers for tuyapi. And after a bit more looking it seems that these SP1 devices require the key to be input into your script inorder to connect/decode the connection. My other devices didn't need this key.

I'm hoping to find the keys and have this working. I'll report back once I've got some news either way.

codeclinic commented 4 years ago

Hmm, even with the keys I'm getting:

$ powermonitor/plugjson.py 53365xxxxxxxxxx15aac 192.168.xxx.xxx 201ac714xxxxxxxx
No handlers could be found for logger "pytuya"
{"result": "ERROR: No response from plug 53365xxxxxxxxxx15aac [192.168.xxx.xxx]."}

Any suggestions?

codeclinic commented 4 years ago

I'm now able to get some random looking output (similar to @corgan222) before the "result":error bit. Every line of the output starts with 3.3 which makes me think that these Gosund devices are usin protocol 3.3 as mentioned here:

https://github.com/codetheweb/tuyapi

Newer firmware may use protocol 3.3. If you are not using find(), you will need to manually pass version: 3.3 to the constructor.

Any idea what could be done to test this with powermonitor?

Thanks.

codeclinic commented 4 years ago

Ok, so this device uses the v3.3 protocol. It needs the device key to connect with the device, and then to decode the encrypted output. However, this library doesn't have a way to handle the v3.3 protocol -although pytuya can handle it.

I've rewritten some big chunks of powermonitor and added that to my forked version. I'll submit a pull request in the next day or two. In the meantime @corgan2222 feel free to use my fork: https://github.com/codeclinic/powermonitor

jasonacox commented 4 years ago

This is great! Yes, please add a contributor note for yourself in README and submit a PR. Thanks @corgan2222

codeclinic commented 4 years ago

@corgan2222 If possible could you test my fork with your devices. It's working great with my Gosund SP-1's but it'd be good to know it works for others too. Thanks.

codeclinic commented 4 years ago

@jasonacox I've sent the pull request with my changes. Let us know how you get on @corgan2222

corgan2222 commented 4 years ago

hey and thanxs for the efforts! Its been some time and since then i flashed my gosund the oldscool way. Actually i dont have a fresh gosund atm, but i have an uncracked sonoff pow r2. Should this work too? https://www.amazon.de/Verbesserte-Pow-Verbrauch-Fernbedienung-Messschalter-Kompatibel/dp/B07C5P7NPQ Anmerkung 2019-10-08 183525

codeclinic commented 4 years ago

As far as I am aware the underlying PyTuya is purely for Tuya/Smartlife/Jinvoo devices