From dca344d2372178df8aa10999e3c9fa647fe0b31d Mon Sep 17 00:00:00 2001 From: Mathieu Maret Date: Sat, 10 Sep 2022 22:44:01 +0200 Subject: [PATCH] Add method to cound number of subscription --- Adafruit_MQTT.cpp | 12 ++++++++++++ Adafruit_MQTT.h | 3 +++ 2 files changed, 15 insertions(+) diff --git a/Adafruit_MQTT.cpp b/Adafruit_MQTT.cpp index 5357fb2..de4e91f 100644 --- a/Adafruit_MQTT.cpp +++ b/Adafruit_MQTT.cpp @@ -890,6 +890,18 @@ uint8_t Adafruit_MQTT::disconnectPacket(uint8_t *packet) { return 2; } +uint Adafruit_MQTT::getSubscriptionCount() +{ + uint count = 0; + + for (int i = 0; i < MAXSUBSCRIPTIONS; i++) { + if (subscriptions[i]) + count++; + } + + return count; +} + // Adafruit_MQTT_Publish Definition //////////////////////////////////////////// Adafruit_MQTT_Publish::Adafruit_MQTT_Publish(Adafruit_MQTT *mqttserver, diff --git a/Adafruit_MQTT.h b/Adafruit_MQTT.h index 1bfac20..f29a98b 100644 --- a/Adafruit_MQTT.h +++ b/Adafruit_MQTT.h @@ -218,6 +218,9 @@ public: // Ping the server to ensure the connection is still alive. bool ping(uint8_t n = 1); + // Count the number of registrered Adafruit_MQTT_Subscribe + uint getSubscriptionCount(); + protected: // Interface that subclasses need to implement: