- Increase wait time to 1 second for complete sensor response
- Read all available bytes from buffer instead of fixed 32
- Search for frame header (FF 02) anywhere in response data
(handles command echo or garbage before actual frame)
- Extract frame from header position for correct byte alignment
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
The CAIRSENS sensor sends response in a single block, not two parts.
The initial read was consuming all 25 bytes leaving nothing for the
actual data read.
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Replace readline() with read(32) to avoid truncation at 0x0A bytes
- Add reset_input_buffer() to clear stale data before each read
- Add initial read to consume echo/acknowledgment from sensor
- Add frame header validation (0xFF 0x02) to reject invalid data
- Add delays to allow sensor response time
Fixes issue where NO2/H2S sensors showed random spikes due to
binary data containing newline characters being misinterpreted.
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>