Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update config values to include warm up and command wait #34

Merged
merged 2 commits into from
Apr 23, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 13 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
11 changes: 8 additions & 3 deletions aqimon/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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",
Expand All @@ -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)
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that this is renamed, so its a breaking change. Possible you set this to do local dev.

),
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),
Expand Down
9 changes: 7 additions & 2 deletions aqimon/read/novapm.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
3 changes: 2 additions & 1 deletion aqimon/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down