Variable not found Local Cloud [Solved]

Hi guys,

I’m having trouble when I try to call my function through the browser like that:

http://‘IP from my local cloud’:8080/v1/devices/‘CORE_ID’/blink?access_token=‘MY TOKEN’

I’m running this code:

int led=D7;

void setup() {
  pinMode(led, OUTPUT); // set the D7 LED as output
  Spark.function("blink",blinkfunc);    // a POST request for "blink" will reference blinkfunc, defined below
}

// call the below function when the POST request matches it
int blinkfunc(String command) {
    digitalWrite(led, HIGH);    // turn it on
    delay(1000);    // wait 1 second
    digitalWrite(led, LOW); // turn it off
    delay(1000);    // wait another second
    return 1;   // return 1 to show that this worked.
}

void loop() {
//not doing anything here
}

I got the message in the browser:

{
  "ok": false,
  "error": "Variable not found"
}

But if I try to run via terminal like that:

curl ‘IP from my local cloud’:8080/v1/devices/‘CORE_ID’/blink -d access_token=‘MY TOKEN’

It works perfectly.

Also if I try to get the spark list, I receive that:

spark list
Checking with the cloud...
Retrieving cores... (this might take a few seconds)
name ('CORE ID') is online
  Functions:
    int blink(String args) 

And if i run:

http://‘IP from my local cloud’:8080/v1/devices/‘CORE ID’/?access_token=‘MY TOKEN’

without send the function called blink it returns me the right information like that:

{
  "id": "'CORE ID'",
  "name": "name",
  "connected": true,
  "variables": {},
  "functions": [
    "blink"
  ]
}

Any ideas what could be the error of Variable not found?

Best Regards.

This is a common misconception. You can’t do it just by entering the URL into the browser.

The reason is layed out quite nicely by @Dave in this “ancient” thread

1 Like

Thanks @ScruffR.

After some research I followed this tutorial ( http://cmsunu28.gitbooks.io/spark-basics/content/3_hello_internet.html ) where I could understand how it works. I simply create a html file with the following content and it worked fine.

<form action="http://IP from my local cloud/v1/devices/'CORE ID'/blink?access_token='MY TOKEN'" method="POST">
Blink me a message!<br>
<input type="radio" name="args" value="hi">Just say hello. (Blink once.)
<br>
<input type="radio" name="args" value="sos">It's an emergency! (Blink SOS.)
<br>
<input type="submit" value="Submit">
</form>

PS: I used the code post_blink2 as suggested at the link above.

1 Like