From 59f32940f741f00c4139e76b72d5077acb2cd4a2 Mon Sep 17 00:00:00 2001 From: Sebastian Lohff Date: Sun, 10 Jan 2021 03:13:50 +0100 Subject: [PATCH] Add debug flag --- mqtt_sensord/mqtt_sensord.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/mqtt_sensord/mqtt_sensord.py b/mqtt_sensord/mqtt_sensord.py index f87ebd6..8c32012 100755 --- a/mqtt_sensord/mqtt_sensord.py +++ b/mqtt_sensord/mqtt_sensord.py @@ -15,13 +15,19 @@ def main(): if sys.implementation.name != 'micropython': parser = argparse.ArgumentParser() parser.add_argument("-c", "--config", default="/etc/mqtt-sensord.conf") + parser.add_argument("-d", "--debug", action="store_true", default=False) args = parser.parse_args() config_path = args.config + debug = args.debug else: # most probably on micropython config_path = "mqtt-sensord.conf" + debug = False config = sensorlib.load_config(config_path) + debug = debug or config.get('debug') + config['debug'] = debug + sensorlib.Sensor.configure(config['host']['name'], sys.platform) mcfg = config['mqtt'] @@ -51,11 +57,13 @@ def main(): last_measurement = time.time() while True: # handle regular sensor data - print("Getting values from sensors...") + if debug: + print("Getting values from sensors...") for sensor in sensors: if sensor.HAS_SENSOR_DATA: data = sensor.gen_datapoint() - print(mqtt_topic, data) + if debug: + print(mqtt_topic, data) mqtt.send_data(mqtt_topic, data) if not mqtt.is_async(): mqtt.process_mqtt()