@kennethlimcp, the following data source should work
(function () {
var sseDatasource = function (settings, updateCallback) {
var self = this;
var currentSettings = settings;
this.updateNow = function () {
var eventSource = new EventSource("https://api.spark.io/v1/devices/" + currentSettings.deviceId + "/events/?access_token=" + currentSettings.accessToken);
eventSource.addEventListener('open', function(e) { },false);
eventSource.addEventListener('error', function(e) { },false);
eventSource.addEventListener(currentSettings.event_name, function(e) {
var parsedData = JSON.parse(e.data);
updateCallback(parsedData.data);
}, false);
}
this.onDispose = function () {
}
this.onSettingsChanged = function (newSettings) {
currentSettings = newSettings;
self.updateNow();
}
};
freeboard.loadDatasourcePlugin({
"type_name": "SSE",
"display_name": "SSE",
"settings": [
{
name: "deviceId",
display_name: "Device ID",
description: 'Spark Core Device ID.',
type: "text",
},
{
name: "accessToken",
display_name: "Access Token",
description: 'Spark Core Access Token.',
type: "text",
},
{
name: "event_name",
display_name: "Event Name",
description: 'Event Name.',
type: "text",
}
],
newInstance: function (settings, newInstanceCallback, updateCallback) {
newInstanceCallback(new sseDatasource(settings, updateCallback));
}
});
}());
I downloaded the Freeboard.io and added this plugin. It is working for me, let me know it works for you