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':
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,10 +57,12 @@ def main():
last_measurement = time.time()
while True:
# handle regular sensor data
if debug:
print("Getting values from sensors...")
for sensor in sensors:
if sensor.HAS_SENSOR_DATA:
data = sensor.gen_datapoint()
if debug:
print(mqtt_topic, data)
mqtt.send_data(mqtt_topic, data)
if not mqtt.is_async():