X-Git-Url: https://zdv2.bktei.com/gitweb/EVA-2020-02-2.git/blobdiff_plain/b17f34b42aa5e6ca959d8f3d748012c87d4d8999..6c6e55301f85a23a4d393cf5244f0f5ba441e309:/examples/particulates.py diff --git a/examples/particulates.py b/examples/particulates.py index 99803ec..04a4950 100755 --- a/examples/particulates.py +++ b/examples/particulates.py @@ -1,9 +1,15 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 import time -from pms5003 import PMS5003 +from pms5003 import PMS5003, ReadTimeoutError +import logging -print("""particulates.py - Print readings from the PMS5003 particulate sensor. +logging.basicConfig( + format='%(asctime)s.%(msecs)03d %(levelname)-8s %(message)s', + level=logging.INFO, + datefmt='%Y-%m-%d %H:%M:%S') + +logging.info("""particulates.py - Print readings from the PMS5003 particulate sensor. Press Ctrl+C to exit! @@ -14,8 +20,10 @@ time.sleep(1.0) try: while True: - readings = pms5003.read() - print(readings) - time.sleep(1.0) + try: + readings = pms5003.read() + logging.info(readings) + except ReadTimeoutError: + pms5003 = PMS5003() except KeyboardInterrupt: pass