This particle.variable() always seems to give me problems. Presently I need to figure out how to send a group of variables to a webpage for further processing, seems like packaging the variables as a fake jSON object may be a good solution, but before I get to that, the Particle Firmware Reference has a strange line at
https://docs.particle.io/reference/firmware/photon/#particle-variable-
The line is
if (Particle.variable("mess", message)==false)
// variable not registered!
Particle.variable("mess2", aString);
The syntax here confuses me, could someone please put in some curly brackets as needed or just change the code to something like
if (Particle.variable("mess", message)==false){
// variable not registered!
}
Particle.variable("mess2", aString);
since the present Firmware example seems to never let “aString” work, unless you somehow make the first “message” char array pointer become not registered!
Anyway if I ignore the example code, my working code looks like:
String theString;
int x1,y1,x2,y2,x3,y3;
void setup()
{
void random_seed_from_cloud(unsigned int seed);
Particle.variable("myString", theString);
}
void loop()
{
x1 = random(1, 99);
y1 = random(1, 99);
x2 = random(1, 99);
y2 = random(1, 99);
x3 = random(1, 99);
y3 = random(1, 99);
theString = String( "x1=" + String(x1) + ", y1=" + String(y1) + ", x2=" + String(x2) + ", y2="+String(y2) + ", x3=" + String(x3) + ", y3=" + String(y3) );
}
So if I throw something like this into my browser
https://api.particle.io/v1/devices/00000000000/myString?access_token=aaaaaaaaaaaaaaa
where the 000000000 are my ID and the aaaaaaaaaaaa are my access token then I get a result like
{
"cmd": "VarReturn",
"name": "myString",
"result": "x1=17, y1=30, x2=21, y2=23, x3=47, y3=37",
"coreInfo": {
"last_app": "",
"last_heard": "2015-11-05T06:37:15.434Z",
"connected": true,
"last_handshake_at": "2015-11-05T06:34:52.260Z",
"deviceID": "00000000000",
"product_id": 6
}
}
Which looks reasonably useful. Now, I just have to remember how to use AJAX to load this back into javascript and I think I am set.