0

Adafruit IO Arduino Subscription Bug?
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Adafruit IO Arduino Subscription Bug?

by sellensr on Sun Nov 12, 2017 4:35 pm

The adafruit_01_subscribe example sketch works great as is, but the subscription fails with these minor changes around the setup.
It seems to be sensitive to the timing of the interactions attaching the feed and the subscription. It fails if you wait until the connection is established. It looks like all the feeds/subs need to be attached before the connection is completed.

Code: Select all | TOGGLE FULL SIZE
// set up the 'counter' feed
//AdafruitIO_Feed *counter = io.feed("counter");
// should be able to declare it publicly here and initialize it later
AdafruitIO_Feed *counter;

void setup() {
  Serial.begin(115200);
  while(! Serial);
  Serial.print("Connecting to Adafruit IO");

  // connect to io.adafruit.com
  io.connect();
  //subscription works if the next two lines are here
  //counter = io.feed("counter");
  //counter->onMessage(handleMessage);

  // wait for a connection
  while(io.status() < AIO_CONNECTED) {
    Serial.print(".");
    delay(500);
  }

  // subscription doesn't work if the next two lines are here instead
  counter = io.feed("counter");
  counter->onMessage(handleMessage);

  // we are connected
  Serial.println();
  Serial.println(io.statusText());

}

sellensr
 
Posts: 41
Joined: Tue Nov 06, 2012 9:41 pm

Please be positive and constructive with your questions and comments.