DigitalShoestringSolutions / AirParticleMonitoring

GNU General Public License v3.0
0 stars 1 forks source link

WARNING:main.measure:previous loop took longer than expected #10

Closed tobyaharris closed 4 weeks ago

tobyaharris commented 1 month ago

On every single sample in the logs of the reference setup, this warning is raised. The line completes with a time, usually by 0.9...s but occasionally this time is only ~0.4s

Greg-Hawkridge commented 1 month ago

Most likely, the solution is set up to try sample at a faster rate than the sensor can reliably support. I would guess that changing it to a sample period of 2 seconds would fix.

tobyaharris commented 1 month ago

It may be relevant to note that whilst the config file does have a sample_count: https://github.com/DigitalShoestringSolutions/AirParticleMonitoring/blob/7666b5d326224bdb9731c86ff7a1fa0dc7d34001/particle_dc/config/config.toml#L9 ...this value is not used at all in the code 🤦. It is loaded from config in: https://github.com/DigitalShoestringSolutions/AirParticleMonitoring/blob/7666b5d326224bdb9731c86ff7a1fa0dc7d34001/particle_dc/code/measure.py#L57 and then nothing is done with self.sample_count. Clearly copied from PowerBasic without much tidying up.

Hence, what is likely happening is: https://github.com/DigitalShoestringSolutions/AirParticleMonitoring/blob/7666b5d326224bdb9731c86ff7a1fa0dc7d34001/particle_dc/config/config.toml#L10 https://github.com/DigitalShoestringSolutions/AirParticleMonitoring/blob/7666b5d326224bdb9731c86ff7a1fa0dc7d34001/particle_dc/code/measure.py#L56 https://github.com/DigitalShoestringSolutions/AirParticleMonitoring/blob/7666b5d326224bdb9731c86ff7a1fa0dc7d34001/particle_dc/code/measure.py#L79 https://github.com/DigitalShoestringSolutions/AirParticleMonitoring/blob/7666b5d326224bdb9731c86ff7a1fa0dc7d34001/particle_dc/code/measure.py#L96 And finally a mucky compensated sleep https://github.com/DigitalShoestringSolutions/AirParticleMonitoring/blob/7666b5d326224bdb9731c86ff7a1fa0dc7d34001/particle_dc/code/measure.py#L129-L134 ... It's trying to run at 5Hz.

tobyaharris commented 1 month ago

And once I've noticed it, I've got to do the minimum to fix it: see branch hotfix/sample-rate