MQQT Posts from multiple arduinos

Dear Community,

While searching for an entry about mqqt problems I found some mqqt posts in this forum. None however fits my topic.
I have been running mqqt on a raspi for about 2 years with one arduino mega publishing data wirhout any problems. Now I setup a second arduino. It seems a lot of publishings just never go through.
I am using a different mac adress on the second and I also changed the name inside the connect request:

if (client.connect("arduinoClient")) {

To if (client.connect("arduinoClient2")) {

I am not sure if this is relevant or not.

Before I post pages full of code I would like to ask in general:
My first arduino never closes the client connection.
Every time the main prg loop reaches the part where data has to be published I simply repeated the client.connect line
With the second arduino this seems to work only sometimes.
I have seen code where the connect.Client is put into an if clause

void reconnect() {
  // Repeat until connection is made
  while (!client.connected()) {
    Serial.print("MQTT connection attempt...");
    // Connection attempt
    if (client.connect("arduinoClient")) {
      Serial.println("Succesfully connected!");
      // Message to outTopic
      client.publish("temp1"," data...");
      
    } else { // Error case => Message and new attempt
      Serial.print("Fehler, rc= ");
      Serial.print(client.state());
      Serial.println(" new attempt in 5 seconds");
      // 5 seconds pause
      delay(5000);
    }
  }

is this pointing towards the right direction?a 5 seconds loop would slow everything down.

Best regards and thanks for any hint

Trigan

It seems a lot of publishings just never go through.

What does that mean? Do you get an error on the Arduino?

I am using a different mac adress on the second and I also changed the name inside the connect request:

Much more important: Are you using different topics to publish to?

In the posted code you only publish the data if the connection was closed since the last update. Was that the intention? It doesn't make sense to me but that may be because i don't have enough context information.