Variable Not Found

I think I’m going crazy. No matter what I do, I seem to get a “Variable not found”. At first I was using the DHT22 code from @wgbartley and I was getting a “Variable not found”. I assumed I was doing something wrong. So I just reflashed my :spark: with the tinker code and I’m able to use the tinker app, but if I try and use my terminal to change the state of anything I am back to the “Variable not found”

This is the exact (minus my ID and Token) command I am running in the terminal:

curl -G https://api.spark.io/v1/devices/ID/digitalwrite -d access_token=TOKEN -d params=D7,LOW

What am I doing wrong? @BDub, Any ideas?

Yep! :smile:

Remove the -G option, that transforms it into a GET request (which you use for variables), but it looks like you are trying to toggle the D7 output which is a function. Those are POST requests.

Formatting the curl request with -d data arguments automatically creates a POST request, unless you add that -G.

VARIABLES (GET REQUEST):
curl https://api.spark.io/v1/devices/55555555/variablekey?access_token=99999999

FUNCTION (POST REQUEST):
curl https://api.spark.io/v1/devices/55555555/functionkey -d access_token=99999999 -d args=coffee

55555555 = Your Device ID
99999999 = Your Access Token ID

1 Like

One day I will learn… Sorry for dumb mistakes!

What command should I have been using to pull sensor data from the DHT22 sensor? I’m using the library wgbartley created. That should use the -G option to GET data right? I still get the same error.

Do you have something like this in the setup() and loop() ?

float h;      // humidity
float t;      // temperature
char h1[10];  // humidity string
char t1[10];  // temperature string
int f = 0;    // failed?
 
void setup() {
    Spark.variable("humidity", &h1, STRING);
    Spark.variable("temperature", &t1, STRING);
    Spark.variable("status", &f, INT);
    dht.begin();
} 
 
void loop() {
    h = dht.readHumidity();
    t = dht.readTemperature();
    
    if (t==NAN || h==NAN) {
        f = 1; // not a number, fail.
    }
    else {
        f = 0; // both numbers! not failed.
        sprintf(h1, "%.2f", h); // convert Float to String
        sprintf(t1, "%.2f", t);
    }
}

Read with:
curl https://api.spark.io/v1/devices/55555555/humidity?access_token=99999999

curl https://api.spark.io/v1/devices/55555555/temperature?access_token=99999999

curl https://api.spark.io/v1/devices/55555555/status?access_token=99999999

Don’t worry about it… everyone learns everything :wink:

5 Likes

I :heart: @BDub

Makes me a little bit teary-eyed. This is exactly the attitude I want the whole :spark: community to have, and in fact, that I wish the whole world had.

Every time some über smart, mind-blowing answer is given here, you know that at some point in the past the speaker went from not knowing to knowing. They weren’t born with the knowledge. We should all have faith in the fact that the more knowledgeable among us will generously share their hard-fought knowledge with those seeking it.

The vulnerability you might feel in asking a question you worry might be perceived as “stupid” pales in comparison to the knowledge you will gain by risking it.

Keep building, people. Keep teaching, and keep learning.

Onward!

6 Likes

I am bumping into variable not found issue on my core. yesterday I was able to get the variable value, today it refuses to work :slight_smile:
Here is my code.Any suggestions?

char TempC[10];

void setup()
{
  // Register a Spark variable here
    Serial.begin(9600);
    delay(10000);
    
  IPAddress localAddr = Network.localIP();
  Serial.print(localAddr);
  Serial.print(" on ");
  Serial.println(Network.SSID());
  Serial.print("Pinging 5 times: ");
  Serial.println(Network.ping(server)); 
  client.connect(server, port);
  
  Spark.variable("temperature", &temperature, INT);
  Spark.variable("TempC", &TempC, STRING);
    
   if (client.connected()) {
    Serial.println("connected");
    client.println("GET /search?q=arduino HTTP/1.0");
    client.println();
  } else {
    Serial.println("connection failed");
  }

  

  // Connect the temperature sensor to A7 and configure it
  // to be an input
  pinMode(A7, INPUT);
}

void loop()
{
  // Keep reading the temperature so when we make an API
  // call to read its value, we have the latest one
  temperature = analogRead(A7);
  voltage=(temperature * 3.3)/4095;
  Temperature_float = (voltage - 0.5) * 100;
  sprintf(TempC,"%f",Temperature_float);
 
  Serial.println(TempC);
  client.println("Temperature is:");
  client.println(TempC); 
  
  
  delay(10000);
}

curl -G https://api.spark.io/v1/devices/***/temperature -d access_token=***
{
“ok”: false,
“error”: “Variable not found”
}

curl -G https://api.spark.io/v1/devices/***/TempC -d access_token=***
{
“ok”: false,
“error”: “Variable not found”
}

First reflash your core since it could be that it failed and is running a previous version or even Tinker.

Then, what happens when you do:

curl -G https://api.spark.io/v1/devices/ -d access_token=***

You should get a list of cores and then cut-and-paste the ID to avoid mistakes:

curl -G https://api.spark.io/v1/devices/***device ID*** -d access_token=***

Should give you something that lists the variables available.

1 Like

Tried that and no change. here is the output
this is after ref lashing
curl -G https://api.spark.io/v1/devices/55ff77065075555356481787 -d access_token=***
{
“id”: “55ff77065075555356481787”,
“name”: “tiger_hacker”,
“connected”: true,
“variables”: {},
“functions”: [
“digitalread”,
“digitalwrite”,
“analogread”,
“analogwrite”
],
“cc3000_patch_version”: “1.29”

Then I flashed the code again
curl -G https://api.spark.io/v1/devices/55ff77065075555356481787 -d access_token=***
{
“id”: “55ff77065075555356481787”,
“name”: “tiger_hacker”,
“connected”: true,
“variables”: {},
“functions”: [],
“cc3000_patch_version”: “1.29”

Hi @lkhosla

The core in the first case is running Tinker, not your firmware. Some error in your code probably caused it to run that as a “safe” mode.

The core in the second case is running code that does not have variables. If you flashed your code from the web IDE, was there any message?

You should keep your access_token private and probably should revoke that one. I will edit your post to remove it.

1 Like

Thanks, will do next time. The code was flashed from Web IDE and it said Flash Successful and I saw the core blinking before going back to Cyan light. There were no errors shown on the IDE.

And you are sure the target in the web IDE is this core with the number 55ff77065075555356481787?

Don’t worry about the name, just the number. Click the target crosshair icon in the web IDE to see which core is “starred” meaning the target for over-the-air flashing. Then click the “>” to the right of the core name to see the device ID.

yes the id is 55ff77065075555356481787. Just checked again in IDE

OK, I went back and read your code with a more critical eye. You have two Spark variables, and int and a char* string but the int variable temperature is not declared globally the way tempC is. In fact I don’t see where many variables are declared at all!

You should have

int temperature;
char TempC[10];

above your setup function.

Also is 10 characters enough? I would make it larger to be sure the floating point number fits.

cut+paste issue
// -----------------
// Read temperature
// -----------------

// Create a variable that will store the temperature value
int temperature=0;
float voltage=0.0;
double Temperature_float=0.0;
TCPClient client;
IPAddress server(192, 168, 1, 108);
uint16_t port = 5005;

//Client client( “192.168.1.122”, 2089 );

char TempC[10];

Hi @lkhosla

I would cut out the TCP client web stuff and make TempC[32] and try to just get the Spark variables working first. You can build from there.

thats how I build it first place and it worked fine yesterday when I just wrote it to serial. Are you suggesting TCPClient etc could cause variables to go away?

ok done. below is the code, no luck w variables.

// -----------------
// Read temperature
// -----------------

// Create a variable that will store the temperature value
int temperature=0;
float voltage=0.0;
double Temperature_float=0.0;
//TCPClient client;
//IPAddress server(192, 168, 1, 108);
//uint16_t port = 5005;

//Client client( "192.168.1.122", 2089 );

char TempC[10];

void setup()
{
  // Register a Spark variable here
    Serial.begin(9600);
    delay(10000);
    
  //IPAddress localAddr = Network.localIP();
  //Serial.print(localAddr);
  //Serial.print(" on ");
  //Serial.println(Network.SSID());
  //Serial.print("Pinging 5 times: ");
  //Serial.println(Network.ping(server)); 
  //client.connect(server, port);
  
  
  Spark.variable("temperature", &temperature, INT);
  Spark.variable("TempC", &TempC, STRING);
    
   //if (client.connected()) {
    //Serial.println("connected");
    //client.println("GET /search?q=arduino HTTP/1.0");
    //client.println();
  //} else {
    //Serial.println("connection failed");
 // }

  

  // Connect the temperature sensor to A7 and configure it
  // to be an input
  pinMode(A7, INPUT);
}

void loop()
{
  // Keep reading the temperature so when we make an API
  // call to read its value, we have the latest one
  temperature = analogRead(A7);
  voltage=(temperature * 3.3)/4095;
  Temperature_float = (voltage - 0.5) * 100;
  sprintf(TempC,"%f",Temperature_float);
 
  Serial.println(TempC);
  //client.println("Temperature is:");
  //client.println(TempC); 
  
  
  delay(10000);
}

curl -G https://api.spark.io/v1/devices/device -d access_token=token
{
“id”: “55ff77065075555356481787”,
“name”: “tiger_hacker”,
“connected”: true,
“variables”: {},
“functions”: [],
“cc3000_patch_version”: “1.29”

Hi @bko
Appreciate your patience for last 2 days on several issues which have come up. I do have a prototype which needs to build and finished and wanted to ask you if this maybe too early for Spark Core as a product or did I possibly get a faulty core ? More than happy to return it and visit back when you guys maybe more ready with documentation etc. Please suggest!!