Long running listener?

It’s time to write the web front/back end for my project. What I would like to do is keep track of all the events that the core is publishing (and possibly trigger time-based alerts). I see that the Cloud API uses SSE to monitor events. Is the idea that I will have a long-running demon that subscribes to the desired events and adds to the database?

I do believe that is the current idea. I’m not even sure if Spark stores events on their own severs for any length of time.

I’ve been using node.js to listen for events and log them locally into a MySQL database

There is also a coming feature called Webhooks, currently in beta, that I think will be more suitable that SSE for server-back-end monitoring of events published by cores. Spark employee Dave know more.

This is exactly what I need to do next. Is your code to do this on git? If not would you please publish it here?

I saw references to webhooks somewhere in the documentation. It talked about those coming in March, and given it’s October, I am guessing that was last March :smile: Let’s see when we get those.

@philipq here is what I have dug up so far for listening to events.

var EventSource = require('eventsource');

var deviceID = "xxxxxxxxxxxxxxxxxxxxxxxx";
var accessToken = "xxxxxxxxxxxxxxxxxxxxxxxx";

var url = "https://api.spark.io/v1/devices/" + deviceID + "/events?access_token=" + accessToken;

console.log("Listening on " + url + " ...");

var es = new EventSource(url);

es.addEventListener('event1', function(e){
	console.log("Event 1");
	console.log(e.data);
}, false);

es.addEventListener('event2', function(e){
	console.log("Event 2");
	console.log( e.data);
}, false);

If I find a few minutes tonight I will put it and reply here

Ok. Here a gist of what I’ve got working. https://gist.github.com/harrisonhjones/c22c300f6458c54d8c24

Interestingly it seems that events published in the “SETUP” don’t appear to fire… What’s up with that?

webhooks are in private beta, if you’re interested in participating, talk to @dave!

Thanks @zach, I’ll send him a message.

Thanks @thebitguru and @harrisonhjones that’s a great help to me