void loop()

in arduino/plant_reference.ino [40:83]


void loop()
{
  if (!otaInProgress) {
    do {
      expresslinkExecuteCommand("AT+Event?\n");

      if (startsWith(expresslinkResponse, "OK 3", 4)) {
        expresslinkExecuteCommand("AT+CONNECT\n");
        while (!startsWith(expresslinkResponse, "OK", 2)) {
          Serial.printf("Attempting to reconnect\n");
          expresslinkExecuteCommand("AT+CONNECT\n");
        }
      } else if (startsWith(expresslinkResponse, "OK 24", 5)) {
        updateShadow();
      } else if (startsWith(expresslinkResponse, "OK 5", 4)) {
        ota();
      }
    } while (startsWith(expresslinkResponse, "OK ", 3));

    // get and send data every 5 min
    if (millis()-lastDataSend >= sendInterval) {
      lastDataSend = millis();
      getData();
      sendData();
    }
  }

  if (otaInProgress || awaitingOTAResponse) {
    ota();
  }

  if (waterOn) {
    if (millis()-pumpStart >= pumpDuration) {
      sendShadowCommandSeq("AT+SHADOW1 UPDATE {\"state\":{\"desired\":{\"water\": \"off\" } } }\n",
                           "AT+SHADOW1 GET UPDATE\n",
                           "OK 1",
                           "OK 0");
    } else if(!otaInProgress && !awaitingOTAResponse) {
      delay(pumpDuration);
    }
  } else if (!otaInProgress && !awaitingOTAResponse) {
    delay(sendInterval-(millis()-lastDataSend)); //adjust sleep to ensure data sent every sendInterval
  }
}