I know this question has been asked many times before as I have searched the forum for answers to this before posting and found lots of things touching on the subject but not been able to work out my exact issue.
def parse(output) {
log.debug "Starting response parsing on ${output}"
def headers = ""
def parsedHeaders = ""
def msg = output
def headersAsString = msg.header // => headers as a string
def headerMap = msg.headers // => headers as a Map
def body = msg.body // => request body as a string
def status = msg.status // => http status code of the response
def json = msg.json // => any JSON included in response body, as a data structure of lists and maps
def xml = msg.xml // => any XML included in response body, as a document tree structure
def data = msg.data // => either JSON or XML in response body (whichever is specified by content-type header in response)
log.debug "headers: ${headerMap}, status: ${status}, body: ${body}, data: ${data}"
if (status == 200) {
if (body.contains("authentication_token")) {
def authToken = null
body = new groovy.json.JsonSlurper().parseText(body)
log.debug "$body"
authToken = body['authentication_token']
if (authToken != null && authToken != "") {
log.debug "Auth Token: $authToken"
sendEvent(name: "authToken", value: "$authToken")
verify()
}
}
}
else {
log.debug "Unable to locate device on your network"
}
}
It works fine in one device handler and one SmartApp, but I just created a new device handler and copied and pasted it and nothing! It’s doing my head in, as it didn’t work in the SmartApp until I deleted it and rebuilt it from the code.
The hub uses the same code there in order to ping the device as part of a SmartApp before creating it as a device to check it exists.
I’ve copied and pasted the code from the SmartApp to a custom device handler, and now no response. I don’t have the kit to check the network for the packets though.
I have, the log debug events I have posted above is all I get.
It’s like the command is built and either the hub doesn’t send it, doesn’t get a response, or just ignores the response. I don’t know how to check that the send and receive has actually occured without somehow using a MITM setup on the hub.
Just out of curiosity. Are you running the same time the SmartApp and the DH with the same code? Are you sure that you are trying to communicate with the right device?
Sorry back again. I thought it was the Device Network Id which was the issue. Turns out I also set the “Hub” at the same time, and this was truly what solved the issue.
So I have added hub selection to my installer SmartApp, this should solve the problem. I can now gladly say I am talking to my lights.