Add debug flag

This commit is contained in:
Sebastian Lohff 2021-01-10 03:13:50 +01:00
parent a883c0d1b3
commit 59f32940f7
1 changed files with 10 additions and 2 deletions

View File

@ -15,13 +15,19 @@ def main():
if sys.implementation.name != 'micropython': if sys.implementation.name != 'micropython':
parser = argparse.ArgumentParser() parser = argparse.ArgumentParser()
parser.add_argument("-c", "--config", default="/etc/mqtt-sensord.conf") parser.add_argument("-c", "--config", default="/etc/mqtt-sensord.conf")
parser.add_argument("-d", "--debug", action="store_true", default=False)
args = parser.parse_args() args = parser.parse_args()
config_path = args.config config_path = args.config
debug = args.debug
else: else:
# most probably on micropython # most probably on micropython
config_path = "mqtt-sensord.conf" config_path = "mqtt-sensord.conf"
debug = False
config = sensorlib.load_config(config_path) config = sensorlib.load_config(config_path)
debug = debug or config.get('debug')
config['debug'] = debug
sensorlib.Sensor.configure(config['host']['name'], sys.platform) sensorlib.Sensor.configure(config['host']['name'], sys.platform)
mcfg = config['mqtt'] mcfg = config['mqtt']
@ -51,11 +57,13 @@ def main():
last_measurement = time.time() last_measurement = time.time()
while True: while True:
# handle regular sensor data # handle regular sensor data
print("Getting values from sensors...") if debug:
print("Getting values from sensors...")
for sensor in sensors: for sensor in sensors:
if sensor.HAS_SENSOR_DATA: if sensor.HAS_SENSOR_DATA:
data = sensor.gen_datapoint() data = sensor.gen_datapoint()
print(mqtt_topic, data) if debug:
print(mqtt_topic, data)
mqtt.send_data(mqtt_topic, data) mqtt.send_data(mqtt_topic, data)
if not mqtt.is_async(): if not mqtt.is_async():
mqtt.process_mqtt() mqtt.process_mqtt()