import requests
import ST7735
from bme280 import BME280
-from pms5003 import PMS5003
+from pms5003 import PMS5003, ReadTimeoutError
from subprocess import PIPE, Popen, check_output
from PIL import Image, ImageDraw, ImageFont
values["temperature"] = "{:.2f}".format(comp_temp)
values["pressure"] = "{:.2f}".format(bme280.get_pressure() * 100)
values["humidity"] = "{:.2f}".format(bme280.get_humidity())
- pm_values = pms5003.read()
- values["P2"] = str(pm_values.pm_ug_per_m3(2.5))
- values["P1"] = str(pm_values.pm_ug_per_m3(10))
+ try:
+ pm_values = pms5003.read()
+ values["P2"] = str(pm_values.pm_ug_per_m3(2.5))
+ values["P1"] = str(pm_values.pm_ug_per_m3(10))
+ except ReadTimeoutError:
+ pms5003 = PMS5003()
+ pm_values = pms5003.read()
+ values["P2"] = str(pm_values.pm_ug_per_m3(2.5))
+ values["P1"] = str(pm_values.pm_ug_per_m3(10))
return values
# Get CPU temperature to use for compensation
#!/usr/bin/env python
import time
-from pms5003 import PMS5003
+from pms5003 import PMS5003, ReadTimeoutError
print("""particulates.py - Print readings from the PMS5003 particulate sensor.
try:
while True:
- readings = pms5003.read()
- print(readings)
- time.sleep(1.0)
+ try:
+ readings = pms5003.read()
+ print(readings)
+ time.sleep(1.0)
+ except ReadTimeoutError:
+ pms5003 = PMS5003()
except KeyboardInterrupt:
pass