From 660d1cde94e700e2bb4d959a7f8fb330a64f2c30 Mon Sep 17 00:00:00 2001 From: acidburns Date: Sun, 1 Feb 2026 18:59:12 +0100 Subject: [PATCH] prevent watchdog from killing while printing json --- include/config.h | 1 + src/main.cpp | 23 ++++++++++++++++++++++- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/include/config.h b/include/config.h index 5a30371..c680fb8 100644 --- a/include/config.h +++ b/include/config.h @@ -74,6 +74,7 @@ constexpr BatchRetryPolicy BATCH_RETRY_POLICY = BatchRetryPolicy::Keep; constexpr uint32_t WATCHDOG_TIMEOUT_SEC = 120; constexpr bool ENABLE_HA_DISCOVERY = true; constexpr bool SERIAL_DEBUG_MODE = true; +constexpr bool SERIAL_DEBUG_DUMP_JSON = true; constexpr uint8_t NUM_SENDERS = 1; inline constexpr uint16_t EXPECTED_SENDER_IDS[NUM_SENDERS] = { diff --git a/src/main.cpp b/src/main.cpp index 25f440e..8b68f8a 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -87,6 +87,8 @@ static uint16_t g_inflight_batch_id = 0; static bool g_inflight_active = false; static uint32_t g_last_debug_log_ms = 0; +static void watchdog_kick(); + static void serial_debug_printf(const char *fmt, ...) { if (!SERIAL_DEBUG_MODE) { return; @@ -99,6 +101,25 @@ static void serial_debug_printf(const char *fmt, ...) { Serial.println(buf); } +static void serial_debug_print_json(const String &json) { + if (!SERIAL_DEBUG_MODE || !SERIAL_DEBUG_DUMP_JSON) { + return; + } + const char *data = json.c_str(); + size_t len = json.length(); + const size_t chunk = 128; + for (size_t i = 0; i < len; i += chunk) { + size_t n = len - i; + if (n > chunk) { + n = chunk; + } + Serial.write(reinterpret_cast(data + i), n); + watchdog_kick(); + delay(0); + } + Serial.write('\n'); +} + static uint16_t g_last_batch_id_rx[NUM_SENDERS] = {}; struct BatchRxState { @@ -376,7 +397,7 @@ static bool send_inflight_batch(uint32_t ts_for_display) { } if (SERIAL_DEBUG_MODE) { serial_debug_printf("tx: batch_id=%u count=%u json_len=%u", g_inflight_batch_id, g_inflight_count, static_cast(json.length())); - Serial.println(json); + serial_debug_print_json(json); } static uint8_t compressed[BATCH_MAX_COMPRESSED];