Second ever Driver http Response broken

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
image

But the Driver looks like this
image

I have tried just about everything I have seen in the forums and online. HELP!

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.

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

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. :wink:

Now I just have to get the rest of the code needed to set some bulbs to match the color!

@cheerlights on Twitter!