From 7f18e1e8e3ded01d4d6d765882e3b80aefd837ed Mon Sep 17 00:00:00 2001 From: Matthijs Abma <4146168+abmaonline@users.noreply.github.com> Date: Sat, 23 May 2020 17:30:48 +0200 Subject: [PATCH] Split logic for adding char to buffer and sending the buffer, to make sure the char doesn't get lost when the buffer is full --- tasmota/support_tasmota.ino | 8 ++++++-- tasmota/xdrv_08_serial_bridge.ino | 8 ++++++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/tasmota/support_tasmota.ino b/tasmota/support_tasmota.ino index f3da57ffb..671b4ad9d 100644 --- a/tasmota/support_tasmota.ino +++ b/tasmota/support_tasmota.ino @@ -1299,11 +1299,15 @@ void SerialInput(void) if ((serial_in_byte_counter < INPUT_BUFFER_SIZE -1) && // Add char to string if it still fits and ... !in_byte_is_delimiter) { // Char is not a delimiter serial_in_buffer[serial_in_byte_counter++] = serial_in_byte; - serial_polling_window = millis(); - } else { + } + + if ((serial_in_byte_counter >= INPUT_BUFFER_SIZE -1) || // Send message when buffer is full or ... + in_byte_is_delimiter) { // Char is delimiter serial_polling_window = 0; // Reception done - send mqtt break; } + + serial_polling_window = millis(); // Wait for next char } } diff --git a/tasmota/xdrv_08_serial_bridge.ino b/tasmota/xdrv_08_serial_bridge.ino index 66a0cbc3d..a713b5cfb 100644 --- a/tasmota/xdrv_08_serial_bridge.ino +++ b/tasmota/xdrv_08_serial_bridge.ino @@ -62,11 +62,15 @@ void SerialBridgeInput(void) if ((serial_bridge_in_byte_counter < SERIAL_BRIDGE_BUFFER_SIZE -1) && // Add char to string if it still fits and ... !in_byte_is_delimiter) { // Char is not a delimiter serial_bridge_buffer[serial_bridge_in_byte_counter++] = serial_in_byte; - serial_bridge_polling_window = millis(); // Wait for more data - } else { + } + + if ((serial_bridge_in_byte_counter >= SERIAL_BRIDGE_BUFFER_SIZE -1) || // Send message when buffer is full or ... + in_byte_is_delimiter) { // Char is delimiter serial_bridge_polling_window = 0; // Publish now break; } + + serial_bridge_polling_window = millis(); // Wait for more data } }