codetheweb / tuyapi

🌧 An easy-to-use API for devices that use Tuya's cloud services. Documentation: https://codetheweb.github.io/tuyapi.
MIT License
2.05k stars 337 forks source link

Prefix / Suffix from requests.json #4

Closed stecooper closed 6 years ago

stecooper commented 6 years ago

Hi,

In requests.json how did you find the prefix and suffix for status, on and off?

I can use your sample code to get the status of my Smart Plug without any issues and can switch on but not off. From a plug switched off to on I do get an error but it does come on:

Status: false
Result of setting status to true: true
SyntaxError: Unexpected end of JSON input
    at JSON.parse (<anonymous>)
    at _send (/home/pi/node_modules/tuyapi/index.js:62:21)
    at Socket.client.on.data (/home/pi/node_modules/tuyapi/index.js:137:14)
    at emitOne (events.js:115:13)
    at Socket.emit (events.js:210:7)
    at addChunk (_stream_readable.js:250:12)
    at readableAddChunk (_stream_readable.js:237:11)
    at Socket.Readable.push (_stream_readable.js:195:10)
    at TCP.onread (net.js:586:20)

But then I try to turn off again

Status: true
{ Error: read ECONNRESET
    at exports._errnoException (util.js:1026:11)
    at TCP.onread (net.js:607:25) code: 'ECONNRESET', errno: 'ECONNRESET', syscall: 'read' }

Could the suffix / prefix be my issue? My Smart Plug is a UK version, not sure if that could be the issue (https://www.amazon.co.uk/Wireless-Switch-Function-Android-Devices/dp/B071SDNGW2/ref=sr_1_3?ie=UTF8&qid=1510959884&sr=8-3&keywords=smart+plug)?

Thanks

codetheweb commented 6 years ago

@stecooper huh. Are you able to sniff the traffic between your phone and device with Wireshark and send the PCAP file to me?

stecooper commented 6 years ago

@codetheweb Thanks for the reply, is there connectivity between the phone and the device directly or does it go via the remote server API? I'm on Android btw and I have tried on bluestacks on Windows with Wireshark running at the same time but while I can see broadcast packets from the device, I can't see any communication from the PC IP with Bluestacks running the app (https://play.google.com/store/apps/details?id=com.efamily.cloud) and the device itself.

codetheweb commented 6 years ago

Ok. I'm not sure how packet sniffing an emulator works, so I'm sorry but I can't help you out there.

The Tuya app turns on/off the device locally, then sends the status of it to a remote server.

If you are able at some point to sniff the traffic with Wireshark, please send it to me and I'll see what I can do.