Function doesn't return correct values?

You should expect something like:

{
  "id": "0123456789abcdef01234567",
  "name": "YourDeviceName",
  "last_app": null,
  "connected": true,
  "return_value": 200
}

I just tried this code and it’s working fine for me:

bool state = HIGH;
void setup() {
    pinMode(D7,OUTPUT);
    digitalWrite(D7,HIGH); // turn on D7 by default
    Spark.function("test", testFunction);
}
int testFunction(String args) {
    state = !state; // toggle the state
    digitalWrite(D7,state);
    return 200;
}

The added benefit of including D7 in the mix, is that you can see the onboard LED toggle on/off for ever successful command you send. If the Core is not receiving the command, you’ll note that the LED will not toggle.

If you send the wrong funcKey which is test, you should see something like this:

{
  "id": "0123456789abcdef01234567",
  "name": "YourDeviceName",
  "last_app": null,
  "connected": true,
  "return_value": {
    "Error": "Something went wrong calling this function: Unknown Function: testjunk"
  }
}

If your device is offline you will see this response:

{
  "error": "Timed out."
}

If you are using Curl commands it’s formatted like this:
curl https://api.spark.io/v1/devices/0123456789abcdef01234567/test -d access_token=1234123412341234123412341234123412341234

where 0123456789abcdef01234567 is your code ID and the access_token ID is your actual token ID.

You can also try using a nice browser extension for Chrome called Advanced Rest Client found here: https://chrome.google.com/webstore/detail/advanced-rest-client/hgmloofddffdnphfgcellkdfbfbjeloo

Example of how to use it:

Here’s an example response: