SmartThings with Huginn -- need help with code errors

smartapp

(pcaseiro) #1

Hello,

I’m trying to integrate SmartThings with Huginn, since I have all my other integrations there.

Everytime I try to make a POST to huginn running at my localhost:3000 I get a java.lang.SecurityException (I can’t say what exception it is because my app is not logging anything at the IDE for some reason, and when I open the Notifications->Messages tab at my Android App there are no notifications). I know I’m getting the java.lang.SecurityException because I’m using the sendPush() method to log the errors to my Android.
This is the code
`

def postToHuginn(message){
sendPush(message)

def params = [
	uri: "http://localhost:3000/users/1/web_requests/49/12345",
	//path: "/users/1/web_requests/49/12345",
	contentType: "application/json",
	body: [
    	"interaction[service_id]": service_id,
    	"interaction[note_public]": message,
        "interaction[state]": "closed",
        "interaction[finish_at]": (new Date()).format("yyyy-MM-dd'T'HH:mm:ss.SSSZ"),
        "interaction[responsible_person_ids][]": [state.person_id],
        "interaction[manual_alarm_state]": "ok"
    ]
]
    
try {
    httpPost(params) { resp ->
        // iterate all the headers
        // each header has a name and a value
        resp.headers.each {
           log.debug "${it.name} : ${it.value}"
        }

        // get an array of all headers with the specified key
        def theHeaders = resp.getHeaders("Content-Length")
        
        // get the contentType of the response
        log.debug "response contentType: ${resp.contentType}"

        // get the status code of the response
        log.debug "response status code: ${resp.status}"

        // get the data from the response body
        log.debug "response data: ${resp.data}"
    }
} catch (e) {
    log.error "something went wrong: $e"
    sendPush("$e")
}

}

`
If I use postman with that same URL ou even paste it in my browser, I’m getting the response I was expecting, so I guess it is not a URL problem. I’ve also tried using the path, but no success.
Any tips?


#2

The localhost likely to be the issue, try to put the actual IP.

Localhost usually represent the host server where the code run


(pcaseiro) #3

Well, I’m not getting the error from before, but a new one appeared.

org.apache.http.conn.ConnectTimeoutException… (can’t read the rest, same reason from before…)

edit: off course, how would it be able to connect to my local machine! I’ll just deploy it and it will be ready to go. Thanks