I'm in the process of writing an app for AAOS that allows me to project Hubitat dashboards in a car running AAOS (different than Android Auto).
My goal is to read the dashboard layout and recreate it in the AAOS App. I'm running into a problem, though. The problem is calling the Hubitat dashboard API from my own Hubitat app.
I pulled out Wireshark and watched the network traffic when I access the dashboard via the local url. The traffic is easy enough to decipher.
Go to the dashboard (url is similar to a regular app url in that is has the access_token query field). In the web page that is returned, buried in the JavaScript, is a variable call javascriptRequestToken. On the second call, the "javascriptRequestToken" is put on the url query string, while the access_token is used in the header for the Authorization. You then send the url path as "layout" and you get the json back with the layout description.
So, using curl, I can faithfully recreate this process and all works just fine. However, if I then go to my hubitat app and code this up, I'm told "connection refused". Oddly, if I use the cloud url for the dashboard, it works fine.
Here is the essence of the code. This first block gets the request token:
String getKeyValue(dashboard){
def key
httpGet(uri:"http://<my hub url>/apps/api/<my dashboard id>/dashboard/<my dashboard id>?access_token=<my access token>"){response->
def pattern=Pattern.compile(/var\s*javascriptRequestToken\s*=\s*"([0123456789abcdef]{8}-[0123456789abcdef]{4}-[0123456789abcdef]{4}-[0123456789abcdef]{4}-[0123456789abcdef]{12})"/)
def lines=response.data.toString().split('\n')
def mat
lines.each{line->
//mat=line=~pattern
mat=pattern.matcher(line)
if(mat.find()){
key=mat.group(1)
}
}
}
return key
}
with the local url, it gives me:
org.apache.http.conn.HttpHostConnectException: Connect to <my hub url>:80 [<my hub rul>/<my hub ip>] failed: Connection refused (Connection refused) on line 146 (method getLayoutGET) (note I find it odd that the error points to a function that calls the above function but indicates the line number from the above function.)
Any thoughts?