Sending an array via output port and then HTTP request


I am currently trying to send three coordinates through the output port of the imp to an HTTP Request node which will send the data via POST to a php script. The problem I am encountering is when I try to read the data on the php side, I can only read one of the coordinates.

Is it possible to send an array through POST using the imp? I am fairly new at squirrel and php/html so please forgive me if I sound like I don’t know what I am talking about.

I define my array as:

local array = [someX, someY, someZ];

and set my output:


and I configure:

imp.configure("Coordinate Buffer", [], [output]);

On the PHP side I try to access the ‘someX’ variable with:


as well as the other two indices for the Y and Z variables but this doesn’t seem to work. Any input would be greatly appreciated!

Take a look at this page, and a few of the pages linked in it:

You may try passing the output type (in this case, its type is an “array”) into the constructor of the OutputPort when you create the output object, as such: (the names in this particular case may lead to confusion since they are quite similar)
output <- OutputPort("value", "array");

The constructor reference page states that if the OutputPort type is omitted, it will default to “number”, which seems to be your case. (See here:

Something to try on the PHP side … just a stab at it without trying it myself …


See if it displays the array of values.
It’s possible the array is already there.

If so …
echo $items[0];
echo $items[1];
echo $items[2];

Thanks for the quick responses!

I ended up trying:

output <- OutputPort("value", "array");

Which definitely sets the output port to send an array (thank you!), and I know it is sending the correct values, but now I think the problem is in the PHP side.

When I connect the noodle from the imp to the HTTP Request, it says (under destination outputs: value[string]. Could this be the problem, can I change what type of variable the HTTP Request node receives?

I also tried the method posted above which was also helpful:

$items=$_POST['value']; print_r($items); echo $items[0]; echo $items[1]; echo $items[2];

It would only show the Xcoord, in this case $item[0]. When I printed them to a file, again only the $item[0] variable would print and $item[1] and $item[2] would both print blank characters.

Here’s a way to test the PHP side.

Make this simple HTML page and perhaps called it “testing.html” …

Item 1:

Item 2:

Item 3:


Now, create a PHP script called “test.php” …


<?php $items=$*POST['value']; echo "This is the array of values:
"; print_r($items); echo "

These are the items individually:
"; echo $items[0]."
"; echo $items[1]."
"; echo $items[2]."
"; ?>


If the PHP script works (displaying the array of values), then you know the PHP part is correct. Now you can work on the imp side of it.

And I am just noticing that the underscore does not appear on this editor.
That’s too bad because the underscore is important. I’ll put an asterisk where there is supposed to be an underscore.