bencorrado / pmsensor

Library to read data from particulate matter sensors
MIT License
20 stars 15 forks source link

Update serial_pm.py #7

Closed noisyfly closed 5 years ago

noisyfly commented 6 years ago

In Home Assistant Particulate Matter result was inconsistent in time. More inconsistent if more time pass. It was because serial device is open once during device init, so data from sensor is collected by system in device buffer and slowly read from it. Data to device buffer is stored faster (sensor send it faster) than it is read from it slowly by Home Assistant. So results are "extended" in time. More extended if more time pass to the limits of device buffer. So added here is cleaning device input buffer before next read of PM value. This way we get most recent results. The problem is more visible after some time because sensor shows data from the past. And actual data will be visible in the future. This issue depends from length of the buffer.

Additionally during research was added check sum control for PLANTOWER1 config.