There seems to be some discrepancy between methods for manipulating strings on the Spark Core. My current goal is to print a JSON formatted object using an API GET call in order to pass some information out to a server. This seems to be harder than expected:
1 - sprintf() for multiple variables seems to not play nice with the core, resulting in 400 errors or refusing to flash. (link)
Example sprintf statement that fails (with extra casting):
sprintf(output, "{ temperature:%d, humidity:%d, fail:%d }", (int) intTemperature, (int) intHumidity, f);
2 - The String variable type doesn’t print properly. Code:
String test = String(millis(),(unsigned char)DEC);
void setup(){
Spark.variable("testString", &test, STRING);
}
void loop(){
test = "testing"; // commenting this line doesn't seem to affect API results
delay(1000);
}
API Results:
{
"cmd": "VarReturn",
"name": "teststring",
"TEMPORARY_allTypes": {
"string": "ďż˝$",
"uint32": null,
"number": null,
"double": null,
"float": null,
"raw": "ďż˝$"
},
"result": "ďż˝$",
"coreInfo": {
"last_app": "",
"last_heard": "2014-01-06T01:58:45.390Z",
"connected": true,
"deviceID": "xxx"
}
}
Typical Arduino string manipulation via concat() or += along with casting variables to String(var) does not seem to alter these API results either.
Has anyone else found a way to manipulate chars or String variables?