Trying to connect and establish data streams from 3 Photons on a single server

I’m currently building a sensory suit for an art installation. We have three suits being made that relay user data to a central processing computer. Im looking for a way to connect three photons to said computer with minimal lag while being able to read three independant data streams.

Right now we have four sensors outputting binary values (on/off), and a 9-DOF device that has been trimmed down to three variables. So, I need to transmit 8 variables to my computer (12 char total). Ive had success using a single photon in which I snt the values to the cloud via publish(), and read them onto my computer via Node.js and particle.getEventStream(). But when I try to connect another photon in my Node.js script one is given permission to connect and transmits, but the other has no data being received on the server side.

What would be the best way to move forward? Should I create a dedicated TCP server and use several ports to listen to all three devices simultaneously? I have almost no experience in back-end web development so Im not sure how to do this at all but from the large sum of forums Ive read this seems possible. If theres an efficient (and not terribly difficult) solution the help would be greatly appreciated.

Cheers.

Can you post your NodeJS code?
You should be able to subscribe to multiple event streams concurrently but each stream needs its own object to deal with the it.

Sure thing.

I only have one object as of now so I’ll try adding another in the mean time.

Here it is:

//Require and fetch libraries
var Particle = require('particle-api-js');
const maxApi = require("max-api");

//Create new Particle object
var particle = new Particle();

//auth tokens for Photon
var token = "blank";
var token2 = "blank";

//device IDs for Particle Cloud
var deviceID = "blank";
var deviceID2 = "blank";


     //Get devices event stream
particle.getEventStream({ deviceId: deviceID, auth: token }).then(function(stream) {
  stream.on('SensorFeed', function(data) {
    console.log(" ", data.data);
    maxApi.outlet(data.data);


    //Get your devices events
    particle.getEventStream({ deviceId: deviceID2, auth: token2 }).then(function(stream) {
    stream.on('SensorFeed', function(data) {
    console.log(" ", data.data);
    maxApi.outlet(data.data);

    });
    });

  });
});

Ive updated the code to include two seperate Particle objects with no success. I’m constantly getting one value in the console log. If I nest the functions I get A, If I leave them asynchronous I get B. Any idea how to receive both?

//Require and fetch libraries
var Particle = require('particle-api-js');
const maxApi = require("max-api");
//Create new Particle object
var particle_A = new Particle();
var particle_B = new Particle();
//Photon credentials
var deviceID_A = "3c0025000d473634333xxxx";
var token_A = "7e12b97d44098c05725e3ea3169bbxxxxxxxxxx";
//Photon credentials
var deviceID_B = "3a004f000f5137333133xxxx";
var token_B = "fda54915211d644dab587f37de978axxxxxxxxxx";


     //Get your devices events
particle_A.getEventStream({ deviceId: deviceID_A, auth: token_A }).then(function(stream) {
  stream.on('UptimeA', function(data) {
    // var parsedData = JSON.parse(data.data);
    // console.log('Received data', parsedData.data);
    console.log("A: ", data.data);
    maxApi.outlet(data.data);


    //Get your devices events
    particle_B.getEventStream({ deviceId: deviceID_B, auth: token_B }).then(function(stream) {
    stream.on('UptimeB', function(data) {
    // var parsedData = JSON.parse(data.data);
    // console.log('Received data', parsedData.data);
    console.log("B: ", data.data);
    maxApi.outlet(data.data);

    });
    });


  });
});

Sorry for the late reply.
I noticed you have two different tokens. Does this mean you are subscribing to devices that are not yours?
If all the devices are claimed to your account you should be able to use one token for all devices and since SSE streams can be filtered by prefix you can actually use the same subscription for all events starting with that prefix filtering the origin by means of the entire event name or device ID provided by the even.
You won’t need to filter for the device ID.

But for minimum lag you may without the need for encrypted data transfer TCP or UDP would be much faster.

Try this for a server code

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

//Create new Particle object
var particle = new Particle();

//auth tokens for Photon
var token = "<--yourToken-->";

//Get devices event stream for all MY devices (events published as PRIVATE)
particle.getEventStream({ deviceId: 'mine', auth: token }).then(function(stream) {
  stream.on('SensorFeed', function(data) {
    console.log(" ", data);
  });
});