Cloud variables not updating

Hi All,

I am working on a fairly simple app that uses a couple of cloud variables which, as per the documentation I am setting up in the setup area like so:

Spark.variable("agvalues", &agvalues, STRING);
Spark.variable("ax", &ax, INT);

The issue is that in a past life of this build ‘agvalues’ was referred to ‘gyro’ and was the only variable and for some reason ‘particle list’ can only see ‘gyro’ rather than the two currently declared variables, I am willing to believe I am doing something stupid I just need someone to point it out :stuck_out_tongue:

Thanks guys

When you have string Spark (Particle) variable, you don’t need the “&” so you should try this:

Spark.variable("agvalues", agvalues, STRING);
1 Like

I tried that a couple builds ago but no dice I’m afraid :confused:

Hi. Have you solved this? I can’t see Particle.variables in my dashboard too

@matheist, can you share your code where you setup and use the Particle.variables()?

double t = 0;
double rh = 0;

void setup(){
  Serial.begin(57600);
  sensor.begin();
  delay(5000);
  Blynk.begin(auth);
  Particle.variable("Temp", &t, DOUBLE);
  Particle.variable("Humid", &rh, DOUBLE);

  }

void loop(){
    Blynk.run();
    float rh = sensor.getRH();
    float t = sensor.getTemp();
    Blynk.virtualWrite(V5, t);
    Blynk.virtualWrite(V6, rh);
    delay(10000);
}

Blynk catches everything fine, but dashboard says “No variables found on device.

Nowadays the syntax has been simplified to this

  Particle.variable("Temp", t);
  Particle.variable("Humid", rh);

and put this to the top of your setup().

The delay() and the Blynk stuff will take too long and the time window for the variable registration will have closed by the time you execute the instructions.

Also to stay responsive for Blynk, I’d change your loop() this way

void loop(){
    static uint32_t msDelay = 0;
    Blynk.run();
    if (millis() - msDelay < 10000) return;
    msDelay = millis();

    float rh = sensor.getRH();
    float t = sensor.getTemp();
    Blynk.virtualWrite(V5, t);
    Blynk.virtualWrite(V6, rh);
}
1 Like

That worked. Thank you guys. You are awesomely helpful for beginners as always!

2 Likes

I had 0 values stored in the variables unless put Particle.variable in the end of the loop. Now it works fine, but isn’t there an overcoding?

What do you mean by this. Can you show your “working” code?

double t = 0;
double rh = 0;

void setup(){
  Particle.variable("Temp", t);
  Particle.variable("Humid", rh);
  Serial.begin(57600);
  sensor.begin();
  delay(5000);
  Blynk.begin(auth);

  }

void loop(){
    Blynk.run();
    double rh = sensor.getRH();
    double t = sensor.getTemp();
    Blynk.virtualWrite(V5, t);
    Blynk.virtualWrite(V6, rh);
    Particle.variable("Temp", t);
    Particle.variable("Humid", rh);
    delay(10000);
}

This works. But when i remove Particle.variables from the loop, dashboard’s GET returns both “0”.

@matheist, those should not be there. Use @ScruffR’s loop() code he posted above with the millis() delay in order to remove the delay(10000);.

@matheist, there is an issue with your local variables t & rh hiding the global ones.

Remove the data type from loop() like this

void loop(){
    static uint32_t msDelay = 0;
    Blynk.run();
    if (millis() - msDelay < 10000) return;
    msDelay = millis();

    rh = sensor.getRH();
    t = sensor.getTemp();
    Blynk.virtualWrite(V5, t);
    Blynk.virtualWrite(V6, rh);
}
2 Likes

Done that. Variables return zeroes. But when i return them into loop, they’re published ok =\

loop() is absolutely not the place for Particle.variable(), full stop.

Have you waited about 10sec before you first checked the variables?

Alternatively try this

void loop(){
    static uint32_t msDelay = 0;
    Blynk.run();
    if (msDelay != 0 && millis() - msDelay < 10000 ) return;
    msDelay = millis();

    rh = sensor.getRH();
    t = sensor.getTemp();
    Blynk.virtualWrite(V5, t);
    Blynk.virtualWrite(V6, rh);
}
2 Likes

Right now the code is

double t = 4;
double rh = 0;

void setup(){

  Particle.variable("Temp", t);
  Particle.variable("Humid", rh);
  Serial.begin(57600);
  sensor.begin();
  //delay(5000);
  Blynk.begin(auth);

  }

void loop(){
    static uint32_t msDelay = 0;
    Blynk.run();
    if (msDelay != 0 && millis() - msDelay < 10000 ) return;
    msDelay = millis();
    
    double rh = sensor.getRH();
    double t = sensor.getTemp();
    Blynk.virtualWrite(V5, t);
    Blynk.virtualWrite(V6, rh);
}

I’ve set t=4 to parse if it changes. And dashboard says that variable Temp is constantly 4. No changes. At the same time Blynk variable t changes normally.

You didn’t read what I wrote

You still have double in your loop() definition of t and rh, hence you are still hiding the exposed global variables with local ones and hence never updating the global variables which you have exposed via Particle.variable()

Look closely at my code and compare with yours!

2 Likes

Yep. Solved. My bad.

2 Likes