# Using HubAction to connect to a URL on the LAN?

**URL:** <https://community.smartthings.com/t/using-hubaction-to-connect-to-a-url-on-the-lan/84941>\
**Category:** Writing SmartApps\
**Created:** [April 16, 2017, 2:42am UTC](https://community.smartthings.com/t/using-hubaction-to-connect-to-a-url-on-the-lan/84941 "2017-04-16T02:42:50Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jonathan\_Spector](https://avatars.discourse-cdn.com/v4/letter/j/9de053/32.png) [@Jonathan\_Spector](https://community.smartthings.com/u/Jonathan_Spector)\
**Post date:** [April 16, 2017, 2:42am UTC](https://community.smartthings.com/t/using-hubaction-to-connect-to-a-url-on-the-lan/84941/1 "2017-04-16T02:42:50Z")

</div>

I’m having a hard time undertsanding the terminology in ST - it seems strange to me. So I am probably doing something very wrong. I’m trying to turn on a virtual device and have that trigger a GET to a page called ‘moviescene.asp’ on the LAN. Here’s the SmartApp:

```
definition(
	name: "The Big Switch",
	namespace: "smartthings",
	author: "SmartThings",
	description: "Turns on, off and dim a collection of lights based on the state of a specific switch.",
	category: "Convenience",
	iconUrl: "https://s3.amazonaws.com/smartapp-icons/Meta/light_outlet.png",
	iconX2Url: "https://s3.amazonaws.com/smartapp-icons/Meta/light_outlet@2x.png"
)

preferences {
	section("When this switch is turned on, off or dimmed") {
		input "master", "capability.switch", title: "Which device?"
	}
}

def installed()
{   
	subscribe(master, "switch.on", onHandler)
	subscribe(master, "switch.off", offHandler)
	subscribe(master, "level", dimHandler)   
}

def updated()
{
	unsubscribe()
	subscribe(master, "switch.on", onHandler)
	subscribe(master, "switch.off", offHandler)
	subscribe(master, "level", dimHandler)   
}

def logHandler(evt) {
	log.debug evt.value
}

def onHandler(evt) {
	log.debug evt.value
	log.debug onSwitches()
	onSwitches()?.on()
}

def offHandler(evt) {
	log.debug evt.value
	log.debug offSwitches()
	offSwitches()?.off()
}

def dimHandler(evt) {
	log.debug "Dim level: $evt.value"
	dimSwitches?.setLevel(evt.value)
}

private onSwitches() {
	if(switches && onSwitches) { switches + onSwitches }
	else if(switches) { switches }
	else { onSwitches }
}

private offSwitches() {
	if(switches && offSwitches) { switches + offSwitches }
	else if(switches) { switches }
	else { offSwitches }
}

// TODO: do the GET

def hubAction = new physicalgraph.device.HubAction(
        method: "GET",
        path: "/moviescene.asp",
        headers: [HOST:"C0A856C8:22B8"]
    )
    
 log.debug hubAction
    hubAction
    log.debug "This is a test"

```

The SmartApp has no error messages, and the log file shows it is executing the GET, but the receiving server does not receive the request.

Any help anyone can provide would be much appreciated. Thanks.

---

<div class="post-metadata">

**Author:** ![Jonathan\_Spector](https://avatars.discourse-cdn.com/v4/letter/j/9de053/32.png) [@Jonathan\_Spector](https://community.smartthings.com/u/Jonathan_Spector)\
**Post date:** [April 16, 2017, 12:34pm UTC](https://community.smartthings.com/t/using-hubaction-to-connect-to-a-url-on-the-lan/84941/2 "2017-04-16T12:34:21Z")

</div>

I’m going to re-post this question to make it a bit simpler, please ignore. Thanks.

---

<div class="post-metadata">

**Author:** ![cvincent](https://avatars.discourse-cdn.com/v4/letter/c/d9b06d/32.png) [@cvincent](https://community.smartthings.com/u/cvincent)\
**Post date:** [April 17, 2017, 2:59pm UTC](https://community.smartthings.com/t/using-hubaction-to-connect-to-a-url-on-the-lan/84941/3 "2017-04-17T14:59:44Z")

</div>

There is a lot of old code hanging around that has bad examples of how to do HubActions like having to use hex represented IP addresses and ports. Here is a more “modern” take using the latest SmartThings documentation. `target` is the notation “host:port” in normal network order IP form. Callback looks like `def nvr_cameraPollCallback( physicalgraph.device.HubResponse hubResponse )` Change the headers (like remove accept) to suit your application.

```
def hubAction = new physicalgraph.device.HubAction(
    [
        path: "/api/2.0/camera/${state.id}?apiKey=${key}",
        method: "GET",
        HOST: target,
        headers: [
            "Host":"${target}",
            "Accept":"application/json"
        ]        
    ],
    null,
    [
        callback: nvr_cameraPollCallback 
    ]
);

sendHubCommand( hubAction );
```

---

<div class="post-metadata">

**Author:** ![HUTCHY](https://yyz2.discourse-cdn.com/smartthings/user_avatar/community.smartthings.com/hutchy/32/92187_2.png) [@HUTCHY](https://community.smartthings.com/u/HUTCHY)\
**Post date:** [February 12, 2019, 2:29pm UTC](https://community.smartthings.com/t/using-hubaction-to-connect-to-a-url-on-the-lan/84941/4 "2019-02-12T14:29:48Z")

</div>

Hi, this works well on my applcation, the only part I do not understand is the nvr\_cameraPollCallback? I am probably being a bit thick!

What I am trying to do is return the contents of the webpage called in path.

Thanks

Mark
