Correcting examples
authorPeter McDonald <me@petermcdonald.co.uk>
Wed, 17 Jun 2020 22:44:38 +0000 (23:44 +0100)
committerPeter McDonald <me@petermcdonald.co.uk>
Wed, 17 Jun 2020 22:45:40 +0000 (23:45 +0100)
examples/all-in-one.py
examples/combined.py

index 6dda60779f2f354c7500e9d06e8ab8d6b1fbdba3..f7933a9e78b9f7603b642e2cad07b0d67e27f945 100755 (executable)
@@ -198,7 +198,7 @@ try:
             try:
                 data = pms5003.read()
             except pmsReadTimeoutError:
             try:
                 data = pms5003.read()
             except pmsReadTimeoutError:
-                logging.warn("Failed to read PMS5003")
+                logging.warning("Failed to read PMS5003")
             else:
                 data = float(data.pm_ug_per_m3(1.0))
                 display_text(variables[mode], data, unit)
             else:
                 data = float(data.pm_ug_per_m3(1.0))
                 display_text(variables[mode], data, unit)
@@ -209,7 +209,7 @@ try:
             try:
                 data = pms5003.read()
             except pmsReadTimeoutError:
             try:
                 data = pms5003.read()
             except pmsReadTimeoutError:
-                logging.warn("Failed to read PMS5003")
+                logging.warning("Failed to read PMS5003")
             else:
                 data = float(data.pm_ug_per_m3(2.5))
                 display_text(variables[mode], data, unit)
             else:
                 data = float(data.pm_ug_per_m3(2.5))
                 display_text(variables[mode], data, unit)
@@ -220,7 +220,7 @@ try:
             try:
                 data = pms5003.read()
             except pmsReadTimeoutError:
             try:
                 data = pms5003.read()
             except pmsReadTimeoutError:
-                logging.warn("Failed to read PMS5003")
+                logging.warning("Failed to read PMS5003")
             else:
                 data = float(data.pm_ug_per_m3(10))
                 display_text(variables[mode], data, unit)
             else:
                 data = float(data.pm_ug_per_m3(10))
                 display_text(variables[mode], data, unit)
index 4b8fbddaf6db117b0daf72d672a5db22b9786ea7..b417ccf1f74e0f81bc4a73a38fa9dd5848a94987 100755 (executable)
@@ -12,7 +12,7 @@ except ImportError:
     import ltr559
 
 from bme280 import BME280
     import ltr559
 
 from bme280 import BME280
-from pms5003 import PMS5003, ReadTimeoutError as pmsReadTimeoutError
+from pms5003 import PMS5003, ReadTimeoutError as pmsReadTimeoutError, SerialTimeoutError
 from enviroplus import gas
 from subprocess import PIPE, Popen
 from PIL import Image
 from enviroplus import gas
 from subprocess import PIPE, Popen
 from PIL import Image
@@ -276,7 +276,7 @@ def main():
                 try:
                     data = pms5003.read()
                 except pmsReadTimeoutError:
                 try:
                     data = pms5003.read()
                 except pmsReadTimeoutError:
-                    logging.warn("Failed to read PMS5003")
+                    logging.warning("Failed to read PMS5003")
                 else:
                     data = float(data.pm_ug_per_m3(1.0))
                     display_text(variables[mode], data, unit)
                 else:
                     data = float(data.pm_ug_per_m3(1.0))
                     display_text(variables[mode], data, unit)
@@ -287,7 +287,7 @@ def main():
                 try:
                     data = pms5003.read()
                 except pmsReadTimeoutError:
                 try:
                     data = pms5003.read()
                 except pmsReadTimeoutError:
-                    logging.warn("Failed to read PMS5003")
+                    logging.warning("Failed to read PMS5003")
                 else:
                     data = float(data.pm_ug_per_m3(2.5))
                     display_text(variables[mode], data, unit)
                 else:
                     data = float(data.pm_ug_per_m3(2.5))
                     display_text(variables[mode], data, unit)
@@ -298,7 +298,7 @@ def main():
                 try:
                     data = pms5003.read()
                 except pmsReadTimeoutError:
                 try:
                     data = pms5003.read()
                 except pmsReadTimeoutError:
-                    logging.warn("Failed to read PMS5003")
+                    logging.warning("Failed to read PMS5003")
                 else:
                     data = float(data.pm_ug_per_m3(10))
                     display_text(variables[mode], data, unit)
                 else:
                     data = float(data.pm_ug_per_m3(10))
                     display_text(variables[mode], data, unit)
@@ -331,8 +331,8 @@ def main():
                 pms_data = None
                 try:
                     pms_data = pms5003.read()
                 pms_data = None
                 try:
                     pms_data = pms5003.read()
-                except pmsReadTimeoutError:
-                    logging.warn("Failed to read PMS5003")
+                except (SerialTimeoutError, pmsReadTimeoutError):
+                    logging.warning("Failed to read PMS5003")
                 else:
                     save_data(7, float(pms_data.pm_ug_per_m3(1.0)))
                     save_data(8, float(pms_data.pm_ug_per_m3(2.5)))
                 else:
                     save_data(7, float(pms_data.pm_ug_per_m3(1.0)))
                     save_data(8, float(pms_data.pm_ug_per_m3(2.5)))