I am completely new to Smartthings, picked one up yesterday and immediately wanted to get my hands dirty. I have a few Lenovo smart plugs which are incompatible with SmartThings so that seemed like a good place to start.
I sniffed the packets sent between my phone and the Lenovo app and pretty soon I had CURL requests which could turn the plug on and off.
I could not post the CURL requests as "new users can only create posts with two links in them. But happy to share
After a bit of searching I found some examples of device handlers and thought I’d give it a go. I created a handler and am attempting to run the HTTP POST, the code runs in the simulator, but I never get a response back from the API. Which, I’m guessing means I have not successfully sent the request.
Perhaps I am doing something wrong. I can code in C# and make sense of most C based languages but I’ve never really used Java or Groovy.
Here is the code I am having trouble with (I’ve tried this many different ways and a fair bit of googling but so far cannot figure this one out).
def cmdStr = new physicalgraph.device.HubAction([
method: "POST", path: "https://a1.tuyaeu.com/api.json?appVersion=1.0.8&appRnVersion=5.16&channel=oem&sign=aeba6e2099943efabbfeb755ceb4c1bcb98ca97f029dd2b0cb1d481682261867&lon=151.34221&deviceId=45a6e73f040d9e5b12f98a7a3c62c9dc4a7ad242a036&platform=Pixel%25204%2520XL&sid=eu158183N26952181nPeWpi331d46bfb56a27534421f684dea448741&requestId=9559c792-dc1d-4912-bb0b-1ba83a8cecc1&lang=en&lat=-33.4315803&a=tuya.m.device.dp.publish&clientId=7cpsrpqaundffdfedrhedrosSystem=10&os=Android&timeZoneId=Botswana%252FArctic&ttid=sdk_tuya%25407cpsrpqaundffdfedrhedret=0.0.1&v=1.0&sdkVersion=3.12.0&time=1582370580", body: "postData=%7B%22devId%22%3A%222800434484f3ebc1b3af%22%2C%22dps%22%3A%22%7B%5C%221%5C%22%3Afalse%7D%22%2C%22gwId%22%3A%222800434484f3ebc1b3af%22%7D", headers: ["HOST": "a1.tuyaeu.com", "User-Agent":"TY-UA=APP/Android/1.0.8/SDK/null", "Content-Type":"application/x-www-form-urlencoded", "Content-Length":"145", "Connection":"Keep-Alive", "Accept-Encoding":"gzip" ]] ) //Send the command to the Hub def CmdResponse = sendHubCommand(cmdStr) log.debug cmdStr **// I see this** log.debug CmdResponse **//There is never a response from the server here.**
I’ve tried (among other things) removing the hostname from the path but that seems to get me in the same situation