hotplot / enviroplus-mqtt

A Python service for logging environmental data over MQTT
MIT License
31 stars 20 forks source link

Receiving values with a long delay #6

Closed ferazambuja closed 4 years ago

ferazambuja commented 4 years ago

After a day and a half of continuous running, the readings sent from my enviro+ are 4 hours late.
It looks it longer it runs bigger it gets. I have 2 (esphome) PMS reading side by side, and as you can see on the image, the readings are hours late. An easy test is to cover the lux meter and see how long it takes to respond.

I thought that it might be related to the delay in publishing the first message, but that doesn't seem to be the case after running a few minutes with a 600-second initial delay.

https://community-home-assistant-assets.s3.dualstack.us-west-2.amazonaws.com/original/3X/a/6/a66e1716e9bce4e4162727c7b9e46aaf960b8a19.png

ferazambuja commented 4 years ago

https://github.com/hotplot/enviroplus-mqtt/blob/93604974d59c703ddc2ca2518ca3441d7fe5baaf/src/logger.py#L93

Is there any good reason to be changing the values? The sensors are quite stable to have noise spikes. Not sure if is related, but I will try to remove it from the code and see.

hotplot commented 4 years ago

The delay issue was caused by polling the PMS5003 too slowly, and was fixed in 093fda6

Regarding your second comment, the sensor values are read at 1 Hz but only published at a configurable interval. Hence the published value is the average of all the samples taken during the current interval.

Averaging the samples over a period of time increases resolution and decreases noise

Closing since the delay issue has been fixed

bsimmo commented 2 years ago

Just a note on this I had similar problems with GNSS sometimes, never remember it with my SDS PM sensors though. Rather than polling all the time in a thread (can the PMS sleep doing this?).

Flush the serial port, then take a reading always solved it for me.