Device Handler POST to local network service

Trying to write a device handler to integration with local network service. I have been beating my head trying to get a local http call to work, but so far nothing. My command method is getting called, and I am returning a HubAction from the method, but the http request is never made. I know my service is up and I can make a curl request and get the expected response.

Here is the code that creates and returns the HubAction, my DNI is set to the hex version of the IP:PORT I have also tried the mac, so far nothing has worked.

def httpPostJSON(path) {
  def hostUri = "192.168.0.2:3000"
  log.debug "Sending command ${path} to ${hostUri} + ${id}"
  def result = new physicalgraph.device.HubAction(
        method: "POST",
        path: path,
        headers: [
                HOST: hostUri,
                Accept: "*/*"
        ],
        null,
        [callback: callbackList] 
  )
   log.debug "Request: ${result.requestId}"
   log.debug "${result}"
  return result
}

are you calling sendHubCommand(result)

I’m not calling sendHubCommnand currently, although I have tried it.

Reading the documentation it appears that is only valid for SmartApps and not device handlers, but I have tried that as well.

I can confirm it works in both but you need to call that for it to work

Does live logging show any errors?

I don’t see any errors in the logging, I can see my command method getting called when I put logging that method. I don’t see any logging after that.

Can anyone confirm if I should use the hexed ip:port or mac address for DNI?

Hmm, I think i may have found the issue. The service I am trying to hit is on another subnet within my network, but accessible. If I start the service within the same subnet then it works as expected, so i’m guessing Smartthings is not sending the request to devices not on the same subnet.

That was definitely the issue. It appears Smartthings cannot send a local network request to another subnet.
I setup a raspberry pi to run my service and put it on the same network and it works great.

So many small unknowns in the platform.

I tinker with my hub off and on, so maybe this has been answered, but is any of the Smarthings code or ecosystem open to contribute to, even documentation to help improve this vs. scouring forum posts?

The current ones are on github, though not sure if its actively being developed because the new platform docs can be found here: https://smartthings.developer.samsung.com/develop/whats-new.html

@Jim would know best about if a) we’re still taking MRs for our Groovy docs and b) if the new ones will be open source as well.

1 Like