What
When i first plugged in and used the PMS5003 sensor, it felt like it wasn't working as expected, the reading from the sensor didn't really change even when i blocked the sensor fan and holes in the front. Here's a graph of the readings over several days:
After looking through the code for this library i noticed that there was a reset API, so i called that which seemed to help, and the sensor did seem to behave differently and the results in the graph also looked a bit more interesting:
However, when ever i restart my python application (which also now performs a reset on the sensor), the sensor behaviour changes on every restart:
I would expect that reset shouldn't change the characteristics of the sensor so drastically.
Here's the snippet of the code:
#!/usr/bin/env python3
import sys
import time
import logging
from pms5003 import PMS5003
from pms5003 import ReadTimeoutError as pmsReadTimeoutError
from pms5003 import SerialTimeoutError
from prometheus_client import start_http_server,Gauge
env_sensor_pm1_gauge = Gauge('env_sensor_pm1', 'particle monitoring 1 in ug/m3')
env_sensor_pm25_gauge = Gauge('env_sensor_pm25', 'particle monitoring 2.5 in ug/m3')
env_sensor_pm10_gauge = Gauge('env_sensor_pm10', 'particle monitoring 10 in ug/m3')
env_sensor_pm_03_pl_gauge = Gauge('env_sensor_pm03_litre', 'particles >0.3um per 1/10 litre of air')
env_sensor_pm_05_pl_gauge = Gauge('env_sensor_pm05_litre', 'particles >0.5um per 1/10 litre of air')
env_sensor_pm_1_pl_gauge = Gauge('env_sensor_pm1_litre', 'particles >1um per 1/10 litre of air')
env_sensor_pm_25_pl_gauge = Gauge('env_sensor_pm25_litre', 'particles >2.5um per 1/10 litre of air')
env_sensor_pm_5_pl_gauge = Gauge('env_sensor_pm5_litre', 'particles >5um per 1/10 litre of air')
env_sensor_pm_10_pl_gauge = Gauge('env_sensor_pm10_litre', 'particles >10um per 1/10 litre of air')
# PMS5003 particulate sensor
pms5003 = PMS5003()
time.sleep(1.0)
def main():
pms5003.reset()
# The main loop
while True:
pms_data = None
try:
pms_data = pms5003.read()
except (SerialTimeoutError, pmsReadTimeoutError):
logging.warning("Failed to read PMS5003")
else:
env_sensor_pm1_gauge.set(pms_data.pm_ug_per_m3(1.0))
env_sensor_pm25_gauge.set(pms_data.pm_ug_per_m3(2.5))
env_sensor_pm10_gauge.set(pms_data.pm_ug_per_m3(10))
env_sensor_pm_03_pl_gauge.set(pms_data.pm_per_1l_air(0.3))
env_sensor_pm_05_pl_gauge.set(pms_data.pm_per_1l_air(0.5))
env_sensor_pm_1_pl_gauge.set(pms_data.pm_per_1l_air(1))
env_sensor_pm_25_pl_gauge.set(pms_data.pm_per_1l_air(2.5))
env_sensor_pm_5_pl_gauge.set(pms_data.pm_per_1l_air(5))
env_sensor_pm_10_pl_gauge.set(pms_data.pm_per_1l_air(10))
time.sleep(30) # Sleep for 30 seconds before getting more data
if __name__ == "__main__":
try:
start_http_server(8000)
main()
except KeyboardInterrupt:
print("shutting down")
sys.exit(0)
I'm running this on a Raspberry Pi Zero 2, 64 bit version of headless Raspbian.
Any idea why this is happening?
What
When i first plugged in and used the PMS5003 sensor, it felt like it wasn't working as expected, the reading from the sensor didn't really change even when i blocked the sensor fan and holes in the front. Here's a graph of the readings over several days:
After looking through the code for this library i noticed that there was a
resetAPI, so i called that which seemed to help, and the sensor did seem to behave differently and the results in the graph also looked a bit more interesting:However, when ever i restart my python application (which also now performs a
reseton the sensor), the sensor behaviour changes on every restart:I would expect that
resetshouldn't change the characteristics of the sensor so drastically.Here's the snippet of the code:
I'm running this on a Raspberry Pi Zero 2, 64 bit version of headless Raspbian.
Any idea why this is happening?