Hi all,
I am trying to set up a Node.js server by following the JavaScript SDK. However, the challenge I am having is that I don’t want to manually insert the Device ID into the parameters. Is there a way to pass the Device ID from the LIST DEVICES function to the GETATTRIBUTES function or any of the others.
I understand that the LIST DEVICES function returns a Promise, since there maybe multiple devices. Thus, I will have to have a way to store and pass the list of Device ID’s into the other functions, as needed.
If there are any tutorials that walk you through the process, or if anyone has some code that I may be able to look at, I will greatly appreciate any help.
Thank you
My code so far:
var Particle = require('particle-api-js');
var particle = new Particle();
var userName = "";
var passWord = "";
particle.login({username: userName, password: passWord}).then(
function(data){
console.log('API call completed on promise resolve: ', data.body.access_token);
},
function(err) {
console.log('API call completed on promise fail: ', err);
}
);
var token; // from result of particle.login
var devicesPr = particle.listDevices({ auth: token });
devicesPr.then(
function(devices){
console.log('Devices: ', devices);
},
function(err) {
console.log('List devices call failed: ', err);
}
);
/*
var devicesPr = particle.getDevice({ deviceId: 'DEVICE_ID', auth: token });
devicesPr.then(
function(data){
console.log('Device attrs retrieved successfully:', data);
},
function(err) {
console.log('API call failed: ', err);
}
);
*/