I am working on a driver for a Rain Bird sprinkler controller. The controller expects a POST that contains an encrypted "application/octet-stream" payload. It sends a similar payload back. I am starting with a very simple test of sending a request for the controller version to get the plumbing all working correctly. I can successfully send the encrypted message but resp does not seem to come back correctly.
Rather than data in the resp it returns the following - <org.apache.http.conn.EofSensorInputStream@14852be wrappedStream=null selfClosed=true eofWatcher=ResponseEntityProxy{[Content-Type: application/octet-stream,Content-Length: 128,Chunked: false]}>
Unsurprisingly I am not able to pull any usable data out of it. Does anyone have any thoughts on why this is happening? I have a fully working Python application that sends and receives correctly. I am sending the exact same data in both so this seems to be something in the hubitat HttpPost library with how it is receiving the incoming data or I should be catching it some other way than result=resp.data.
Any thoughts???
the code looks like this
def GetVersion() {
request_id = Math.floor((new Date()).getTime()/1000);
//This is the command to get controller version
strSendData = /{"id":$request_id,"jsonrpc":"2.0","method":"tunnelSip","params":{"data":"02","length":1}}/
//encrypt payload with shared password
byte [] baEncryptedSendData = encrypt (strSendData, SprinklerPassword)
if (isDebug) { log.debug "encrypt return = " + baEncryptedSendData.encodeHex().toString() }
def postParams = [
uri: "http://$SprinklerIP/stick",
contentType: "application/octet-stream",
requestContentType: "application/octet-stream",
headers: [
"Accept-Language": "en",
"Accept-Encoding": "gzip, deflate",
"User-Agent": "RainBird/2.0 CFNetwork/811.5.4 Darwin/16.7.0",
"Accept": "*/*",
"Connection": "keep-alive"
],
body : baEncryptedSendData
]
httpPost(postParams) { resp ->
result = resp.data
log.debug "Response Status: ${resp.status}"
log.debug "Received Headers: ${resp.getAllHeaders()}"
log.debug "resp.data read allowed: ${resp.data.isReadAllowed ()}"
log.debug "result : ${result}"
log.debug "result dump: ${result.dump()}"
}
if (isDebug) { log.debug "Return from rainbird controller = " + result.dump() }
}
The log.debug lines above return
2020-06-30 10:25:38.607 am debugReturn from rainbird controller = <org.apache.http.conn.EofSensorInputStream@14852be wrappedStream=null selfClosed=true eofWatcher=ResponseEntityProxy{[Content-Type: application/octet-stream,Content-Length: 128,Chunked: false]}>
app:1652020-06-30 10:25:38.600 am debugresult dump: <org.apache.http.conn.EofSensorInputStream@14852be wrappedStream=null selfClosed=true eofWatcher=ResponseEntityProxy{[Content-Type: application/octet-stream,Content-Length: 128,Chunked: false]}>
app:1652020-06-30 10:25:38.594 am debugresult : n����?��@r����D$���Lj�*�W0�:Y�p\@t�d�2Is'�ڮ��mA���E�v,orв�4Y
p�p��ݺ�F��=vS>���u�Qv_��������ox��.e��=���\
app:1652020-06-30 10:25:38.590 am debugresp.data read allowed: true
app:1652020-06-30 10:25:38.585 am debugReceived Headers: [Connection: Close, Content-type: application/octet-stream, Content-length: 128]