Ignored after 15 subscriptions-Adafruit

Hello,

I have made a box to monitor my nodes around the house (like a security control panel) and the program enclosed will give you an idea about the structure. My mqtt server is running on a Pi4 with mosquitto and node-red.

I also have node-red client running on a PC without any problems.

And the problem is my monitor box ignores and subscriptions greater than 15 (out of 20) and swapping subscriptions proved it too. Also played with number inside “while ((subscription = mqtt.readSubscription(5000))) “ with no avail. So I appreciate any help.

// c8:2b:96:2e:d4:89 IP:24
/***************************************************
20/11/23 updated: 28/8/25
Arduino IDE 2.3.4
code for NodeMCU v.3 mqtt_monitor 
using ESP-12E module in IDE boards
pin nmap-
A0    -   
GPIO  D   Device
16    0   N/O
05    1   i2c pcfx4 + oled (https://www.youtube.com/watch?v=ssB6pJ3JH5w&t=22s)
04    2   i2c same
00    3   pulled-up  
02    4   N/O           
14    5   alarmreset (button)
12    6   alarmled (led)
13    7   beeper
15    8   software serial-pulled to ground

****************************************************/

#include <time.h>
#include <ESP8266WiFi.h>
#include <ESP8266mDNS.h>
#include <WiFiUdp.h>
#include <ArduinoOTA.h>
#include "Adafruit_MQTT.h"
#include "Adafruit_MQTT_Client.h"
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include "Arduino.h"
#include "PCF8574.h"
#include <Wire.h>

#define WLAN_SSID       "coke"
#define WLAN_PASS       "withbacardis"
#define AIO_SERVER      "192.168.1.11"
#define AIO_SERVERPORT  1883   
#define AIO_USERNAME    ""
#define AIO_KEY         ""
#define STASSID "coke"
#define STAPSK  "**********"

const int masterledpin = D6;
const int beeppin = D7;
bool SALFLASH = false;
bool firstrun = true;
char message;
int linecounter=0;
int x, minX; 
bool deviceActive = false;
PCF8574 cluster1(0x20); // for dead nodes
PCF8574 cluster2(0x21); // for activity
PCF8574 cluster3(0x22); // for warning
PCF8574 cluster4(0x26); // extra
//Timers
long interval = 50000; 
long interval1 = 120000; 
long screentimer = 30000;
unsigned long previousMillis = 0;
unsigned long previousMillis1 = 0;
unsigned long screentimerMillis = 0;
long intervalive = 180000; 
unsigned long previouslives = 0; 
bool isitdark = true; //activates after time is installed

WiFiClient client;
Adafruit_MQTT_Client mqtt(&client, AIO_SERVER, AIO_SERVERPORT, AIO_USERNAME, AIO_KEY); //Retain requires lots of workaround so prospone

Adafruit_MQTT_Subscribe GUPANICALARM = Adafruit_MQTT_Subscribe(&mqtt, AIO_USERNAME "GUPANICALARM");
Adafruit_MQTT_Subscribe GUTEMPALARM = Adafruit_MQTT_Subscribe(&mqtt, AIO_USERNAME "GUTEMPALARM"); 
Adafruit_MQTT_Subscribe GULDRALARM = Adafruit_MQTT_Subscribe(&mqtt, AIO_USERNAME "GULDRALARM"); 
Adafruit_MQTT_Subscribe WC1PANICALARM = Adafruit_MQTT_Subscribe(&mqtt, AIO_USERNAME "WC1PANICALARM");
Adafruit_MQTT_Subscribe WC1TEMPALARM = Adafruit_MQTT_Subscribe(&mqtt, AIO_USERNAME "WC1TEMPALARM");
Adafruit_MQTT_Subscribe WC2TEMPALARM = Adafruit_MQTT_Subscribe(&mqtt, AIO_USERNAME "WC2TEMPALARM");
Adafruit_MQTT_Subscribe WC1LDRALARM = Adafruit_MQTT_Subscribe(&mqtt, AIO_USERNAME "WC1LDRALARM");
Adafruit_MQTT_Subscribe WC1FLOODALARM = Adafruit_MQTT_Subscribe(&mqtt, AIO_USERNAME "WC1FLOODALARM");
Adafruit_MQTT_Subscribe WRTEMP1ALARM = Adafruit_MQTT_Subscribe(&mqtt, AIO_USERNAME "WRTEMP1ALARM"); 
Adafruit_MQTT_Subscribe WRTEMP2ALARM = Adafruit_MQTT_Subscribe(&mqtt, AIO_USERNAME "WRTEMP2ALARM");
Adafruit_MQTT_Subscribe DETEMPALARM = Adafruit_MQTT_Subscribe(&mqtt, AIO_USERNAME "DETEMPALARM"); 
Adafruit_MQTT_Subscribe DEFLOODALARM = Adafruit_MQTT_Subscribe(&mqtt, AIO_USERNAME "DEFLOODALARM");
Adafruit_MQTT_Subscribe DETOOHIGHALARM = Adafruit_MQTT_Subscribe(&mqtt, AIO_USERNAME "DETOOHIGHALARM");
Adafruit_MQTT_Subscribe DEPUMP = Adafruit_MQTT_Subscribe(&mqtt, AIO_USERNAME "DEPUMP");
Adafruit_MQTT_Subscribe ZETEMPALARM = Adafruit_MQTT_Subscribe(&mqtt, AIO_USERNAME "ZETEMPALARM"); 
Adafruit_MQTT_Subscribe ZELDRALARM = Adafruit_MQTT_Subscribe(&mqtt, AIO_USERNAME "ZELDRALARM"); 
Adafruit_MQTT_Subscribe EBTEMPALARM = Adafruit_MQTT_Subscribe(&mqtt, AIO_USERNAME "EBTEMPALARM"); 
Adafruit_MQTT_Subscribe EBLDRALARM = Adafruit_MQTT_Subscribe(&mqtt, AIO_USERNAME "EBLDRALARM"); 
Adafruit_MQTT_Subscribe SATEMPALARM = Adafruit_MQTT_Subscribe(&mqtt, AIO_USERNAME "SATEMPALARM"); 
Adafruit_MQTT_Subscribe SALDOORALARM = Adafruit_MQTT_Subscribe(&mqtt, AIO_USERNAME "SALDOORALARM"); 
Adafruit_MQTT_Subscribe SALLDRALARM = Adafruit_MQTT_Subscribe(&mqtt, AIO_USERNAME "SALLDR"); 
Adafruit_MQTT_Subscribe MUTEMPALARM = Adafruit_MQTT_Subscribe(&mqtt, AIO_USERNAME "MUTEMPALARM"); 
Adafruit_MQTT_Subscribe IDLDRALARM = Adafruit_MQTT_Subscribe(&mqtt, AIO_USERNAME "IDLDRALARM");

//local vars to be used later for post processing of alarms
String WC1PANICALARMLOCAL ="";
String WC1TEMPALARMLOCAL ="";
String WC2TEMPALARMLOCAL ="";
String WC1LDRALARMLOCAL ="";
String WC1FLOODALARMLOCAL ="";
String WRTEMP1ALARMLOCAL ="";
String WRTEMP2ALARMLOCAL ="";
String DETEMPALARMLOCAL ="";
String DEFLOODALARMLOCAL ="";
String DEPUMPLOCAL ="";
String DETOOHIGHALARMLOCAL ="";
String SATEMPALARMLOCAL ="";
String SALDOORALARMLOCAL ="";
String SALLDRALARMLOCAL ="";
String IDLDRALARMLOCAL ="";
String MUTEMPALARMLOCAL ="";
String ZETEMPALARMLOCAL ="";
String ZELDRALARMLOCAL ="";
String EBTEMPALARMLOCAL ="";
String EBLDRALARMLOCAL ="";
String GUPANICALARMLOCAL ="";
String GULDRALARMLOCAL ="";
String GUTEMPALARMLOCAL ="";
void MQTT_connect();

void setup()
{
  Serial.begin(9600);
  Wire.begin();
  WiFi.begin(WLAN_SSID, WLAN_PASS);
  delay(500);
  while (WiFi.status() != WL_CONNECTED) 
    {
        delay(500);
    }
  magazine(); //subscriptions
  Serial.println("before OTA");
  ArduinoOTA.onStart([]() {
    String type;
    if (ArduinoOTA.getCommand() == U_FLASH) {
      type = "sketch";
    } else { // U_SPIFFS
      type = "filesystem";
    }
  });
  ArduinoOTA.onEnd([]() {
    //Serial.println("\nEnd");
  });
  ArduinoOTA.onProgress([](unsigned int progress, unsigned int total) {
  });
  ArduinoOTA.onError([](ota_error_t error) {
    if (error == OTA_AUTH_ERROR) {
    } else if (error == OTA_BEGIN_ERROR) {
    } else if (error == OTA_CONNECT_ERROR) {
    } else if (error == OTA_RECEIVE_ERROR) {
    } else if (error == OTA_END_ERROR) {
    }
  });
  ArduinoOTA.begin();
//LED Array
cluster1.begin();cluster2.begin();cluster3.begin();cluster4.begin();
cluster1.pinMode(P0, OUTPUT); //IDalarm
cluster1.pinMode(P1, OUTPUT);//Idalive
cluster1.pinMode(P2, OUTPUT);//IDactivity
cluster1.pinMode(P3, OUTPUT);//gualarm
cluster1.pinMode(P4, OUTPUT);//gualive
cluster1.pinMode(P5, OUTPUT);//left red brick led
cluster1.pinMode(P6, OUTPUT);//mid yellow brick led
cluster1.pinMode(P7, OUTPUT);//guactivity
//------------------- green LED WARNING
cluster2.pinMode(P0, OUTPUT); 
cluster2.pinMode(P1, OUTPUT);
cluster2.pinMode(P2, OUTPUT);
cluster2.pinMode(P3, OUTPUT);
cluster2.pinMode(P4, OUTPUT);
cluster2.pinMode(P5, OUTPUT);
cluster2.pinMode(P6, OUTPUT);
cluster2.pinMode(P7, OUTPUT);
//------------------ yellow LED ACTIVITY
cluster3.pinMode(P0, OUTPUT); 
cluster3.pinMode(P1, OUTPUT);
cluster3.pinMode(P2, OUTPUT);
cluster3.pinMode(P3, OUTPUT);
cluster3.pinMode(P4, OUTPUT);
cluster3.pinMode(P5, OUTPUT);
cluster3.pinMode(P6, OUTPUT);
cluster3.pinMode(P7, OUTPUT);
//------------------ RED LED ACTIVITY
cluster4.pinMode(P0, OUTPUT); 
cluster4.pinMode(P1, OUTPUT); 
cluster4.pinMode(P2, OUTPUT); 
cluster4.pinMode(P3, OUTPUT); 
cluster4.pinMode(P4, OUTPUT); 
cluster4.pinMode(P5, OUTPUT); 
cluster4.pinMode(P6, OUTPUT); 
cluster4.pinMode(P7, OUTPUT); 
Serial.println("will test");
resetclusters(); //all LOW
selftest();
Serial.println("will enter loop");
}
//**********************************************************************************

void loop()
{
        ArduinoOTA.handle();   
        MQTT_connect();
        magazine(); //subscriptions
        Adafruit_MQTT_Subscribe *subscription;
        while ((subscription = mqtt.readSubscription(5000))) 
          {

                 if  (subscription == &WC1PANICALARM)
                          {
                                  if (strcmp((char *)WC1PANICALARM.lastread, "0") == 1) {cluster4.digitalWrite(P6, LOW);} else {cluster4.digitalWrite(P6, HIGH);} 
                                  Serial.println(" 1 WC1PANIC=");
                          }

          else   if  (subscription == &MUTEMPALARM)
                          {
                                  if (strcmp((char *)MUTEMPALARM.lastread, "0") == 1) {cluster4.digitalWrite(P0, LOW);} else {cluster4.digitalWrite(P0, HIGH);} 
                                  Serial.println(" 2 MUTEMP=");
                          }
          else    if  (subscription == &WC1TEMPALARM)
                          {
                                  if (strcmp((char *)WC1TEMPALARM.lastread, "0") == 1) {cluster4.digitalWrite(P6, LOW);} else {cluster4.digitalWrite(P6, HIGH);} 
                                  Serial.println(" 3 WC1TEMP=");
                          }

          else   if  (subscription == &GUPANICALARM)
                          {
                                  if (strcmp((char *)GUPANICALARM.lastread, "0") == 1) {cluster1.digitalWrite(P3, LOW);} else {cluster1.digitalWrite(P3, HIGH);} 
                                  Serial.println(" 4 GUPANIC=");
                          }    

           else  if  (subscription == &WC1FLOODALARM)
                          {
                                  if (strcmp((char *)WC1FLOODALARM.lastread, "0") == 1) {cluster4.digitalWrite(P6, LOW);} else {cluster4.digitalWrite(P6, HIGH);} 
                                  Serial.println(" 5 WC1FLOOD=");
                          }

           else  if  (subscription == &WC1LDRALARM)
                          {
                                  if (strcmp((char *)WC1LDRALARM.lastread, "0") == 1) {cluster2.digitalWrite(P6, LOW);} else {cluster2.digitalWrite(P6, HIGH);} 
                                  Serial.println(" 6 WC1LDR=");
                          }
            else  if  (subscription == &ZELDRALARM)
                          {
                                  if (strcmp((char *)ZELDRALARM.lastread, "0") == 1) {cluster2.digitalWrite(P2, LOW);} else {cluster2.digitalWrite(P2, HIGH);} 
                                  Serial.println(" 7 ZELDR=");

                          }
             else if  (subscription == &GULDRALARM)
                          {
                                  if (strcmp((char *)GULDRALARM.lastread, "0") == 1) {cluster1.digitalWrite(P7, LOW);} else {cluster1.digitalWrite(P7, HIGH);} 
                                  Serial.println(" 8 GULDR=");
                          }                              
    
              else if  (subscription == &WRTEMP1ALARM)
                          {
                                  if (strcmp((char *)WRTEMP1ALARM.lastread, "0") == 1) {cluster4.digitalWrite(P5, LOW);} else {cluster4.digitalWrite(P5, HIGH);} 
                                  Serial.println(" 9 WRTEMP=");
                          }
              else if  (subscription == &WRTEMP2ALARM)
                          {
                                  if (strcmp((char *)WRTEMP2ALARM.lastread, "0") == 1) {cluster4.digitalWrite(P5, LOW);} else {cluster4.digitalWrite(P5, HIGH);} 
                                  Serial.println(" 10 WRTEMP2=");
                          }
              else if  (subscription == &DETEMPALARM)
                          {
                                  if (strcmp((char *)DETEMPALARM.lastread, "0") == 1) {cluster4.digitalWrite(P7, LOW);} else {cluster4.digitalWrite(P7, HIGH);} 
                                  Serial.println(" 11 DETEMP=");
                          }
              else if  (subscription == &GUTEMPALARM)
                          {
                                  if (strcmp((char *)GUTEMPALARM.lastread, "0") == 1) {cluster1.digitalWrite(P5, LOW);} else {cluster1.digitalWrite(P5, HIGH);} 
                                 Serial.println(" 12 GUTEMP=");
                          }                          
              else if  (subscription == &DEFLOODALARM)
                          {
                                  if (strcmp((char *)DEFLOODALARM.lastread, "0") == 1) {cluster4.digitalWrite(P7, LOW);} else {cluster4.digitalWrite(P7, HIGH);} 
                                  Serial.println(" 13 DEFLOOD=");                                  
                          }

              else if  (subscription == &DEPUMP)
                          {
                                  if (strcmp((char *)DEPUMP.lastread, "0") == 1) {cluster2.digitalWrite(P7, LOW);} else {cluster2.digitalWrite(P7, HIGH);} 
                                 Serial.println(" 14 DEPUMP=");
                          }                          
               else if  (subscription == &ZETEMPALARM)
                          {
                                  if (strcmp((char *)ZETEMPALARM.lastread, "0") == 1) {cluster4.digitalWrite(P2, LOW);} else {cluster4.digitalWrite(P2, HIGH);} 
                                Serial.println(" 15 ZETEMP=");
                          }
 //From here after nothing works      
               else  if  (subscription == &EBTEMPALARM)
                          {
                                  if (strcmp((char *)EBTEMPALARM.lastread, "0") == 1) {cluster4.digitalWrite(P3, LOW);} else {cluster4.digitalWrite(P3, HIGH);} 
                                  Serial.println(" 16 EBTEMP=");
                          }
               else  if  (subscription == &EBLDRALARM)
                          {
                                  if (strcmp((char *)EBLDRALARM.lastread, "0") == 1) {cluster2.digitalWrite(P3, LOW);} else {cluster2.digitalWrite(P3, HIGH);} 
                                  Serial.println(" 17 EBLDR=");
                                  
                          }                          
               else  if  (subscription == &SATEMPALARM)
                          {
                                  if (strcmp((char *)SATEMPALARM.lastread, "0") == 1) {cluster4.digitalWrite(P1, LOW);} else {cluster4.digitalWrite(P1, HIGH);} 
                                  Serial.println(" 18 SATEMP=");
                          }
               else  if  (subscription == &SALDOORALARM)
                          {
                                  if (strcmp((char *)SALDOORALARM.lastread, "0") == 1) {cluster1.digitalWrite(P0, LOW);} else {cluster1.digitalWrite(P0, HIGH);} 
                                  Serial.println(" 19 SALDOOR=");
                          }
               else   if  (subscription == &SALLDRALARM)
                          {
                                  if (strcmp((char *)SALLDRALARM.lastread, "0") == 1) {cluster1.digitalWrite(P5, LOW);} else {cluster1.digitalWrite(P5, HIGH);} 
                                  Serial.println(" 20 SALLDR=");
                          }                          
          }

processalarm();
if(! mqtt.ping()) {mqtt.disconnect();}           
}

void processalarm() //further processing bells etc..
{

}
void beepfire()
      {
          cluster1.digitalWrite(P5, LOW);cluster1.digitalWrite(P6, HIGH);tone(beeppin, 1000); delay(75); noTone(beeppin); delay (75);cluster1.digitalWrite(P5, HIGH);cluster1.digitalWrite(P6, LOW); //short beep
      delay(3000);
      }
void beeppanic()
      {
          cluster1.digitalWrite(P5, LOW);cluster1.digitalWrite(P6, HIGH);tone(beeppin, 1000); delay(75); noTone(beeppin); delay (75);cluster1.digitalWrite(P5, HIGH);cluster1.digitalWrite(P6, LOW);
          delay(3000);
      }
void beepalarm()
      {
          tone(beeppin, 1000); delay(75); noTone(beeppin); delay (75);
      }            
void beepflood()
      {
          cluster1.digitalWrite(P5, LOW);cluster1.digitalWrite(P6, HIGH);tone(beeppin, 1000); delay(75); noTone(beeppin); delay (75);cluster1.digitalWrite(P5, HIGH);cluster1.digitalWrite(P6, LOW);
      delay(3000);
      }               
void MQTT_connect() {int8_t ret;if (mqtt.connected()) {return;}
  uint8_t retries = 3;
  while ((ret = mqtt.connect()) != 0) { // connect will return 0 for connected
       Serial.println(mqtt.connectErrorString(ret));
       Serial.println("Retrying MQTT connection in 5 seconds...");
       mqtt.disconnect();
       delay(5000);  // wait 5 seconds
       retries--;
       if (retries == 0) {
         // basically die and wait for WDT to reset me
         while (1);
       }
  }
  Serial.println("MQTT Connected!");
}

void magazine()
{
        mqtt.subscribe(&GUPANICALARM);
        mqtt.subscribe(&GUTEMPALARM);
        mqtt.subscribe(&GULDRALARM);
        mqtt.subscribe(&WC1PANICALARM);
        mqtt.subscribe(&WC1TEMPALARM);
        mqtt.subscribe(&WC2TEMPALARM);
        mqtt.subscribe(&WC1LDRALARM);
        mqtt.subscribe(&WC1FLOODALARM);
        mqtt.subscribe(&WRTEMP1ALARM);
        mqtt.subscribe(&WRTEMP2ALARM);
        mqtt.subscribe(&DETEMPALARM);
        mqtt.subscribe(&DEFLOODALARM);
        mqtt.subscribe(&DETOOHIGHALARM);
        mqtt.subscribe(&DEPUMP);
        mqtt.subscribe(&ZETEMPALARM);
        mqtt.subscribe(&ZELDRALARM);
        mqtt.subscribe(&EBTEMPALARM);
        mqtt.subscribe(&EBLDRALARM);
        mqtt.subscribe(&SATEMPALARM);
        mqtt.subscribe(&SALDOORALARM);
        mqtt.subscribe(&SALLDRALARM);
        mqtt.subscribe(&MUTEMPALARM);
        mqtt.subscribe(&IDLDRALARM);
}
void selftest()
{
int delayed=50;
cluster1.digitalWrite(P0, LOW);
delay(delayed);
cluster1.digitalWrite(P0, HIGH);
delay(delayed);
cluster1.digitalWrite(P1, LOW);
delay(delayed);
cluster1.digitalWrite(P1, HIGH);
delay(delayed);
cluster1.digitalWrite(P2, LOW);
delay(delayed);
cluster1.digitalWrite(P2, HIGH);
delay(delayed);
cluster1.digitalWrite(P3, LOW);
delay(delayed);
cluster1.digitalWrite(P3, HIGH);
delay(delayed);
cluster1.digitalWrite(P4, LOW);
delay(delayed);
cluster1.digitalWrite(P4, HIGH);
delay(delayed);
cluster1.digitalWrite(P5, LOW);
delay(delayed);
cluster1.digitalWrite(P5, HIGH);
delay(delayed);
cluster1.digitalWrite(P6, LOW);
delay(delayed);
cluster1.digitalWrite(P6, HIGH);
delay(delayed);
cluster1.digitalWrite(P7, LOW);
delay(delayed);
cluster1.digitalWrite(P7, HIGH);
delay(delayed);

cluster2.digitalWrite(P0, LOW);
delay(delayed);
cluster2.digitalWrite(P0, HIGH);
delay(delayed);
cluster2.digitalWrite(P1, LOW);
delay(delayed);
cluster2.digitalWrite(P1, HIGH);
delay(delayed);
cluster2.digitalWrite(P2, LOW);
delay(delayed);
cluster2.digitalWrite(P2, HIGH);
delay(delayed);
cluster2.digitalWrite(P3, LOW);
delay(delayed);
cluster2.digitalWrite(P3, HIGH);
delay(delayed);
cluster2.digitalWrite(P4, LOW);
delay(delayed);
cluster2.digitalWrite(P4, HIGH);
delay(delayed);
cluster2.digitalWrite(P5, LOW);
delay(delayed);
cluster2.digitalWrite(P5, HIGH);
delay(delayed);
cluster2.digitalWrite(P6, LOW);
delay(delayed);
cluster2.digitalWrite(P6, HIGH);
delay(delayed);
cluster2.digitalWrite(P7, LOW);
delay(delayed);
cluster2.digitalWrite(P7, HIGH);
delay(delayed);

cluster3.digitalWrite(P0, LOW);
delay(delayed);
cluster3.digitalWrite(P0, HIGH);
delay(delayed);
cluster3.digitalWrite(P1, LOW);
delay(delayed);
cluster3.digitalWrite(P1, HIGH);
delay(delayed);
cluster3.digitalWrite(P2, LOW);
delay(delayed);
cluster3.digitalWrite(P2, HIGH);
delay(delayed);
cluster3.digitalWrite(P3, LOW);
delay(delayed);
cluster3.digitalWrite(P3, HIGH);
delay(delayed);
cluster3.digitalWrite(P4, LOW);
delay(delayed);
cluster3.digitalWrite(P4, HIGH);
delay(delayed);
cluster3.digitalWrite(P5, LOW);
delay(delayed);
cluster3.digitalWrite(P5, HIGH);
delay(delayed);
cluster3.digitalWrite(P6, LOW);
delay(delayed);
cluster3.digitalWrite(P6, HIGH);
delay(delayed);
cluster3.digitalWrite(P7, LOW);
delay(delayed);
cluster3.digitalWrite(P7, HIGH);
delay(delayed);

cluster4.digitalWrite(P0, LOW);
delay(delayed);
cluster4.digitalWrite(P0, HIGH);
delay(delayed);
cluster4.digitalWrite(P1, LOW);
delay(delayed);
cluster4.digitalWrite(P1, HIGH);
delay(delayed);
cluster4.digitalWrite(P2, LOW);
delay(delayed);
cluster4.digitalWrite(P2, HIGH);
delay(delayed);
cluster4.digitalWrite(P3, LOW);
delay(delayed);
cluster4.digitalWrite(P3, HIGH);
delay(delayed);
cluster4.digitalWrite(P4, LOW);
delay(delayed);
cluster4.digitalWrite(P4, HIGH);
delay(delayed);
cluster4.digitalWrite(P5, LOW);
delay(delayed);
cluster4.digitalWrite(P5, HIGH);
delay(delayed);
cluster4.digitalWrite(P6, LOW);
delay(delayed);
cluster4.digitalWrite(P6, HIGH);
delay(delayed);
cluster4.digitalWrite(P7, LOW);
delay(delayed);
cluster4.digitalWrite(P7, HIGH);
delay(delayed);
}

void resetclusters()
{
cluster1.digitalWrite(P0, HIGH);
cluster1.digitalWrite(P1, HIGH);
cluster1.digitalWrite(P2, HIGH);
cluster1.digitalWrite(P3, HIGH);
cluster1.digitalWrite(P4, HIGH);
cluster1.digitalWrite(P5, HIGH);
cluster1.digitalWrite(P6, HIGH);
cluster1.digitalWrite(P7, HIGH);

cluster2.digitalWrite(P0, HIGH);
cluster2.digitalWrite(P1, HIGH);
cluster2.digitalWrite(P2, HIGH);
cluster2.digitalWrite(P3, HIGH);
cluster2.digitalWrite(P4, HIGH);
cluster2.digitalWrite(P5, HIGH);
cluster2.digitalWrite(P6, HIGH);
cluster2.digitalWrite(P7, HIGH);

cluster3.digitalWrite(P0, HIGH);
cluster3.digitalWrite(P1, HIGH);
cluster3.digitalWrite(P2, HIGH);
cluster3.digitalWrite(P3, HIGH);
cluster3.digitalWrite(P4, HIGH);
cluster3.digitalWrite(P5, HIGH);
cluster3.digitalWrite(P6, HIGH);
cluster3.digitalWrite(P7, HIGH);

cluster4.digitalWrite(P0, HIGH);
cluster4.digitalWrite(P1, HIGH);
cluster4.digitalWrite(P2, HIGH);
cluster4.digitalWrite(P3, HIGH);
cluster4.digitalWrite(P4, HIGH);
cluster4.digitalWrite(P5, HIGH);
cluster4.digitalWrite(P6, HIGH);
cluster4.digitalWrite(P7, HIGH);
}

void processlogs() //need to log all incidents into a log file...under construction.. come back later
      {

      }

You will have to modify the library, the culprit is likely this line 133 that sets the max to 15 (note also the buffer’s max size).

Problem solved. I wonder why put such a limitation without mentioning it by Adafruit.

Anyway, Thank you very much **J-M-L**Jackson.

Developers have this saying : the code is the ultimate documentation :slight_smile:

Glad I was able to help. Have fun.

Can’t speak to why its not mentioned, but from that snippet, each subscription requires a buffer of 20 bytes plus memory for pointers and resources for MQTT message processing overhead which will be reserved in “dynamic memory”. On top of that there will be your other program variables and running overhead. On a 328P[B] or 32u4 MCU, there is only 2kb and 2.5kb respectively of “dynamic memory” so it makes sense to keep the number to a sensible limit.

So now I can’t exceed 19 subs after modifying MAXSUBSCRIPTIONS to 50 and MAXBUFFERSIZE to 300. I have a total of 30 subs and increasing.

Any suggestions for perhaps a better library than Adafruit. Or maybe even migrate to ESP32 instead.

Don't know if it's "better", but I use: https://github.com/knolleary/pubsubclient

you could investigate the GitHub - knolleary/pubsubclient: A client library for the Arduino Ethernet Shield that provides support for MQTT.

Moving to ESP32 will give you way more RAM and more capability on the hardware side with a dual-core architecture where one core can run user tasks while the other manages WiFi, making connections more stable and less likely to interfere with program execution.

Mybad. I checked my code again and found that I have not subscribed to the new subs. Now all 30 subs are reporting correctly.

I would like to thank everyone for there support.

note: if (subscription == &WRALIVE) should have warned me for not subscribing. But thats another matter.

good to hear!

(careful with large number of subscriptions and large buffers. At some point you'll run out of RAM - the ESP32 will help push that limit further).