httpPost to LAN ip


(Jcluo) #1

Hi, my SmartApp needs to send httpPost to IP address in LAN. It is getting timeout error. While I set port forward in my router to forward an external port and httpPort to the external WAN IP, there is no problem.
My question here is that is the SmartApp execute by cloud server or the hub? How can httpPost to a local LAN IP?

Thanks,
Daniel


(sidjohn1) #2

Sounds like you’re using the wrong command. Httppost is for wan/cloud devices. Hubaction is for lan.

http://docs.smartthings.com/en/latest/cloud-and-lan-connected-device-types-developers-guide/building-lan-connected-device-types/index.html


(Jcluo) #3

I follow the GET example but the following code does not work.

def result = new physicalgraph.device.HubAction(
    	method: "POST",
    	path: "/rfoutlet/toggle.php",
    	headers: [HOST: "192.168.2.105"],
        body: """Id=${rfid}&Status=ON"""
)
sendHubCommand(result)

Does anyone has working HubAction POST example code?

Thanks
Daniel


(Rob) #4

I use a GET with HubAction. I think I tried POST and it worked but don’t remember for sure.

def on() {
def result = new physicalgraph.device.HubAction(
method: “GET”,
path: “/api/alarm/arm”,
headers: [
HOST: “$ip:$port”
//HOST: getHostAddress()
]
)
log.debug “response” : “Request to arm received”
//log.debug "arm"
sendEvent (name: “switch”, value: “on”)
return result
}


(sidjohn1) #5

There are several devicetypes that do, use the search icon to look up Roomba or generic ip camera. There are plenty others hiding under search.


(Jcluo) #6

I still can’t get it work. I am calling hubAction from SmartApp. Does it only work for device type? I haven’t tried write a device type yet.