From d4fbc17d4362b8c9927a3fc01da770b97259f046 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sybren=20A=2E=20St=C3=BCvel?= Date: Sat, 14 Mar 2026 20:15:24 +0100 Subject: [PATCH] Cut up log lines into 20-byte BLE packets --- src/helpers/esp32/BLELogInterface.h | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/helpers/esp32/BLELogInterface.h b/src/helpers/esp32/BLELogInterface.h index db94de63..30442ccc 100644 --- a/src/helpers/esp32/BLELogInterface.h +++ b/src/helpers/esp32/BLELogInterface.h @@ -31,8 +31,18 @@ class BLELogInterface : public Print, BLEServerCallbacks { void flushLine() { if (_line_len > 0 && _connected) { - _tx_char->setValue((uint8_t*)_line_buf, _line_len); - _tx_char->notify(); + // BLE notifications are capped at ATT_MTU-3 bytes; MTU negotiation is not + // guaranteed, so always chunk at 20 bytes (the safe minimum) to ensure the + // full line is delivered regardless of the negotiated MTU. + const int CHUNK = 20; + int offset = 0; + while (offset < _line_len) { + int n = _line_len - offset; + if (n > CHUNK) n = CHUNK; + _tx_char->setValue((uint8_t*)_line_buf + offset, n); + _tx_char->notify(); + offset += n; + } } _line_len = 0; }