Loop and publish variable

I am having a little trouble with the looping of a variable being published. In short I am unable to adjust the time between publishing, either it doesn’t publish or it publishes ever hour.

I have tried delay, sleep and time now with set wait times.

Current firmware I am running is below;

int analogvalue = 0;
int boardLed = D7; // LED
int moister_value = 0;
char *message = "Kentia_P02";

void setup()
  Particle.variable("Unit", message, STRING);
  pinMode(A1, INPUT);

void loop()
    analogvalue = analogRead(A1);
    moister_value = (100 - ( (analogvalue/4095.00) * 100 ) ); // read capacitive sensor
    Particle.variable("moister", &moister_value, INT);
    // put device to sleep for 1 hours (3600 seconds)

I’d be grateful if someone can put me on the right track.

Particle.variable() is not to be called multiple times for the same variable.
You register a global variable (or function) once in setup() and from then on whenever the cloud requests that variable the value of that variable/function will be sent back.

Also a Particle.variable() is never published/pushed but needs to be requested.
If you want to push data you’d use Particle.publish() (at a rate of no more than 1/second).

BTW, your syntax is outdated.
The correct (current) form is Particle.variable("moister", moister_value);

In addition: Have you tried researching that question in the forum before posting?
This topic has come up and been answered numerous times before already :wink:



This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.