You have to do this with a POST request, and the data you want to send is
message=winning
If this still doesnāt make sense, try pasting your spark.js into a gist: https://gist.github.com/
and share the URL to the gist here. Then someone can help you debug.
Yeah, thatās a general guidance rule about REST APIs. The only GET request documented in the API right now is the SSE route (e.g., https://api.sprk.io/v1/devices/elroy_box/events) which you can try and see that the connection stays open, but thereās no core sending any data to that stream. The two routes for controlling a device are POST requests.
Oh come on⦠you guys donāt have a Spark Core in a closet somewhere spitting out digits of Pi?
Will there be a more simple GET request that we can just query a snapshot of the pins, or even one specific pin?
Also so far I kind of have POST requests working with the ārequestā library, but Nodeās built in āhttpsā library is complaining a lot! Iāll keep debugging⦠this is how I learn.
What kind of response should I get from sending { āmessageā: āwinningā } ?
Currently Iām getting
{
"ok": false,
"errors": [
"No valid pin or custom message found"
]
}
My code:
var request = require('request');
request.post(
'https://api.sprk.io/v1/devices/elroy',
//{'pin':'D0', 'level':'HIGH'},
{'message':'winning'},
function (error, response, body) {
if (!error && response.statusCode == 200) {
console.log(body);
}
else
console.log('ERROR: '+error+' '+response+' '+body);
}
);
You can see how I tried to set the pin high as well⦠I get the same response with that one. Probably something Iām not understanding about the request library yet.
Ok, I got it working and saw the {āokā: true} response⦠then I cried a bit⦠now Iām all smiles. I can set pins and see the error message when the pin numbering is out of scope. Iāll try to wrap this up into a nice example for anyone that might want to use Node.js
I don't have one either... just passing the time with my addiction to Node.js
Check out this simple Node.js wrapper I whipped up today for the Spark API
Currently supports simple pin setting high/low and custom messages, with callbacks!
digitalWrite(D0,HIGH);
sendMessage('winning');
Right now the examples are at the bottom of the sparkapi.js file. I'll break them out later in a separate examples folder to keep the wrapper clean.
Hopefully I can add the simple GET request for digitalRead() when Spark documents it. SSE Streaming is cool, but I'm not sure how to handle it well yet.
Thatās where I recognize your name from! I was like⦠dang I know this guy. I just retired from a year of TT.FM and well over 10,000 lines of code for many different projects there.