dongphusang / Terra

Plant Management
GNU General Public License v3.0
3 stars 0 forks source link

Next Watering Schedule not Updating Properly #41

Closed dongphusang closed 7 months ago

dongphusang commented 7 months ago

Context

dongphusang commented 7 months ago

Solution

// check if current schedule exists
if (schedule_index != -1) {
  // get next_schedule (schedule at next index)
  if (schedule_index == schedules.size() - 1) // if current schedule is at the end, grab the first element
    next_schedule = schedules[0];
  else // if current schedule isn't at the end, grab the next element
    next_schedule = schedules[schedule_index + 1]; 
    // include next_schedule in content
    content.set("fields/NextWateringSchedule/stringValue", std::string(next_schedule).c_str());
    // upload content to firestore
    if (Firebase.Firestore.patchDocument(&fbdo, FIRESTORE_ID, "", path.c_str(), content.raw(), mask.c_str()))
      Serial.printf("ok\n%s\n\n", fbdo.payload().c_str());
    else
      Serial.println(fbdo.errorReason());
}