Sending array from agent via HTTP response

My device is generating an array containing the states of each pin. I would like to submit this array to the agent and then send it as the HTTP response. Unfortunately, I’ve only been able to send the memory address (as a string) and not the array itself.

Logging the array itself on the device side yields a memory address.
Logging the first index of the array on the device side yields the value stored at the index.
The same is true on the agent side.

How can I now submit this array to the client in the form of an HTTP response?

At a rough guess, I’d say you need the agent to run through the array and convert each element to a string. You then combine those strings into one and send it off in your HTTP response to be converted back to an array and processed. Something like this:

`local send_string;

foreach (item in array)
{
send_string = send_string + item.tostring();
}

cached_response.send(200, send_string);`

Thanks for your suggestion. This solution seems a little unwieldy to me – is it not possible to somehow use JSON encoding? (I’ve been unsuccessful with this so far.)

It is perhaps a little hammer-to-crack-nut, but it has the advantage of being easy. You can create an http object to POST, and there’s a http.jsonencode() method which will code up an array, but you’ll need to send it to an entity capable of dealing with HTTP requests.

Ah! No idea how I overlooked this. Thanks for your help.