Any Documentation on "physicalgraph device HubAction"?


(Nicholas Wilde) #30

I don't get why the functions aren't ubiquitous across both the device type and SmartApp. Thanks for the clarification.


(Geno) #31

So how do you do it from a device type? There are no examples and everything I try acts like it is sending the request but when I check my IIS logs, there is no request.


(www.rboyapps.com - Make your home your butler!) #32

Converting IP address to Hex is easy patrick has done that and for those who want the code:

private String convertIPtoHex(ipAddress) { 
    String hex = ipAddress.tokenize( '.' ).collect {  String.format( '%02x', it.toInteger() ) }.join()
    return hex

}

private String convertPortToHex(port) {
	String hexport = port.toString().format( '%04x', port.toInteger() )
    return hexport
}

Interestingly has anyone been able to get an IP address from a Hostname inside device code?


Nanoleaf's new light panels
(Tom Beech) #33

I’ve just about given up with trying to make a HTTP POST / GET from the hub… I copied your code and the logs output the HubAction, which looks to be the correct, but no call is made… I have some debug lines which print out on my HTTP service which tell me when a GET / POST request are made…

The device network id are set correctly (as hex) in the device, but it still does not appear to make the call… :frowning:

I then went back to basics (with no luck), referring to the documentation http://docs.smartthings.com/en/latest/cloud-and-lan-connected-device-types-developers-guide/building-lan-connected-device-types/building-the-device-type.html:

def get() {
def result = new physicalgraph.device.HubAction(
method: "GET",
path: "/api/display",
headers: [
    HOST: "192.168.1.130:9000"
])

log.debug result
result

return result
}

(Patrick Stuart [@pstuart]) #34

What does the response look like? St can only handle text, json and HTML. No binary or raw responses.


(Tom Beech) #35

I return JSON from my web api. However, I have managed to get it working! Turns out I did not assign my device to a hub, so the local commands were not being sent anywhere. There was no debug info in the log output… and no mention of it in the api docs. But oh well, I managed to get local HTTP GET / POST commands working :smiley:

Took all day, but its done…

I do have a question though, it appears that whenever you call hubAction, the response always goes to def parse { }… However, is there anyway to get it to goto a different method? I may need to treat the data differently based on what comes back :S

Thanks for the reply :slight_smile:


[RELEASE] Absolute Simplest ESP8266 Smart Blinds, no mqtt, rest, bridge, or broker, just your board and your hub
(Kevin Tierney) #36

It will always go to parse, but you can send it off to other functions however you need


(Tom Beech) #37

OK, but there doesnt seem to be anyway of knowing where the request originated from?


(Kevin Tierney) #38

Not directly, you may be able to set a state variable that tracks which function sent the request


(Umar) #39

Hi can someone tell me what I’m missing please? I tried a few methods but my parse function is never triggered. I am trying to pull a temperature from an ESP8266 wifi shield connected to a temperature sensor. I can see the temperature in the html when i go to the ip address in the browser.

//html
ESP8266 Temperature Sensor

Temp F: 79.25
Temp C: 26.25
//end html

// handle commands
def getTemp() {
log.debug "Executing 'getTemp'"

def ip = "192.168.1.7"
def hexIp = "C0A80107"
def port = "80"
def hexPort = "50"
def deviceNetworkId = "C0A80107:50"
device.deviceNetworkId = deviceNetworkId
log.debug "The device id configured is: $device.deviceNetworkId"
def macAddress = "A020A6107DA8"

/*def result = new physicalgraph.device.HubAction(
    method: "GET",
    path: "/",
    headers: [
        HOST: ip
    ]
)
return result*/

//sendHubCommand(new physicalgraph.device.HubAction("""GET / HTTP/1.1\r\nHOST: $ip\r\n\r\n""", physicalgraph.device.Protocol.LAN, "${deviceNetworkId}"))

def headers = [:] 
headers.put("HOST", "$ip:$port")
log.debug "The Header is $headers"

def method = "GET"

try {
    def hubAction = new physicalgraph.device.HubAction(
        method: method,
        path: path,
        headers: headers
        )
    log.debug hubAction
	hubAction
}
catch(Exception ex) {
	log.debug "Hit Exception $e on $hubAction"
}
}

The logs are
Executing 'getTemp’
The device id configured is: C0A80107:50
The Header is [HOST:192.168.1.7:80]
GET path HTTP/1.1
Accept: /
User-Agent: Linux UPnP/1.0 SmartThings
HOST: 192.168.1.7:80


(Brian) #40

Is the sendHubCommand after defining your hubAction just missing from your example?


(Patrick Stuart [@pstuart]) #41

your path in your hubaction isn’t defined, its just sending “GET path HTTP/1.1”


(Umar) #42

Updated:

def headers = [:] 
headers.put("HOST", "$ip:$port")
log.debug "The Header is $headers"

def method = "GET"

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

I also tried replacing hubAction at the end of the try block with sendHubCommand(hubAction) but it made no difference. Would the issue have anything to do with UPNP?


(Patrick Stuart [@pstuart]) #43

UPNP is something completely different. What are you trying to do?


(Umar) #44

Just get the body of the html and parse through it. I have read the method used depends on if you are building a device handler or a smartapp. In my case I am trying to build a device handler, I also read that in some case you use mac address and some ip and in some ip:port in hex. I have been playing with all of these but with no luck so I was looking at UPNP but this was just me grasping at straws to figure out why the parse function never fires.

def parse(String description) {
log.debug "Parsing '${description}'"

def msg = parseLanMessage(description)
    log.debug msg
}

(Umar) #45

Also not sure if it matters but I have only tried this in the simulator.

Thanks


(Umar) #46

I tried running the hub action which was printed out in the logs in putty

so I ran
"GET / HTTP/1.1
Accept: /
User-Agent: Linux UPnP/1.0 SmartThings
HOST: 192.168.1.7:80"

and got the following so I know the GET is working. Pasting html in here doesn’t work so just pasting the non html

HTTP/1.1 200 OK
Content-Type: text/html

ESP8266 Temperature Sensor

Temp F: 80.82
Temp C: 27.12


(Umar) #47

any other ideas?


(Patrick Stuart [@pstuart]) #48

so you are getting a response? What’s the issue?


(Umar) #49

No response the parse function is never triggered. I am only getting the response in putty or the browser.

I just cane across this so I will try it and see what happens.