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:
parent
564e87ff36
commit
b996b096b3
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Adafruit_MQTT_Subscribe *Adafruit_MQTT::readSubscription(int16_t timeout) {
|
||||
|
@ -127,7 +127,7 @@ class Adafruit_MQTT {
|
||||
bool publish(const char *topic, const char *payload, uint8_t qos);
|
||||
|
||||
// Add a subscription to receive messages for a topic. Returns true if the
|
||||
// subscription could be added, false otherwise.
|
||||
// subscription could be added or was already present, false otherwise.
|
||||
bool subscribe(Adafruit_MQTT_Subscribe *sub);
|
||||
|
||||
// Check if any subscriptions have new messages. Will return a reference to
|
||||
|
Loading…
Reference in New Issue
Block a user