JuHyun
(JuHyun)
July 1, 2019, 5:53am
#1
def dataCallback(physicalgraph.device.HubResponse hubResponse) {
logger(“dataCallback”);
def msg, json, status
try {
msg = parseLanMessage(hubResponse.description)
status = msg.status
json = msg.json
state.dataList = json
state.latestHttpResponse = status
} catch (e) {
logger(‘warn’, "Exception caught while parsing data: "+e);
}
}
def getDataList(){
def options = [
“method”: “GET”,
“path”: “/”,
“headers”: [
“HOST”: “https://community.smartthings.com ”
]
]
def myhubAction = new physicalgraph.device.HubAction(options, null, [callback: dataCallback])
log.debug("myhubAction");
log.debug(myhubAction);
sendHubCommand(myhubAction)
}
The dataCallback function is not called.
def myhubAction = new physicalgraph.device.HubAction(options, null, [callback: dataCallback])
There is no error log, but logger (“dataCallback”);
Does not occur.
joshua_lyon
(Josh, SharpTools.io Dashboard)
July 2, 2019, 10:09pm
#2
Try formatting your code so it’s easier for others to read. You can either highlight the block of text and then tap the </>
icon in the editor toolbar or surround the code with triple backticks:
```
your code here
```
What are you trying to accomplish? Do you want to make an internal (LAN) or external (internet) HTTP call? And are you trying to do it from a Device Handler or a SmartApp?
If you are trying to make an external asynchronous HTTP call, check out the following docs:
https://docs.smartthings.com/en/latest/smartapp-developers-guide/async-http.html
include 'asynchttp_v1'
def initialize() {
def params = [
uri: 'https://api.github.com',
contentType: 'application/json'
]
def data = [key1: "hello world"]
asynchttp_v1.get('responseHandlerMethod', params, data)
}
def responseHandlerMethod(response, data) {
log.debug "got response data: ${response.getData()}"
log.debug "data map passed to handler method is: $data"
}
There are also simply synchronous external HTTP helper methods as documented here:
https://docs.smartthings.com/en/latest/smartapp-developers-guide/calling-web-services-in-smartapps.html
def params = [
uri: "http://httpbin.org",
path: "/get"
]
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"
}