Enhance MQTT debug macros to prevent hangs by checking Serial availability before printing.
This commit is contained in:
1 parent
03d519f8d4
commit
3589043b2e
1 file changed
+5
-2
@@ -11,8 +11,11 @@
|
||||
|
||||
#if defined(MQTT_DEBUG) && defined(ARDUINO)
|
||||
#include <Arduino.h>
|
||||
#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(...) {}
|
||||
|
||||
Reference in new issue
Block a user