From e1f97c4a4e57ba6e6a4e2179159199181859078f Mon Sep 17 00:00:00 2001 From: Dirk Alders Date: Tue, 13 Sep 2022 06:10:09 +0100 Subject: [PATCH] Module mqtt implemented --- .gitmodules | 3 +++ ambient_info.py | 19 +++++++------------ mqtt | 1 + 3 files changed, 11 insertions(+), 12 deletions(-) create mode 160000 mqtt diff --git a/.gitmodules b/.gitmodules index b4b6223..8e529cd 100644 --- a/.gitmodules +++ b/.gitmodules @@ -4,3 +4,6 @@ [submodule "report"] path = report url = https://git.mount-mockery.de/pylib/report.git +[submodule "mqtt"] + path = mqtt + url = https://git.mount-mockery.de/pylib/mqtt.git diff --git a/ambient_info.py b/ambient_info.py index 3b19a5d..e8e975f 100644 --- a/ambient_info.py +++ b/ambient_info.py @@ -1,6 +1,6 @@ import config import logging -import paho.mqtt.client as paho +import mqtt import socket import report import time @@ -15,18 +15,13 @@ except ImportError: logger = logging.getLogger(ROOT_LOGGER_NAME).getChild('main') -def send_data_to_mqtt(data): - client= paho.Client(config.APP_NAME) - client.username_pw_set(config.MQTT_USER, config.MQTT_PASS) - try: - client.connect(config.MQTT_SERVER, 1883) - for key in data: - topic = config.MQTT_TOPIC + "/" + key - logger.info("Sending Ambient Information to mqtt %s=%s", topic, str(data[key])) - client.publish(topic, data[key]) - except (socket.timeout, OSError) as e: - logger.warning("Erro while sending ambient information") +mc = mqtt.mqtt_client(config.APP_NAME, config.MQTT_SERVER, 1883, config.MQTT_USER, config.MQTT_PASS) +def send_data_to_mqtt(data): + for key in data: + topic = config.MQTT_TOPIC + "/" + key + logger.info("Sending Ambient Information to mqtt %s=%s", topic, str(data[key])) + mc.send(topic, data[key]) def dht_callback(**data): del(data["time"]) diff --git a/mqtt b/mqtt new file mode 160000 index 0000000..cf97fa0 --- /dev/null +++ b/mqtt @@ -0,0 +1 @@ +Subproject commit cf97fa066cdff0e2f7eda0ff4d3c8c0f59c3f2ec