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:
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.
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.