Just a question⌠shouldnât it be possible to make it work with String objects as well? That would make Spark.variable() of type STRING make more logical sense and more universal.
Few hours ago @zachary made an update to master that now supports strings up to full queue length. So âfinalâ limit seems to be now 622 characters and wonât timeout if you try longer (it just cuts the string at limit).
The first byte of queue was also part of size variable instead of sole second one that I had figured out in my version.
/* This function is called once at start up ----------------------------------*/
void setup()
{
//Expose variables to the cloud
Spark.variable("strReceived", inSerial, STRING);
Spark.variable("statResp", stsMessage, STRING);
......
}
In my application, I say
int DisplayMessage (void){
Serial.println("begintodisplaymessage");
....
switch (stsArVal[1]) {
case 1:
//do something when var equals 1
stsMessage= "1= WAITING TO SAMPLE";
break;
...
}
When I print to serial, the variable is updated. When I go to another function and print the same variable to serial (which should make any scope problems a non-issue I think), I also get the proper response.
You see, stsMessage is getting overwritten with new information. This is properly conveyed to the serial port but not in the cloud.
Incidentally, strReceived is getting properly updated. Is this an issue with using char* ?
When I call this variable from the cloud, it is not updated.
I think youâre running into a fun C quirk with pointers, yay pointers!
When youâre setting up a Spark.variable, youâre saying you have something interesting at a particular address in memory, in this case the address of âstsMessageâ during setup. When you assign it a new value in the loop, instead of copying your new information into that same spot in memory, youâre pointing stsMessage somewhere else, in this case to the address of âWAITING TO SAMPLEâ. I think if you used strcpy, or something similar, and initialized stsMessage to a larger array for strings, youâd be golden, e.g.:
Hi!
I believe I have the same issue. If I understand correctly, I should copy using âstrcpyâ before I sprintf, correct? Would the same thing apply to spark.publish?
Also, does the âstsâ do something such as replace the â&â?
Thanks!
The âstsâ in this case is just his naming convention, not needed If youâre using sprintf, then sprintf is printing into that character array, and you donât need to do a strcpy.
This also doesnât apply to Spark.publish calls, since it just pulls whatever is there at the moment you call that command, instead of referring to an address you pointed to earlier and then changed.