- Retry up to 3 times if no valid frame is received
- Reduced wait time per attempt to 0.8s (total max ~3s with retries)
- Small delay between retries (0.2s)
- Only logs command on first attempt to reduce noise
This should eliminate the occasional 0 values caused by timing issues.
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Some readings were returning 0 because the sensor hadn't fully
responded within 1 second. Increased to 1.5s for more reliable reads.
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- 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>