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()