adafruit / Adafruit_IO_Arduino

Arduino library to access Adafruit IO from WiFi, cellular, and ethernet modules.
Other
209 stars 108 forks source link

Group data is never cleared #122

Open phord opened 4 years ago

phord commented 4 years ago

I have some code like this where I have a single AdafruitIO_Group object that I use to interact with a feed group.

AdafruitIO_WiFi io(IO_USERNAME, IO_KEY, WIFI_SSID, WIFI_PASS);
AdafruitIO_Group *grp = io.group("mygroup");

void setup() {
  grp->onMessage(handleMessage);
  grp->set("FOREVER", "never-comes");
  grp->save();
}

void loop() {
  if (something_happened) {
      grp->set("Temperature", get_temp());
      grp->save();
  }
}

void handleMessage(AdafruitIO_Data *data) { }

Every time I call grp->save(), I find that the AdafruitIO_Data object has all the different feeds in it that it has ever touched, and they all get sent to IO again. It seems like it also has the data received and sent to handleMessage(). Sometimes the data is duplicated, like this:

FOREVER = never-comes
Temperature = 72
forever = never-comes
temperature = 71

One problem is that I don't want to publish every value that I've already sent before when I save. Another is that there are duplicated feeds here. It's not clear to me what will be "saved" when I publish a feed with both "Temperature=72" and (keyname) "temperature=71" in the data collection.

It's important to me that I don't Publish old values that might now be stale. This scenario would create a race between my Published updates and the dashboard updates I could receive, but it doesn't give me any clear option to avoid this race.

I can work around this by creating a new Group object every time I want to publish, but it wasn't clear to me that this was required from the docs, and this behavior is unexpected.