This commit is contained in:
quackerd 2022-01-22 05:50:48 +08:00
parent 4b3fbc9642
commit acc9c0ab9d
2 changed files with 8 additions and 3 deletions

View File

@ -8,7 +8,7 @@ class PTQS1005AC:
def __make_16bit_int(self, high, low) -> int:
return int(high) << 8 | int(low)
def __init__(self):
def __clear_val(self):
self.pm10 = 0
self.pm25 = 0
self.pm100 = 0
@ -32,6 +32,10 @@ class PTQS1005AC:
self.hum = 0
def __init__(self, raw_resp : bytes):
if raw_resp == None:
self.__clear_val()
return
if len(raw_resp) != 42:
raise Exception("Invalid response length: " + str(len(raw_resp)))

View File

@ -3,6 +3,7 @@ import libptqs1005
import time
import logging
import influxdb_client
import sys
import signal
NUM_READS = 10
@ -51,7 +52,7 @@ def measure(drv : libptqs1005.PTQS1005Driver) -> libptqs1005.PTQS1005AC:
logging.debug("Measurement " + str(i) + " out of " + str(NUM_READS) + ".")
time.sleep(DELAY_PER_READ)
ret = libptqs1005.PTQS1005AC()
ret = libptqs1005.PTQS1005AC(raw_resp = None)
for attr in COLUMN_MAP:
# average all measurements
@ -75,7 +76,7 @@ def data_to_line(data : libptqs1005.PTQS1005AC) -> str:
return ret
def main():
#logging.basicConfig(filename="monitor.log", encoding='utf-8', level=logging.DEBUG)
logging.basicConfig(stream=sys.stdout, level=logging.DEBUG)
logging.info("Setting up signal handler...")
signal.signal(signal.SIGINT, signal_handler)