I’ve been really trying to get up and running with some applications that utilize Spark.variable
and Spark.function
however I’m hitting way to many issues on the cloud API.
Given the following code, here are some issues I’ve noticed.
int light;
void setup() {
pinMode(D6, OUTPUT);
pinMode(A7, INPUT);
Spark.variable("light", &light, INT);
}
void loop() {
digitalWrite(D6, HIGH);
light = analogRead(A7);
}
The API isn’t reporting any variables:
$ curl "https://api.spark.io/v1/devices/<my_core_id>?access_token=<private>"
{
"id": "<my_core_id>",
"name": "snowcone-alpha",
"variables": [],
"functions": []
}
Ok, well that’s weird… What happens when we ask for the variable anyway:
$ curl "https://api.spark.io/v1/devices/<my_core_id>/light?access_token=<private>"
{
"cmd": "VarReturn",
"name": "light",
"TEMPORARY_allTypes": {
"string": "\u0000\u0000\b\"",
"uint32": 2082,
"number": 2082,
"double": null,
"raw": "\u0000\u0000\b\""
},
"result": "\u0000\u0000\b\"",
"coreInfo": {
"last_app": "foo",
"last_heard": "2013-12-24T10:53:10.065Z",
"connected": false,
"deviceID": "<my_core_id>"
}
}
First of all, the core is reporting to be not connected. Also it seems to be struggling with the analog read.
What happens if I just read a random variable (that doesn’t exist)
$ curl "https://api.spark.io/v1/devices/<my_core_id>/asdga?access_token=<private>"
{
"cmd": "VarReturn",
"name": "asdga",
"TEMPORARY_allTypes": {
"string": " \u0000P\u0000",
"uint32": 536891392,
"number": 536891392,
"double": null,
"raw": " \u0000P\u0000"
},
"result": " \u0000P\u0000",
"coreInfo": {
"last_app": "foo",
"last_heard": "2013-12-24T10:54:40.240Z",
"connected": false,
"deviceID": "<my_core_id>"
}
}
Ok, well that was unexpected. I should be getting an error here.
I had similar difficulty with the Spark.function
function.