sendHubCommand and POST?

I have been successful sending local GET requests with the following:

def ip = “10.0.0.12:8080"
def pathorparams = “?doSomethingLikeThis"
def deviceNetworkId = “1234"
sendHubCommand(new physicalgraph.device.HubAction(””“GET /$pathorparams HTTP/1.1\r\nHOST: $ip\r\n\r\n””", physicalgraph.device.Protocol.LAN, “${deviceNetworkId}”))

But for the life of me I am unable to work out the structure for a POST. Would the experts at large shine a little light on this for us.

I’ve very curious about this as well, what GET requests have you been able to get replies back from?

Honestly, I don’t care about the response. I am sending GET requests to HAM Bridge to execute commands from it, but I have other devices that require POST and PUT. I suppose I can have HAM Bridge do those, and trigger them with a GET; I was just hoping to eliminate the extra hop.

how does the code written in my smartthings account will work with my smartthings sensors and hub???which is the triggering point???please reply me as early as possible???

@KATTI - I would encourage your to check out the following resources in the SmartThings Documentation:

An Introduction to the IDE
http://docs.smartthings.com/en/latest/introduction/introduction-to-the-ide/what-is-the-ide.html

Building Your First SmartApp
http://docs.smartthings.com/en/latest/introduction/introduction-to-the-ide/building-your-first-smartapp.html

And a general overview of SmartApps
http://docs.smartthings.com/en/latest/introduction/what-can-developers-do/smartapp-overview.html

If you still have questions, these docs should help you write them up in a way that helps the community to help you. Failing that, you can always contact support@smartthings.com

Thanks

Still struggling with this and would really appreciate some guidance. Is there something borked with sending a POST from sendHubCommand? Or just something odd about it I should know?

When sending from curl:

curl --data "mode=1&fan=0&heattemp=50&cooltemp=85" http://10.0.0.31/control

My Venstar ColorTouch turns on (heat mode=1).

But when I execute:

def postHTTP() {
def body = """mode=${settings.mode}&fan=${settings.fan}&heattemp=${settings.heattemp}&cooltemp=${settings.cooltemp}"""
def length = body.getBytes().size().toString()
def venstar = "${settings.server}"
sendHubCommand(new physicalgraph.device.HubAction("""POST /control HTTP/1.1
HOST: ${venstar}
Content-Length: ${length}
Content-Type: application/x-www-form-urlencoded

${body}
""", physicalgraph.device.Protocol.LAN, "${venstar}"))
}

I get the following in the log, but nothing happens on the thermostat.

8:31:34 AM: debug Executing POST /control HTTP/1.1
HOST: 10.0.0.31
Content-Length: 36
Content-Type: application/x-www-form-urlencoded

mode=1&fan=0&heattemp=50&cooltemp=85
on Home Hub via sendHubCommand

Now if I send the above curl command to another terminal on my LAN I get:

POST /control HTTP/1.1
User-Agent: curl/7.30.0
Host: 10.0.0.12
Accept: */*
Content-Length: 36
Content-Type: application/x-www-form-urlencoded

mode=1&fan=0&heattemp=50&cooltemp=85

And if I direct the sendHubCommand to that terminal I get:

POST /control HTTP/1.1
HOST: 10.0.0.12
Content-Length: 36
Content-Type: application/x-www-form-urlencoded

mode=1&fan=0&heattemp=50&cooltemp=85

I have even gone so far as to include the Accept and User-Agent header fields in the call to sendHubCommand, but nothing has worked when attempting to POST to the thermostat.

Poking at an old thread, I know. @scottinpollock, how far did you get with that Venstar t-stat?

Works like a charm; no auto discovery though. Check it out HERE.

1 Like

Thanks @scottinpollock.

. . . . means you tried but couldn’t get a Service Manager SmartApp to work or didn’t bother to try?

Also, according to the ST docs, it seems like ST intends, in addition to discovery, that a Service Manger SmartApp handle the communication and the Device Handler does the parsing and such. However, it looks like your Device Handler is taking care of the POSTs and GETs (communication). So, I think, that leaves discovery that would be handled by the Service Manager, if there was one.

So, if you don’t mind, and you did try, what problems did you encounter trying to create a Service Manager? Did you find the Venstar API adequate?

Looked at it. Documentation sucked (still does), and no one was willing to help. It works well as it is, and that was all I needed.

BTW, the Venstar API is great, but completely local. Frankly, I use it more (called from HAM Bridge) than the SmartThings integration as I still can’t count on SmartThings to reliably execute critical tasks (in this case preventing pipes from freezing).

@scottinpollock, yea, the docs in this area seem to leave a lot to be desired. Also, unless I’m missing something, there are no ST-published handlers for LAN-connected devices to use as examples.

. . . and, if I haven’t used up my allotment of stupid questions. . . . the Venstar API uses JASON formatting for GETs but the POSTs are URL-encoded. Do you know why that is?

Thanks again!

Nope. My guess is that most usage for control/settings would only be a few name/value pairs versus the info get returns can be far more comprehensive.

I thought that might be the case but I am a relative newb so I was afraid I may be missing some key concept. Thanks again.