Example #1
0
 Device.getHeightTemp = function (deviceId, cb) {
     particle.getVariable({ deviceId: deviceId, name: 'heightTemp', auth: tm.getAccessToken() }).then(function (data) {
         cb(null, data.body.result);
     }, function (err) {
         console.log('getHeightTemp error!');
         cb(null, null);
     });
 };
Example #2
0
 Device.getTimeDelay = function (deviceId, cb) {
     particle.getVariable({ deviceId: deviceId, name: 'timeDelay', auth: tm.getAccessToken() }).then(function (data) {
         cb(null, data.body.result);
     }, function (err) {
         console.log('timeDelay error!');
         cb(null, -1);
     });
 };
Example #3
0
 // Retrieves the number of spots each particle photon is keeping track of
 function getNumVariable(id) {
   particle.getVariable({ deviceId: id, name: "num_vars", auth: AUTH_TOKEN }).then(function(data) {
                             result = data.body.result;
                             for(var i = 0; i < result; i++) {
                               var spot = "spot_" + i;
                               getDataFromParticleCloud(spot, id);
                             }
                           }, function(err) {});                          
 }
Example #4
0
 function (data) {
     if (data.body.return_value == 1) {
         particle.getVariable({ deviceId: deviceId, name: 'enviCurrent', auth: tm.getAccessToken() }).then(function (data) {
             cb(null, data.body.result);
         }, function (err) {
             console.log('getInfoEnv error!');
             cb(null, null);
         });
     }
 }, function (err) {
function getLightOn (callback) {
  var particle = new Particle();
  particle.getVariable({ deviceId: deviceId, name: 'lightOn', auth: token }).then(
    function(data){
      var value = data.body['result'];
      callback(null, value);
    }, 
    function(err) {
        console.log('An error occurred while getting attrs:', err);
        callback(err);
    }
  );
}
Example #6
0
    // Need a global flag for sampling each spot according to the variable
    function getDataFromParticleCloud(variable, id) {
        particle.getVariable({ deviceId: id, name: variable, auth: AUTH_TOKEN }).then(function(data) {
                                //console.log('Device variable retrieved successfully:', data.body.result);
                                // Setting the values according to new format
                                //var date = data.body.coreInfo["last_heard"].split(".");
                                //date = date[0];
                                //console.log("date is now: " + date);
                                firebaseEntry(id, "date", variable, data.body.result);

                              }, function(err) {
                                //console.log('An error occurred while getting attrs:', err);
                              });                        
    }
Example #7
0
  pg.connect(connectionString, function(err, client, done){
     particle.getVariable({ deviceId: '230043001347343339383037', name: 'RMSwattage', auth: 'fee27c1ec9f8c9dbd8188886f4f60c995aabfbd6' }).then(function(data) {
         //console.log('Device variable retrieved successfully:', data);
         var body = data.body;
         var val = numeral(body.result).format('0.0')
         var date = moment.utc(body.coreInfo.last_heard).tz('America/New_York').format('D MMM h:mma z');
         if(err) {
             done();
             console.log(err);
             return res.stats(500).json({success: false, data: err});
         }
         var body = data.body;
         client.query("INSERT INTO currentvalues(deviceid, timeread, rmscurrent) values($1, $2, $3)", 
             [body.coreInfo.deviceID, body.coreInfo.last_heard, body.result]);
             res.render('partials/home', {deviceIDToaster: body.coreInfo.deviceID, timestampToaster: date, wattageToaster: val});
             return res.status(200).json({ success: true, data: 'RMScurrent added!'});
         }, function(err) {
           console.log('An error occurred while getting attrs:', err);
         });
 });
Example #8
0
router.post('/api/v1/rmscurrent', function(req, res) {
    
    particle.getVariable({ deviceId: '39003f000247343339373536', name: 'RMSwattage', auth: 'fee27c1ec9f8c9dbd8188886f4f60c995aabfbd6' }).then(function(data) {
      //console.log('Device variable retrieved successfully:', data);

      pg.connect(connectionString, function(err, client, done){
        if(err) {
            done();
            console.log(err);
            return res.stats(500).json({success: false, data: err});
        }
        var body = data.body;
        client.query("INSERT INTO currentvalues(deviceid, timeread, rmscurrent) values($1, $2, $3)", 
            [body.coreInfo.deviceID, body.coreInfo.last_heard, body.result]);
        return res.status(200).json({ success: true, data: 'RMScurrent added!'});
      });

    }, function(err) {
      console.log('An error occurred while getting attrs:', err);
    });
});