LAN sendHubCommand in Drivers

I have a SmartThings DTH that controls a LAN device I’m trying to get ported over to a Hubitat Driver.

This is the original code section on ST:

def result = new physicalgraph.device.HubAction(
method: "GET",
path: "/?cmd=" + cmd,
headers: [
    HOST: settings.ipAddress // Formatted as hostname:port

I originally tried a few different methods of creating the HubAction object before finding a thread here that it’s not supported in Drivers.

Next thing I tried was using httpGet with the following code:

def params = [
    uri: "http://${settings.ipAddress}",  // Formatted as hostname:port
    path: "/?cmd=${cmd}"
    log.debug "params: ${params}"

try {
    httpGet(params) { resp ->
        resp.headers.each {
        log.debug "Response: ${} : ${it.value}"
    log.debug "response contentType: ${resp.contentType}"
    log.debug "response data: ${}"
} catch (e) {
    log.error "something went wrong: $e"

I get the following logs:

dev:4 2018-03-01 16:28:45.894:debugresponse data: Bad Request
dev:4 2018-03-01 16:28:45.892:debugresponse contentType: text/html
dev:4 2018-03-01 16:28:45.890:debugResponse: Content-Length : 11
dev:4 2018-03-01 16:28:45.887:debugResponse: Connection : keep-alive
dev:4 2018-03-01 16:28:45.885:debugResponse: Date : Thu, 1 Mar 2018 16:28:46 GMT
dev:4 2018-03-01 16:28:45.882:debugResponse: Content-Type : text/html

I don’t have access to the services on the device to see the incoming request but I’m assuming either httpGet doesn’t work locally or the path parameters are not being sent correctly.

Any info available on getting local connections working in Drivers or is there a different way to go about this?


httpGet has no restrictions on working locally. However it does expect a proper html response. You can try using something like PostMan to do the same request and see what is coming back.

1 Like

Thanks for confirming that. I just tested with PostMan as was able to reproduce the bad request response by leaving the path parameters out. Looks like I was using the params map incorrectly by putting the query parameters in the path. I moved them to the query map and I’m getting the proper response now. I also tried putting it all in the URI and that also worked but definitely not the proper implementation.

Here’s what I ended up with

def params = [
    uri: "http://${settings.ipAddress}/",
    query: [ cmd : "${cmd}" ]