[Solved] Accessing Spark Core variables via CURL

I am playing around with the GPS application on my Spark Core.

If I use the following URL in Chrome browser (Access token and ID are dummy ones)


Only when the event is published by the Spark Core, the browser window updates with the following. I was hoping the API would just give me the last time the variable gpsloc was last updated.


event: gpsloc
data: {"data":"-42.909233,147.419235","ttl":"60","published_at":"2015-02-08T04:34:40.741Z","coreid":"53af72066678505545451467"}

I want to retrieve the variable gpsloc using curl, but it will not work?? I assume I would just use the following command

curl https://api.spark.io/v1/devices/53af72066678505545451467/gpsloc?access_token=e3273ffe51b907473c4b488962dd2c2d18f19ff3

But I just get the following error

  "ok": false,
  "error": "Variable not found"

Any help appreciated.

Kind regards

@sconrad, seems like you are using Spark.publish()?

You might want to read the docs further and use Spark.variable() instead:


1 Like

Thanks so much… Worked like a charm :smile: I have only been working with the Spark Core for 2 days… I must say I am loving it so far.

void setup(){
    Serial1.begin(9600);                    // Serial comms for talking to GPS module
    pinMode(led2, OUTPUT);                  // Set led2 (D7 onboard LED) as an output
    Spark.variable("gpsloc", szInfo, STRING);

Output is now.

  "cmd": "VarReturn",
  "name": "gpsloc",
  "result": "-42.909229,147.419312",
  "coreInfo": {
    "last_app": "",
    "last_heard": "2015-02-08T05:36:18.829Z",
    "connected": true,
    "deviceID": "53af72066678505545451467"