Because raw socket hubactions won’t actually return results, I’ve started writing a http based middle layer. I can’t figure out how actually retrieve the response. I thought it should come back in the parse() function but as far as I can tell its not being called.
I’ve tried both methods of HubAction
def poll() {
def pollAction = new physicalgraph.device.HubAction(
method: "POST",
body: body
path: "/send/<ip>/10002?timeout=1001",
headers: [HOST: "<ip>:54231", 'Content-type': 'application/json']
)
pollaction
}
and
def poll() {
def pollAction = new physicalgraph.device.HubAction("""POST /send/<ip>/10002?timeout=1002 HTTP/1.1\r\nContent-Length: ${bodyLength}\r\nContent-type: application/json\r\nHOST: <ip>:54231\r\n\r\n${body}\r\n""", physicalgraph.device.Protocol.LAN, "${deviceNetworkId}")
pollAction
}
Looking at a network dump (using ngrep)
POST /send/<ip>/10002?timeout=1002
HTTP/1.1
Content-Length: 40
Content-type: application/json
HOST: <ip>:54231
["<username>\r", "<password>\r", "POWR? \r"]..
Response:
HTTP/1.1 200 OK
X-Powered-By: Express
Content-Type: application/json; charset=utf-8
Content-Length: 43
X-Response-Time: 1005.299ms
Date: Thu, 18 Sep 2014 04:32:28 GMT
Connection: keep-alive
["Login:","\r\nPassword:","\r\n1\r","\r\n"]