Last active
August 29, 2015 14:23
-
-
Save ahmedsa1983/ef94c5a37ec982a57ab6 to your computer and use it in GitHub Desktop.
Get an event data from a Spark core using NodeJS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*jslint node: true */ | |
"use strict"; | |
var spark = require('spark'); | |
var fs = require('fs'); | |
spark.on('login', function() { | |
//Get test event for specific core | |
spark.getEventStream('MyEvent', '00000000000000000', function(data) { | |
console.log("New Event: " + JSON.stringify(data) + ". Logging it to file"); | |
fs.appendFile('Carpet1 Sensors Data.txt', data.data + "," + | |
data.published_at + "," + data.name + "\r\n", function (err) { | |
if(err) | |
console.log("File log failure. Error = " + JSON.stringify(err)); | |
else | |
console.log("File log success"); | |
}); | |
}); | |
}); | |
// Login as usual | |
spark.login({ username: 'Myemail@gmail.com', password: 'MyPassword'}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I can't test this, but just a shot in the dark...
/*jslint node: true */
"use strict";
var spark = require('spark');
var fs = require('fs');
spark.on('login', function() {
//Get test event for specific core
spark.getEventStream('MyEvent', '00000000000000000', function(data) {
console.log("New Event: " + JSON.stringify(data) + ". Logging it to file");
});
// Login as usual
spark.login({ username: 'Myemail@gmail.com', password: 'MyPassword'});
I tried to find documentation on published_at but I couldn't find any. It seems like if you are getting a GMT or UTC string, you could just convert it to a date object and the do the conversion to local time. If it is already a Date object it should be even more simple, but I assume that the solution isn't as simple as it seems to me. What have you already tried? You said that you tried the toLocalString() method... what were the results? Did you get an error?
I'm sorry if this doesn't help.