Spark.variable name length limitation

I’ve managed to read the value of a variable declared with Spark.variable using curl, but apparently the length of the variable name has to be limited to some (in my opinion) rather low value. For example, when I declare a variable as follows:

Spark.variable( "airtemp", &airtemperature, DOUBLE );

then I can read it with:

curl https://api.spark.io/v1/devices/<my-device-id>/airtemp?access_token=<my-token>

However, if I declare it as follows, extending the name to something more meaningful:

Spark.variable( "airtemperature", &airtemperature, DOUBLE );

then suddenly curl (obviously with “airtemp” replaced with “airtemperature”) complains that:

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

I hardly expect this to be the intended behavior. Am I missing something? (Yes, I’ve double-checked my spelling in case anyone wonders.)

Hi @wolf

The doc notes that there is a limit:

NOTE: Variable names are truncated after the 12th character: temperature_sensor is accessible as temperature_

There is also a limit on how many variables you can have.

I think RAM is very tight for a lot of people and dedicating more RAM to these names would not be a good trade-off for many users. The source code is available and if you want to change the limit you certainly can. I know someone did that for the event length limit for their application, for instance.

3 Likes

Yep, that’s the intended response:

http://docs.spark.io/#/firmware/data-and-control-spark-function

“The length of the funcKey is limited to a max of 12 characters.”

varKey is not stated the same, but it most likely is. Something that probably needs to be updated in the documentation.

EDIT: boom… double the help, at lightning speed.

3 Likes

Photo finish!

. . . . . . . || . F
. . . :racehorse: . | . I
. . . :racehorse: . | . N
. . . . . . . | . I
. . . . . . . | . S
. . . . . . . || . H

Okay, the horses are backwards, I’ll get it right the next time… :slight_smile:

5 Likes

wow Dave, looks like bko is leading by a butt! :open_mouth:

3 Likes

I am going to submit a feature request so I can :heartbeat: things multiple times! :smiley:

You guys are too funny!

1 Like

Actually there’s a feature in Discourse that weights the value of likes from Staff users to 3 vs. 1. So you may already be covered :wink:

1 Like

Thanks–I had missed that document entirely.

I’m a little surprised this comes out as a RAM issue, though. I’d have thought the compiler were smart enough to detect a constant string and place it in flash, leaving significantly more room for string length.

That’s a good question, and the compiler IS smart enough to save const char arrays to flash memory first… but the way the Spark Protocol is written, the variable key is explicitly truncated at 12 characters and copied into the spark protocol memory structure:

Why exactly it can’t be a pointer to a character array in flash is not something I’ve thought long enough about. But this information is transferred to the Cloud, so perhaps there is some underlying reason for it to be exactly a certain number of bytes or something. Since things are encrypted.

1 Like