Hasty1
November 8, 2020, 4:00am
1
Below is my code for the poll
def poll() {
if (logEnable) log.debug "polling..."
String url = "http://api.thingspeak.com/channels/1417/field/1/last.txt"
try {
httpGet(url) { response ->
def body = response.data
if (logEnable) log.debug "${body}"
sendEvent(name: "color1", value: body, isStateChange: true);
}
} catch(Exception e) {
log.debug "error occured calling httpget ${e}"
}
}
The log looks like this
But the Driver looks like this
I have tried just about everything I have seen in the forums and online. HELP!
Hasty1
November 8, 2020, 1:55pm
3
Changing the code to the value of of body, yields the following error in the log
Try changing the following line
From
def body = response.data
To
def body = new String(response.data)
We need store a copy of the contents in a variable, rather than just a reference to it.
Hasty1
November 8, 2020, 2:25pm
5
That yields a new error
I also tried response.data.ToString() and got a similar error.
I am not a programmer but it seems that response.data is Schrödinger data... as is both a string and not a string at the same time
Try
def body = new String("${response.data}"}
1 Like
Hasty1
November 8, 2020, 3:10pm
7
That worked...thanks a ton. I am so not a programmer. But i am happy to get this hacked together!
2 Likes
Glad it helped. I had literally just figured out the exact same thing last night in an app I was working on. There may be a better solution, but this at least works for now. If others have a better solution, I am all ears.
Hasty1
November 8, 2020, 3:27pm
9
Now I just have to get the rest of the code needed to set some bulbs to match the color!
@cheerlights on Twitter!