So, here’s my “playground” for trying to accomplish my goal of being able to call meteor methods from within particle-api-js getEventStream() using 1.2…
if (Meteor.isServer) {
var Particle = Meteor.npmRequire('particle-api-js');
var particle = new Particle();
var particleLogin = particle.login({
username: 'USERNAME',
password: 'PASSWORD'
});
particleLogin.then(function (data) {
return data.body.access_token;
}).then(function (token) {
console.log(token);
return particle.getEventStream({
deviceId: 'DEVICE_ID',
auth: token
});
}).then(function (stream) {
stream.on('event', function (data) {
var eventString = data.name + ": " + data.data;
console.log(eventString);
});
});
}
The console.log() works, but I get an error whenever I try to call a meteor method or insert into a mongo db.
I had a working example using spark, but it quit working in the past week - “An error occurred while getting core attrs: [Error: invalid_token]”