@izmevid yep, you can grab as many variables as you need. Just change the return value of callApi() to something like List<String> or Map<String, String> (etc), make all the calls you need and build up the composite return value as you go.
e.g.:
(warning: I’m doing this from memory, so this snippet may not actually compile, but you get the picture )
Async.executeAsync(ParticleCloud.get(MainActivity.this), new Async.ApiWork() {
@Override
public Map<String, String> callApi(ParticleCloud sparkCloud) throws ParticleCloudException, IOException {
sparkCloud.logIn("-----", "------");
sparkCloud.getDevices();
mDevice = sparkCloud.getDevice("------");
Map<String, String> returnVals = new ArrayMap<>();
for (String var : new String[] {"foo", "bar"}) {
try {
value = mDevice.getStringVariable(var);
returnVals.put(var, value);
} catch (ParticleDevice.VariableDoesNotExistException e) {
Toaster.s(MainActivity.this, "Error reading variable " + var);
}
}
return returnVals;
}
@Override
public void onSuccess(Map<String, String> values) {
// do whatever with returned values
}
@Override
public void onFailure(ParticleCloudException e) {
Toaster.l(MainActivity.this, e.getBestMessage());
e.printStackTrace();
Log.d("info", e.getBestMessage());
}
});
I just tried out your code and with a little bit of modification it worked fine when compiling but when using this app instead of the one, which was just reading one variable, the Electron turns into blinking red when I want to get the variables (did work fine with one variable). Maybe something is wrong with my Electrons program which doesn’t quite make sense for me because it worked out fine with one variable as well. Do you know what the problem could be?
You need to make the base variables global and setup the Particle.variable() in setup().
And the three parameter overload of Particle.variable() is outdated anyway (and didn’t work on String objects either).
Not the function is outdated but the three parameter overload
Particle.variable("varName", strVar, STRING); // outdated/deprecated (and without ampersand for strings!)
Particle.variable("varName", strVar); //that's the way to do it now