Skip to content

Commit a36c0e8

Browse files
committed
Merge branch 'use-generic-variables' of git://github.com/cipy/enviroplus-python into cipy-use-generic-variables
2 parents 476a391 + 8a7d81b commit a36c0e8

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

examples/all-in-one.py

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import ltr559
99

1010
from bme280 import BME280
11-
from pms5003 import PMS5003
11+
from pms5003 import PMS5003, ReadTimeoutError as pmsReadTimeoutError
1212
from enviroplus import gas
1313
from subprocess import PIPE, Popen
1414
from PIL import Image
@@ -193,7 +193,7 @@ def get_cpu_temperature():
193193
unit = "ug/m3"
194194
try:
195195
data = pms5003.read()
196-
except pms5003.ReadTimeoutError:
196+
except pmsReadTimeoutError:
197197
pass
198198
else:
199199
data = data.pm_ug_per_m3(1.0)
@@ -202,16 +202,24 @@ def get_cpu_temperature():
202202
if mode == 8:
203203
# variable = "pm25"
204204
unit = "ug/m3"
205-
data = pms5003.read()
206-
data = data.pm_ug_per_m3(2.5)
207-
display_text(variables[mode], data, unit)
205+
try:
206+
data = pms5003.read()
207+
except pmsReadTimeoutError:
208+
pass
209+
else:
210+
data = data.pm_ug_per_m3(2.5)
211+
display_text(variables[mode], data, unit)
208212

209213
if mode == 9:
210214
# variable = "pm10"
211215
unit = "ug/m3"
212-
data = pms5003.read()
213-
data = data.pm_ug_per_m3(10)
214-
display_text(variables[mode], data, unit)
216+
try:
217+
data = pms5003.read()
218+
except pmsReadTimeoutError:
219+
pass
220+
else:
221+
data = data.pm_ug_per_m3(10)
222+
display_text(variables[mode], data, unit)
215223

216224
# Exit cleanly
217225
except KeyboardInterrupt:

0 commit comments

Comments
 (0)