Fixed bug (script not reporting data to influx) when the influxdb server is temporarily down

This commit is contained in:
2025-07-07 13:41:02 +02:00
parent f23cb435d2
commit 8509f99483

View File

@@ -130,8 +130,6 @@ if __name__ == "__main__": # if run from cli (not imported as a module)
mqtt_client.connect(mq_broker, mq_port, 60) mqtt_client.connect(mq_broker, mq_port, 60)
mqtt_client.loop_start() mqtt_client.loop_start()
influx_client = InfluxDBClient(db_host, db_port, db_user, db_pwd, db_name)
## define the report functions (to be run in a thread) ## define the report functions (to be run in a thread)
def threaded_mqtt_report(): def threaded_mqtt_report():
last_data = data last_data = data
@@ -179,6 +177,7 @@ if __name__ == "__main__": # if run from cli (not imported as a module)
} }
} }
] ]
influx_client = InfluxDBClient(db_host, db_port, db_user, db_pwd, db_name)
influx_client.write_points(json_body) influx_client.write_points(json_body)
print(f"{bcolors.OKBLUE}Written data to the {bcolors.BOLD}influx database.{bcolors.ENDC}") print(f"{bcolors.OKBLUE}Written data to the {bcolors.BOLD}influx database.{bcolors.ENDC}")