Add debug flag
This commit is contained in:
parent
a883c0d1b3
commit
59f32940f7
|
@ -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,10 +57,12 @@ def main():
|
||||||
last_measurement = time.time()
|
last_measurement = time.time()
|
||||||
while True:
|
while True:
|
||||||
# handle regular sensor data
|
# handle regular sensor data
|
||||||
|
if debug:
|
||||||
print("Getting values from sensors...")
|
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()
|
||||||
|
if debug:
|
||||||
print(mqtt_topic, data)
|
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():
|
||||||
|
|
Loading…
Reference in New Issue