1
0
mirror of https://github.com/adafruit/Adafruit_MQTT_Library.git synced 2025-06-11 22:48:09 +03:00

Fix Adafruit_MQTT:subscribe()

This method contained a loop that checked for an existing subscription,
but it only printed a debug message if so. Now, it immediately returns
true if the subscription is already registered.

When this method succesfully adds a subscription, it was documented to
return true, but the actual code did not return anything in this case,
resulting in a compiler warning. In practice, on AVR, the value of the
first argument would be returned, which likely evaluates as true, so
it is likely it actually seemed to work fine.
This commit is contained in:
Matthijs Kooijman
2015-07-02 13:28:38 +02:00
parent 564e87ff36
commit b996b096b3
2 changed files with 6 additions and 7 deletions

View File

@ -176,7 +176,7 @@ bool Adafruit_MQTT::subscribe(Adafruit_MQTT_Subscribe *sub) {
for (i=0; i<MAXSUBSCRIPTIONS; i++) {
if (subscriptions[i] == sub) {
DEBUG_PRINTLN(F("Already subscribed"));
break;
return true;
}
}
if (i==MAXSUBSCRIPTIONS) { // add to subscriptionlist
@ -184,14 +184,13 @@ bool Adafruit_MQTT::subscribe(Adafruit_MQTT_Subscribe *sub) {
if (subscriptions[i] == 0) {
DEBUG_PRINT(F("Added sub ")); DEBUG_PRINTLN(i);
subscriptions[i] = sub;
break;
return true;
}
}
}
if (i==MAXSUBSCRIPTIONS) {
DEBUG_PRINTLN(F("no more subscription space :("));
return false;
}
DEBUG_PRINTLN(F("no more subscription space :("));
return false;
}
Adafruit_MQTT_Subscribe *Adafruit_MQTT::readSubscription(int16_t timeout) {