Use the HubAction with the IP:Port as a HOST parameter and make sure the hub action is returned from your command method:
def myCommand() {
def result = new physicalgraph.device.HubAction(
method: "GET",
path: "/yourpath?param1=value1¶m2=value2",
headers: [
HOST: "192.168.1.10:80"
]
)
return result
}
In order to handle responses in a device, you’ll need the DNI
(device network ID) of your device in SmartThings set to either the IP:PORT in hex or the MAC address of the target device and the response will show up in parse()
. If you want to see the responses in a SmartApp, you’ll have to subscribe to the location
and handle the response yourself.
There’s some work being done on adding callbacks to hubaction… this isn’t officially documented yet, but you can see an example of it in some of the official device types in the SmartThings GitHub repo:
sendHubCommand(new physicalgraph.device.HubAction("""GET /setup.xml HTTP/1.1
HOST: ${deviceNetworkId}
""", physicalgraph.device.Protocol.LAN, "${deviceNetworkId}", [callback: "setupHandler"]))
void setupHandler(hubResponse) {
String contentType = hubResponse?.headers['Content-Type']
if (contentType != null && contentType == 'text/xml') {
def body = hubResponse.xml
def wemoDevices = []
String deviceType = body?.device?.deviceType?.text() ?: ""
...