0

I need your guys help on this. Is there any way to call a local variable outside a function?

Code

var ubidots = require('ubidots');
var client = ubidots.createClient('***API Key***');

var overview = client.auth(function () {

    var tempData = this.getVariable('**Key**');                     // Temperature Variable ID 
    var humidData = this.getVariable('**Key**');                    // Humidity Variable ID
    var lightData = this.getVariable('**Key**');                    // Light Variable ID
    var soilData = this.getVariable('**Key**');                     // Soil Moisture Variable ID 

        tempData.getValues(function (err, data) {  
            var tempValue = data.results[0].value;
        });

        humidData.getValues(function (err, data) {  
            var humidValue = data.results[0].value;
        });

        lightData.getValues(function (err, data) {  
            var lightValue = data.results[0].value;
        });

        soilData.getValues(function (err, data) {  
            var soilValue = data.results[0].value;
        });

});

console.log(tempValue);
console.log(humidValue);
console.log(lightValue);
console.log(soilValue);

How can I prrint out the value of tempValue, humidValue, lightValue& soilValue ?

Your help is much appriciated!

Michael
  • 23
  • 2
  • If `client.auth` is asynchronous (and it wouldn't make sense for it to take a callback if it weren't), your answers are here: [*How do I return the response from an asynchronous call?*](https://stackoverflow.com/questions/14220321/how-do-i-return-the-response-from-an-asynchronous-call) – T.J. Crowder Sep 09 '17 at 09:57
  • Have you tried defining your variables outside the function? – cl3m Sep 09 '17 at 09:57

0 Answers0