hi all, i'm a non-programmer trying to get something working 'cause no-one else seems to have my issue.
i've spent HOURS trying to work this problem out, i've gotten what seems to be very close but i don't understand how to progress.
I am trying to successfully do a httpGet to an Daikin AC wifi controller.
The existing HE driver for the non-secure (HTTP) wifi adapter version of this AC unit uses a HubAction GET for its dirty work. However MY wifi adapter is the newer 'secure' version that uses HTTPS. After much time and pain, I can get the damn thing to connect, but it refuses to allow connection with HubAction (keeps giving connection resets). If i use httpGet method, it seems to connect OK, BUT i keep getting a data type error of sorts as I try to receive the data.
"java.lang.ClassCastException: java.lang.String cannot be cast to java.util.Map on line 175 (apiGet)".
I've read numerous posts and code examples, but for something that I am guessing is simple for a seasoned programmer to understand, I don't know the fundamentals enough to truly understand whats going on and how to sort it. the problem line is the httpGet, i don't really understand the 'closure' thing at all, the { resp -> def respData = resp.data.response } bit was stolen from someones post hoping it would work but ... nope.
What is the format of the reply? Do you have an API reference or another example or demo from the web that shows how to interact with the Daikin?
Try the closer part like this. I'll guess that you may need to tweak either contentType or requestContentType based on what the device expects and how it replies.
hmmm...same error:
java.lang.ClassCastException: java.lang.String cannot be cast to java.util.Map on line 176 (apiGet).
the log msg you added does not 'appear', it doesn't get that far.
uh...dumb question...how do i copy the code with the numbers? the side bar with the numbers is not 'selectable'.
line 176 is literally just the httpGet(params) line
BTW thanks for your efforts so far...same error though, it doesn't get past the httpGet and down to display the debug messages.
the guide docs Common Methods Object - Hubitat Documentation shows that using a Map to provide the necessary parameters is valid, this closure thing to me is completely unexplained and references an object of type "HttpResponseDecorator"
sync http waits for the response.. if the Site takes 2 seconds to respond, the hub's going to be hit by that. Async on the other hand, splits the send and the response, allowing the hub to work while the Site is responding.
Obviously, if the httpGet is run once an hour, the hub isn't going to falter significantly. But for the most part, these are usually polled and at a high cycle time. Async is the better choice.
However, back to your actual question, yes, the Headers need to be a Map as shown in my snippet...
hi csteele...thanks for the explanation, i read the method guide but it wasn't clear to me what the difference is between sync and async httpGETs are in this context.
i even gave async a try during my many hours of frustration, but i couldn't get it working either, and i seemed to be getting further with the sync version.
i agree with your suggestion...i'm almost too scared to try.
The "trick" is to recognize that the response is 'stale' until the next arrives. In my case, I have to login in two sequential http get's.. once to get some cookies, then a real login with the cookies sent along. Quite clearly, I can't fall into the 2nd http get til the first returns the cookies. With sync of course, falling is precisely what works and is easy.
hi @csteele i';ve given it a go...but error "Method definition not expected here. Please define the method at an appropriate place or perhaps try using a block/Closure instead. at line: 182 column: 5. File: Script1.groovy @ line 182, column 5."
also: in this case is the return variable resp.Data ?
In other words, apiGet() finishes.. the hub gets control back and goes off and does other work... when the response comes in.. maybe 2 seconds later, the getStatusHandler method runs.
hmm..i thought being a "def" not a "private" meant you were defining a type of variable, not creating a new routine. OK that makes sense. i thought your } was a typo