v1.8.3 - Serial Protocol Reliability Refactoring (2025-11-23)¶
What Changed?¶
This release refactors the serial command reception from custom byte-by-byte reading to Arduino's Serial.readBytesUntil() API. The new implementation is simpler (64% code reduction), more reliable (500ms timeout), and safer (buffer overflow protection). All user-facing behavior remains unchangedβcomplete backward compatibility with existing commands.
What's New¶
Main Feature: Improved Serial Command Reception¶
What it does:
Replaces custom serial line-reading logic with Arduino's built-in Serial.readBytesUntil() API for more robust command reception. The new implementation:
- Uses standard Arduino API instead of custom byte loops
- Implements reliable 500ms timeout for incomplete commands
- Protects against buffer overflow (63-byte limit)
- Supports cross-platform line endings (Unix
\n, Windows\r\n, Mac\r)
How to use it:
No changes required! Send commands exactly as before:
- Open Serial Monitor at 115200 baud
- Select "NL" (newline) line ending
- Type commands:
STATUS,SET_POLL_COUNT 150, etc. - Commands process identically to previous versions
Code example:
// Before: ~55 lines of custom byte-by-byte logic
// After: ~20 lines using Serial.readBytesUntil()
Serial.setTimeout(SERIAL_READ_TIMEOUT_MS);
size_t bytes_read = Serial.readBytesUntil('\n', buffer, CMD_MAX_LENGTH);
// Overflow detection: if 63 bytes without newline, flush and reject
if (bytes_read == CMD_MAX_LENGTH) {
while (Serial.available()) Serial.read(); // Flush remaining
return false; // Reject command
}
Installation¶
Quick Start¶
# Get the release
git checkout v1.8.3
# Build
task dev:build
# Upload
task dev:upload
# Test
task monitor
What's Different from the Last Version?¶
β Added¶
SERIAL_READ_TIMEOUT_MSconstant (500ms timeout for line reception)CMD_BUFFER_SIZEandCMD_MAX_LENGTHconstants for buffer managementserial_command_tdata structure for command representation- Comprehensive docstrings and inline comments explaining timeout/overflow behavior
- Full quickstart testing guide with 8 test procedures
π§ Changed¶
- serial_read_text_command(): Replaced custom loop with
Serial.readBytesUntil()(55 β 20 lines) - Timeout handling: Now uses
Serial.setTimeout()instead of manual timing - Buffer overflow: Automatic flush on 63-byte overflow detection
- Line ending support: Unified trim logic handles
\n,\r\n, and\r
π Fixed¶
- Improved reliability of incomplete command detection
- Eliminated edge cases in custom byte-reading logic
- Better handling of slow data arrival (incremental reception)
- Safe recovery from buffer overflow without command corruption
Is It Safe to Upgrade¶
Backward Compatible: β Yes (100% compatible)
- No breaking API changes
- Function signature unchanged:
bool serial_read_text_command(char* buffer, int buffer_size) - All commands work identically
- Response format unchanged (JSON still sent via serial)
- No changes to command syntax or behavior
Impact on existing users¶
- Zero impact - Commands behave exactly as before
- No new configuration required
- No changes to serial monitor settings needed
- All existing firmware features work unchanged
Tests Passed¶
- β Builds without errors (SUCCESS at 6.30s)
- β Test 1: Complete command reception (STATUS β JSON response)
- β Test 2: Command with arguments (SET_POLL_COUNT 150 β confirmation)
- β Test 3: Partial command timeout (no response after 500ms)
- β Test 4: Buffer overflow rejection (70 bytes safely rejected)
- β Test 5: Cross-platform line endings (NL, CR+LF, CR all work)
- β Test 6: Empty command rejection (silent, no error)
- β Test 7: Rapid command queue (FIFO order preserved)
- β Test 8: Case insensitivity (lowercase/mixed case work)
- β Flash usage: 23.9% (no significant increase)
- β RAM usage: 7.3% (optimal)
Release Details¶
- Date: 2025-11-23
- Version: v1.8.3
- Files Changed: 3 (config.h, serial_protocol.h, serial_protocol.cpp)
- Commits: e794517, 9887b74, 2655837, 9cae7a4, afa546a
- Lines Changed: ~55 β ~20 in serial_read_text_command() (64% reduction)
Next Steps¶
- v1.9.0: RTC (Real-Time Clock) feature for event timestamping
- Future: Additional serial protocol enhancements based on user feedback
- Roadmap: See
REFACTORING_ROADMAP.md