diff --git a/src/helpers/bridges/MQTTBridge.h b/src/helpers/bridges/MQTTBridge.h index f6d54a10..e3f79dcc 100644 --- a/src/helpers/bridges/MQTTBridge.h +++ b/src/helpers/bridges/MQTTBridge.h @@ -11,8 +11,11 @@ #if defined(MQTT_DEBUG) && defined(ARDUINO) #include - #define MQTT_DEBUG_PRINT(F, ...) Serial.printf("MQTT: " F, ##__VA_ARGS__) - #define MQTT_DEBUG_PRINTLN(F, ...) Serial.printf("MQTT: " F "\n", ##__VA_ARGS__) + // USB CDC-aware debug macros: only print if Serial is ready (non-blocking check) + // Serial.availableForWrite() returns bytes available in write buffer (>0 means ready) + // This prevents hangs when USB CDC isn't ready yet (e.g., ESP32-S3 native USB) + #define MQTT_DEBUG_PRINT(F, ...) do { if (Serial.availableForWrite() > 0) { Serial.printf("MQTT: " F, ##__VA_ARGS__); } } while(0) + #define MQTT_DEBUG_PRINTLN(F, ...) do { if (Serial.availableForWrite() > 0) { Serial.printf("MQTT: " F "\n", ##__VA_ARGS__); } } while(0) #else #define MQTT_DEBUG_PRINT(...) {} #define MQTT_DEBUG_PRINTLN(...) {}