Can't figure out hub to device over http


(Heath) #1

Folks,

I need help trying to get a devicetype to make a call to a local http server. Using an Arduino Nano and the cc3000 wifi breakout, I automated my blinds. I want to use the smartthing tiles to control them using the slider control. I have tried to use HTTPGet, HubAction and I cannot get a call to work.

I have in the past created a device type for my dlink camera, but I opened up a port on my firewall to get that to work. I can definitely do that, but I thought that I could do a hub to lan device call.

I used these posts to try to make the connection:


I am not using the SmartShield with my Arduino. Any help is appreciated.
Thanks in advance


(John S) #2

The local hubaction works fine - you should be using an ip address on your local network for it to work. Maybe post a code snippit of the code that’s not working?


(Heath) #3

Sorry, I had tried so many options that I didn’t keep track of. Here is the last bit that I tried from someone elses post.
def on()
{
send()
}

def send()
{
def host = "192.168.1.234"
def hosthex = "C0A801EA"
def porthex = "0050"
def deviceNetworkId = “$hosthex:$porthex”

log.debug "The device id configured is: $device.deviceNetworkId"



def headers = [:] 
headers.put("HOST", "192.168.1.234")


log.debug "The Header is $headers"

def method = "GET"


log.debug "The method is $method"

try {
def hubAction = new physicalgraph.device.HubAction(
	method: method,
	path: "/",
	headers: headers
    )
    	
hubAction.options = [outputMsgToS3:true]
log.debug hubAction
hubAction
}
catch (Exception e) {
	log.debug "Hit Exception $e on $hubAction"
}

}


(John S) #4

You should give the docs another read here http://docs.smartthings.com/en/latest/cloud-and-lan-connected-device-types-developers-guide/building-lan-connected-device-types/building-the-device-type.html

Off the top of my head I see:
HOST isn’t using the HEX values for ip address, nor is it including the port. That’s likely the first problem.

Also, hubaction isn’t executed when you put it on a line by itself, it’s executed “when it’s returned” from a function. So you should just be returning hubAction, no need to wrap it in a try/catch (it’s not going to throw anything…)

You need to look for the response inside your parse() method. Again, the doc page above is pretty reasonable .


(Heath) #5

Thanks John. It was the hex address that was missing
def myCommand() {
def result = new physicalgraph.device.HubAction(
method: “GET”,
path: “/?servo=1&degree=90”,
headers: [
HOST: “C0A801EA:0050”
]
)
log.debug (result)

return result

}


(Coolcatiger) #6

How do you convert IP to hex address?

Did you convert e.g 192168001005 to hex for host ip 192.168.1.5?


(Heath) #7

I cheated and used this website: http://www.miniwebtool.com/ip-address-to-hex-converter/.

On this page there is some sample code to do the same thing:
http://docs.smartthings.com/en/latest/cloud-and-lan-connected-device-types-developers-guide/building-lan-connected-device-types/building-the-device-type.html