Add sensor_logging/src/sensor_logging/cli.py
This commit is contained in:
parent
28825647e0
commit
b8b14097eb
1 changed files with 36 additions and 0 deletions
36
sensor_logging/src/sensor_logging/cli.py
Normal file
36
sensor_logging/src/sensor_logging/cli.py
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
import argparse
|
||||
import sys
|
||||
from sensor_logging import core
|
||||
|
||||
|
||||
def main() -> None:
|
||||
"""Command-line interface entrypoint for sensor logging."""
|
||||
parser = argparse.ArgumentParser(
|
||||
description="CLI to log sensor data from BME280 sensors."
|
||||
)
|
||||
parser.add_argument(
|
||||
"--sensor-id",
|
||||
required=True,
|
||||
type=str,
|
||||
help="Kennung des zu loggenden Sensors."
|
||||
)
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
sensor_id = args.sensor_id.strip()
|
||||
|
||||
if not sensor_id:
|
||||
print("Fehler: Sensor-ID darf nicht leer sein.", file=sys.stderr)
|
||||
sys.exit(1)
|
||||
|
||||
try:
|
||||
# Placeholder example values – actual sensor reading handled in core.log_sensor_data
|
||||
# The function itself will access the BME280 sensor for actual data.
|
||||
core.log_sensor_data(sensor_id=sensor_id, temperature=0.0, humidity=0.0)
|
||||
except Exception as exc:
|
||||
print(f"Fehler beim Loggen der Sensordaten: {exc}", file=sys.stderr)
|
||||
sys.exit(2)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Loading…
Reference in a new issue