HTTP GET to call a device level function

I know I saw some explanation on how you could make an HTTP request against the cloud API that would allow you to call a function in your code on the device with parameters, but I cant seem to find that now. Can anyone point me in the right direction? I thought it was an HTTP POST command with parameters, and that the word “message” may have been part of the syntax.

Hi @contractorwolf, I believe this is the documentation you’re looking for:

http://docs.spark.io/#/api

oh @zach, that is exactly what I needed. Thank you. I love this thing, when can I buy more?

1 Like

actually one more question, how do i read a variable that is a String? your example in the docs reads an int and has the definition like this:

Spark.variable("temperature", &temperature, INT);

but will i be able to do a string in a similar way?

Spark.variable("message", &message, STRING);

Right now Spark.variable() only accepts integers; we are working on adding functionality for other variable types.

ok, no worries, for now I can work around this. When will we be able to buy more?

You can buy more on our website (spark.io), but they’re on back-order until January while we produce our second manufacturing run. Starting in January they should be available for immediate purchase.

I’m trying the two LED example, Reading the api is like reading greek [geek]
I am a hardware dude, your info is truncated and sparse

if i put the command line into the browser I get

POSTING into command line of browser
https://api.spark.io/v1/devices/53ff6c065067544814310587/test1 \ -d access_token=43fd95f4fa5a8030c058186973a111809920dd81 -d params=l1,HIGH

{
“code”: 400,
“error”: “invalid_request”,
“error_description”: “The access token was not found”
}

I have gotten the token and device ID twice

How about a complete html page with all the bells and whistles so I don’t have to guess what you are talking about?
how about a button and an indicator for the device?

Hi there!

For me exactly the same issue…

Grtz Hamel

Keep up the good work!

@sobellinni It looks like the problem is that you're using the \ in the wrong place. We use the \ to denote a new line, but if you don't actually have a new line, then it confuses curl. Remove the backslash and it should work fine.

@Hamel this might work for you too, but it would depend on your curl request; if this doesn't fix it for you, copy/paste your request in this window and I can help debug for you as well.

Hi Zach,

My request looks like this:

https://api.spark.io/v1/devices/48ff6e065067555032411187/test -d access_token=386e13deb963955387edfac23cd5b77a1eba7132 -d params=rc,FORWARD

This is what I get in my browser:

{
“code”: 400,
“error”: “invalid_request”,
“error_description”: “The access token was not found”
}

I’ve got the sample RC software flashed on the Core.

Are you pasting this into the browser? Unfortunately that won’t work; You need to use curl or a proper REST API tool to generate these requests.

Is it a simple run command? Im working on a website that will let you control your spark by sending the curl requests.

As I dont have my core I cant test it but you could try it if you want to?

That is my point, curl is yet another piece of frivolous programming jabberwocky that gets in the way of doing what needs to be done, And that is producing an HTML and Javascript/jquery web page that posts commands and Gets data...and this is the first time I've heard of curl

all the -d parts does it add
?hhh=hhh

and the second -d adds
&jjj=jjjj

i have my online code working and submitting access tokens etc. but im getting a { “error”: “Timed out.” } because its not actually doing anything with a real core. if someone wants to allow me to test a basic function on theirs? as access tokens can be changed and i don’t have my core yet to test it.

Hopefully then this util can help the thread creator in his online control quest

@zach if you have one i can test this with it would be great? i will gladly make the util fully open to everyone on this site, but before i add in more coding it would be nice to check the curl posts work properly

Thanks,
Jamie

EDIT:
Seems it should be working, when i check a curl error given from the time out i get this
Curl error:
{ “id”: "
", “name”: "", “last_app”: null, “connected”: true, “return_value”: { “Error”: “Something went wrong calling this function: Unknown Function: test” } }

so i take it the connections are working, i used you sample code you listed above @Hamel, hope you don’t mind? but it seems using my util i can get your request to work

curl is a very common method for generating HTTP requests from the command line:

jQuery can generate the same requests through $.ajax, and every modern language has some simple mechanism for generating these same types of requests. We’ll be developing our own language wrappers as well.

If you’re looking for a website for posting commands and getting data, check out this tool created by a community member:

http://jflasher.github.io/spark-helper/

very similar to what i’m doing except i am building it to store the actions. i was intending to use it for my light controller, but may aswell release it to everyone else

That’s awesome, please do! Looking forward to seeing it. Persistence between sessions would be a great feature

Would you like to personally test it zach? You will do a better job then me as my spark isnt here :slight_smile: best to get it tested before I properly release it to everyone

No problem @bigjme.

@zach curl is a new thing for me. But no worries I will get it working :smile: Thanx for your support so far!