[Photon] Lost .publish data

I’m using a photon w/ relay shield with 5 capacitive moisture sensors.
I’m trying to publish the sensor values, which can later be taken to IFTTT for push notifications.
However, I am only receiving 4 sensor values, on the web ide events page. The 5th sensor (sensorvalue4) is not getting uploaded.
Am I trying to push too much data at once? Please help.

Thanks in advance,

#define THRESHOLD          2200
#define SENSOR_PIN0          A0
#define SENSOR_PIN1          A1
#define SENSOR_PIN2          A2
#define SENSOR_PIN3          A3
#define SENSOR_PIN4          A4
#define TEXTING_INTERVAL    1800000 //30 minutes (1000ms * 60s * 30mins)
int sensorvalue0 = 0;
int sensorvalue1 = 0;
int sensorvalue2 = 0;
int sensorvalue3 = 0;
int sensorvalue4 = 0;
unsigned long lastTextTime = 0;
unsigned long previousMillis = 0;

void setup() {
    pinMode(SENSOR_PIN0, INPUT);
    pinMode(SENSOR_PIN1, INPUT);
    pinMode(SENSOR_PIN2, INPUT);
    pinMode(SENSOR_PIN3, INPUT);
    pinMode(SENSOR_PIN4, INPUT);

Particle.variable("sensor0", sensorvalue0);
Particle.variable("sensor1", sensorvalue1);
Particle.variable("sensor2", sensorvalue2);
Particle.variable("sensor3", sensorvalue3);
Particle.variable("sensor4", sensorvalue4);

void loop() {

  unsigned long currentMillis = millis();

  if((currentMillis - previousMillis) >= 5000) {
    previousMillis = currentMillis;  // Remember the time
    sensorvalue0 = analogRead(SENSOR_PIN0);
    sensorvalue1 = analogRead(SENSOR_PIN1);
    sensorvalue2 = analogRead(SENSOR_PIN2);
    sensorvalue3 = analogRead(SENSOR_PIN3);
    sensorvalue4 = analogRead(SENSOR_PIN4);

      if (sensorvalue0 > THRESHOLD) {
      Particle.publish("0 Water Me Now!", String( sensorvalue0));
      else {
      Particle.publish("0Adequate soil moisture", String( sensorvalue0));

        if (sensorvalue1 > THRESHOLD) {
        Particle.publish("1Water Me Now!", String( sensorvalue1));
        else {
        Particle.publish("1Adequate soil moisture", String( sensorvalue1));

          if (sensorvalue2 > THRESHOLD) {
          Particle.publish("2Water Me Now!", String( sensorvalue2));
          else {
          Particle.publish("2Adequate soil moisture", String( sensorvalue2));

            if (sensorvalue3 > THRESHOLD) {
            Particle.publish("3Water Me Now!", String( sensorvalue3));
            else {
            Particle.publish("3Adequate soil moisture", String( sensorvalue3));
              if (sensorvalue4 > THRESHOLD) {
              Particle.publish("4Water Me Now!", String( sensorvalue4));
              else {
              Particle.publish("4Adequate soil moisture", String( sensorvalue4));


The docs do provide the answer to that “riddle”

That’s what we call the publish rate limit and there are many discussions about it :wink:

Adding to ScruffR’s response, you should either combine all 5 sensor readings into one message and parse on the backend, or stagger your reporting times for the sensors by 0.5-1 second. It appears you’re monitoring soil water level, so I wouldn’t expect a plant to go from full to thirsty in a few seconds. :slight_smile:


There is another solution which is to use the PublishQueueAsyncRK library to queue the publish events and then send them at the rate of 1 per second. For now I would combine the sensor readings into one message. IMO it would be better to also stop using the String() object to format your messages and do something like this which will avoid blocking if not cloud connected, avoid string overrun and produce event in a simple JSON format. Note that your Particle.publish did not include the PRIVATE flag which is now necessary.

char dataStr[255];
snprintf(dataStr, sizeof(dataStr), "{\"SV1\":\"%i\"},{\"SV2\":\"%i\"}", sensorvalue1, sensorvalue2);
if (Particle.connected())
       (void) Particle.publish("SENSORDATA", dataStr, 60, PRIVATE);