Constant eventsStream

Hello guys.

just started to learn particle-api-js and im sorry if this have been asked before but i could not find anything about it.
I guess i am doing something wrong with credentials.

I tested this function.

//Get all events
particle.getEventStream({ auth: token}).then(function(stream) {
  stream.on('event', function(data) {
    console.log("Event: " + data);
  });
});

This get my console to go nut with events from all kind of coreid’s out there.
Makes me wonder how the access_token works.
I thought when i had that one it would only show the devices that i have claimed to my accounts but i guess not.

So my question would be what data i need to use to only get events from devices that is claimed by my account as the cloud do?

Here is my full code

var Particle = require('particle-api-js');
var particle = new Particle();
var token;



particle.login({username: '', password: ''}).then(
  function(data){
    console.log('API call completed on promise resolve: ', data.body.access_token);
    token = data.body.access_token;
    console.log('token data: ', token);

    var devicesPr = particle.listDevices({ auth: token });

    devicesPr.then(
      function(devices){
        console.log('Devices: ', devices);
      },
      function(err) {
        console.log('List devices call failed: ', err);
      }
    );

    //Get device events
    particle.getEventStream({ auth: token }).then(function(stream) {
      stream.on('event', function(data) {
        console.log("Event: " + data.coreid);
      });
    });
  },
  function(err) {
    console.log('API call completed on promise fail: ', err);
  }
);

BR
Emilkl

You need to specify deviceId:‘mine’ in the getEventStream request, literally ‘mine’ for all of your devices or you can list a specific device id, otherwise you get all public events.

particle.getEventStream({ deviceId: 'mine', auth: token }).then(function(stream) {
  stream.on('event', function(data) {
    console.log("Event: " + data);
  });
});

https://docs.particle.io/reference/javascript/

1 Like

aa is that so. I thought the deviceId: ‘mine’ part just represented, change out “mine” to your own deviceId :slight_smile:
Thank you rickaas7 for clarifying.

BR
Emilkl