Proper method to call a URL

Hi There,

I am trying to call a URL from my SmartApp, i made an event on WemoManager and its external URL is as such

xxxx.ddns.net:4030/event/fanon

I tried both methods,
//1
def params = [
uri: “http://xxxx.ddns.net:4030”,

path: "/event/fanoff"

]

try {
httpGet(params) { resp ->
resp.headers.each {
log.debug “${it.name} : ${it.value}”
}
log.debug "response contentType: ${resp.contentType}"
log.debug “response data: ${resp.data}”
}
} catch (e) {
log.error “something went wrong: $e”
}

//2

def result = new physicalgraph.device.HubAction(
method: “GET”,
path: “/event/fanoff”,
headers: [
HOST: “xxxx.ddns.net:4030”,

]

)
sendHubCommand(result)

The 2nd one seems to be able to connect

//Result on log

55f6d304-15f5-46ed-bddb-2f7c8e1dad91 10:08:11 PM: debug Executing GET /event/fanoff HTTP/1.1
Accept: /
User-Agent: Linux UPnP/1.0 SmartThings
HOST: xxxx.ddns.net:4030
ACCEPT: text/html,application/xhtml+xml,application/xml;q=0.9,/;q=0.8
CONNECTION: keep-alive
requestContentType: application/json

But it still does not send a signal to my switch…

Any help would be great

1 Like

You’re doing a GET, which means you’re doing the same thing as visiting the URL in a web browser.

The 1st one does the request from the cloud (ie, from the ST service “outside” your home network. For that to work the URL you give it must be accessible from the internet - so a firewall might be blocking it if its running on your local network.

The 2nd one does the request from your ST hub, INSIDE your network - so it works to access stuff on your local network which might otherwise be blocked by a firewall.

My guess is, since the 2nd one worked, your firewall is blocking port 4030, or otherwise not doing port forwarding to the local device. As to why it doesn’t turn on/off the thing, my other guess is that the device is looking for you to POST or PUT some data to it, not GET the url. Try hitting the URL in a browser on your local machine to see what it gives you back?

2 Likes