Browse Source

Module mqtt implemented

master
Dirk Alders 2 years ago
parent
commit
e1f97c4a4e
3 changed files with 11 additions and 12 deletions
  1. 3
    0
      .gitmodules
  2. 7
    12
      ambient_info.py
  3. 1
    0
      mqtt

+ 3
- 0
.gitmodules View File

@@ -4,3 +4,6 @@
4 4
 [submodule "report"]
5 5
 	path = report
6 6
 	url = https://git.mount-mockery.de/pylib/report.git
7
+[submodule "mqtt"]
8
+	path = mqtt
9
+	url = https://git.mount-mockery.de/pylib/mqtt.git

+ 7
- 12
ambient_info.py View File

@@ -1,6 +1,6 @@
1 1
 import config
2 2
 import logging
3
-import paho.mqtt.client as paho
3
+import mqtt
4 4
 import socket
5 5
 import report
6 6
 import time
@@ -15,18 +15,13 @@ except ImportError:
15 15
 logger = logging.getLogger(ROOT_LOGGER_NAME).getChild('main')
16 16
 
17 17
 
18
-def send_data_to_mqtt(data):
19
-    client= paho.Client(config.APP_NAME)
20
-    client.username_pw_set(config.MQTT_USER, config.MQTT_PASS)
21
-    try:
22
-        client.connect(config.MQTT_SERVER, 1883)
23
-        for key in data:
24
-            topic = config.MQTT_TOPIC + "/" + key
25
-            logger.info("Sending Ambient Information to mqtt %s=%s", topic, str(data[key]))
26
-            client.publish(topic, data[key])
27
-    except (socket.timeout, OSError) as e:
28
-        logger.warning("Erro while sending ambient information")
18
+mc = mqtt.mqtt_client(config.APP_NAME, config.MQTT_SERVER, 1883, config.MQTT_USER, config.MQTT_PASS)
29 19
 
20
+def send_data_to_mqtt(data):
21
+    for key in data:
22
+        topic = config.MQTT_TOPIC + "/" + key
23
+        logger.info("Sending Ambient Information to mqtt %s=%s", topic, str(data[key]))
24
+        mc.send(topic, data[key])
30 25
 
31 26
 def dht_callback(**data):
32 27
     del(data["time"])

+ 1
- 0
mqtt

@@ -0,0 +1 @@
1
+Subproject commit cf97fa066cdff0e2f7eda0ff4d3c8c0f59c3f2ec

Loading…
Cancel
Save