diff --git a/README.md b/README.md index b45142e..41697c1 100644 --- a/README.md +++ b/README.md @@ -70,17 +70,19 @@ sudo systemctl start aqimon Aqimon uses environment variables for configuration, but all values should ship with sensible defaults. -| Variable | Default | Description | -|----------------------------------|---------------------|-----------------------------------------------------------------------------------------------------------------------------------| -| **AQIMON_DB_PATH** | ~/.aqimon/db.sqlite | The path to the database file, where read information is stored. It should be an absolute path; user home expansion is supported. | -| **AQIMON_POLL_FREQUENCY_SEC** | 900 (15 minutes) | Sets how frequently to read from the device, in seconds. | -| **AQIMON_RETENTION_MINUTES** | 10080 (1 week) | Sets how long data will be kept in the database, in minutes. | -| **AQIMON_READER_TYPE** | NOVAPM | The reader type to use, either NOVAPM or MOCK. | -| **AQIMON_USB_PATH** | /dev/ttyUSB0 | The path to the USB device for the sensor. | -| **AQIMON_SLEEP_TIME_SEC** | 5 | The number of seconds to wait for between each read in a set of reads. | -| **AQIMON_SAMPLE_COUNT_PER_READ** | 5 | The number of reads to take with each sample. | -| **AQIMON_SERVER_PORT** | 8000 | The port to run the server on. | -| **AQIMON_SERVER_HOST** | 0.0.0.0 | The host to run the server on. | +| Variable | Default | Description | +|------------------------------------|---------------------|-----------------------------------------------------------------------------------------------------------------------------------| +| **AQIMON_DB_PATH** | ~/.aqimon/db.sqlite | The path to the database file, where read information is stored. It should be an absolute path; user home expansion is supported. | +| **AQIMON_POLL_FREQUENCY_SEC** | 900 (15 minutes) | Sets how frequently to read from the device, in seconds. | +| **AQIMON_RETENTION_MINUTES** | 10080 (1 week) | Sets how long data will be kept in the database, in minutes. | +| **AQIMON_READER_TYPE** | NOVAPM | The reader type to use, either NOVAPM or MOCK. | +| **AQIMON_USB_PATH** | /dev/ttyUSB0 | The path to the USB device for the sensor. | +| **AQIMON_SLEEP_SEC_BETWEEN_READS** | 5 | The number of seconds to wait for between each read in a set of reads. | +| **AQIMON_SAMPLE_COUNT_PER_READ** | 5 | The number of reads to take with each sample. | +| **AQIMON_WARM_UP_SEC** | 15 | The number of seconds to wait for the device to warm up before reading. | +| **AQIMON_COMMAND_WAIT_TIME** | 1 | The number of seconds to wait for the device respond to a command. | +| **AQIMON_SERVER_PORT** | 8000 | The port to run the server on. | +| **AQIMON_SERVER_HOST** | 0.0.0.0 | The host to run the server on. | ## Contributing diff --git a/aqimon/config.py b/aqimon/config.py index 0f13a44..9a36d0e 100644 --- a/aqimon/config.py +++ b/aqimon/config.py @@ -17,9 +17,10 @@ class Config: # Nova PM properties usb_path: str - usb_sleep_time_sec: int + sleep_sec_between_reads: int sample_count_per_read: int warm_up_sec: int + command_wait_time: int # EPA Properties epa_lookback_minutes: int @@ -36,8 +37,9 @@ class Config: epa_lookback_minutes=60 * 8, # 8 hours reader_type="NOVAPM", usb_path="/dev/ttyUSB0", - usb_sleep_time_sec=5, + sleep_sec_between_reads=5, warm_up_sec=15, + command_wait_time=1, sample_count_per_read=5, server_port=8000, server_host="0.0.0.0", @@ -52,8 +54,11 @@ def get_config_from_env() -> Config: retention_minutes=int(os.environ.get("AQIMON_RETENTION_MINUTES", DEFAULT_CONFIG.retention_minutes)), reader_type=os.environ.get("AQIMON_READER_TYPE", DEFAULT_CONFIG.reader_type), usb_path=os.environ.get("AQIMON_USB_PATH", DEFAULT_CONFIG.usb_path), - usb_sleep_time_sec=int(os.environ.get("AQIMON_USB_SLEEP_TIME_SEC", DEFAULT_CONFIG.usb_sleep_time_sec)), + sleep_sec_between_reads=int( + os.environ.get("AQIMON_SLEEP_SEC_BETWEEN_READS", DEFAULT_CONFIG.sleep_sec_between_reads) + ), warm_up_sec=int(os.environ.get("AQIMON_WARM_UP_SEC", DEFAULT_CONFIG.warm_up_sec)), + command_wait_time=int(os.environ.get("AQIMON_COMMAND_WAIT_TIME", DEFAULT_CONFIG.command_wait_time)), sample_count_per_read=int(os.environ.get("AQIMON_SAMPLE_COUNT_PER_READ", DEFAULT_CONFIG.sample_count_per_read)), server_port=int(os.environ.get("AQIMON_SERVER_PORT", DEFAULT_CONFIG.server_port)), server_host=os.environ.get("AQIMON_SERVER_HOST", DEFAULT_CONFIG.server_host), diff --git a/aqimon/read/novapm.py b/aqimon/read/novapm.py index b4eafc2..5fc6a87 100644 --- a/aqimon/read/novapm.py +++ b/aqimon/read/novapm.py @@ -15,13 +15,18 @@ class OpinionatedReader: """NOVA PM SDS011 Reader.""" def __init__( - self, ser_dev: Union[str, serial.Serial], warm_up_secs: int = 15, iterations: int = 5, sleep_time: int = 3 + self, + ser_dev: Union[str, serial.Serial], + warm_up_secs: int = 15, + iterations: int = 5, + sleep_time: int = 3, + command_wait_time: int = 15, ): """Create the device.""" if isinstance(ser_dev, str): ser_dev = serial.Serial(ser_dev, timeout=2) - self.reader = QueryModeReader(ser_dev=ser_dev) + self.reader = QueryModeReader(ser_dev=ser_dev, send_command_sleep=command_wait_time) # Initial the reader to be in the mode we want. self.reader.wake() diff --git a/aqimon/server.py b/aqimon/server.py index 5f29ac9..5ee37bc 100644 --- a/aqimon/server.py +++ b/aqimon/server.py @@ -84,7 +84,8 @@ def build_reader() -> ScheduledReader: ser_dev=conf.usb_path, warm_up_secs=conf.warm_up_sec, iterations=conf.sample_count_per_read, - sleep_time=conf.usb_sleep_time_sec, + sleep_time=conf.sleep_sec_between_reads, + command_wait_time=conf.command_wait_time, ), ) else: