MQTT "messageReceived" not working when inserting RTC timestamp in loop?

Hi,
I’m using the MQTT.h library with success in one of my project using Adruino UNO w/Ethershield based on your ArduinoEthernetShield.ino exemple.

https://github.com/256dpi/arduino-mqtt/blob/master/examples/ArduinoEthernetShield/ArduinoEthernetShield.ino

I wanted to add to the loop a timestamp based on RTC clock every second. (DS3231 - Tested and working)
Once the RTC commands is added to the “if (millis() - lastMillis > 1000)” time gets displayed every seconds, but the reception of MQTT messages stops working.
As if the “void messageReceived(String &topic, String &payload)” is not triggered anymore by incoming messages.

I can confirm the arduino is connected to broker and subscribe to topic.
Thx for any helpfull infos.

Here is my code sample:

#include <Ethernet.h>
#include <MQTTClient.h>
#include <MQTT.h>
#include <Wire.h>
#include "RTClib.h"
RTC_DS3231 rtc;

...
...
...

void loop() { 
  client.loop();
  if (!client.connected()) { 
    Serial.print("\nNOT CONNECTED TO BROKER....");
    connect();                                      
  }
// publish a message roughly every second.
  if (millis() - lastMillis > 1000) {
    lastMillis = millis();
    Serial.print("\nDEBUG\n");
    DateTime now = rtc.now();       //THIS CAUSE ISSUE
    Serial.print(now.hour(), DEC);  //THIS CAUSE ISSUE
    Serial.print(':');               //THIS CAUSE ISSUE
    Serial.print(now.minute(), DEC); //THIS CAUSE ISSUE
    Serial.print(':');                //THIS CAUSE ISSUE
    Serial.print(now.second(), DEC); //THIS CAUSE ISSUE
    Serial.println();                //THIS CAUSE ISSUE
  }
}

Post all your code.

Here it is.
Not yet optimized…

Note: Code working fine as joined.
Wont work when RTC lines in the loop are uncommented. Thx alot for your time.

ArduinoForum-RTCbugv1.ino (7.73 KB)

I expected that use of serial was slowing your code down but the baud rate suggests not. What happens if you print the same amount of text, but leave the rtc out of it?

Same amount of text as so, no problem, working fine.:

 if (millis() - lastMillis > 1000) {
    lastMillis = millis();
    Serial.print("\n--------- DEBUG 6 ------------\n");
    Serial.print("\n--------- DEBUG 6 ------------\n");
    Serial.print("\n--------- DEBUG 6 ------------\n");
    Serial.print("\n--------- DEBUG 6 ------------\n");
    Serial.print("\n--------- DEBUG 6 ------------\n");
    Serial.print("\n--------- DEBUG 6 ------------\n");
    Serial.print("\n--------- DEBUG 6 ------------\n");
//    DateTime now = rtc.now();
//    Serial.print(now.hour(), DEC);
//    Serial.print(':');
//    Serial.print(now.minute(), DEC);
//    Serial.print(':');
//    Serial.print(now.second(), DEC);
//    Serial.println();
  }

In fact, at fist I only printed one line of RTC infos (seconds). And issue appeared.
If RTC is involved, RTC works and prints correct date&time, but MQTT wont be analysing incoming messages on my subscibed topic....

Thx again!