Browse Source

Adaption to paho 2.0

master
Dirk Alders 9 months ago
parent
commit
92ce2e7d4f
2 changed files with 7 additions and 11 deletions
  1. 7
    10
      ambient_info.py
  2. 0
    1
      requirements.txt

+ 7
- 10
ambient_info.py View File

@@ -1,5 +1,6 @@
1 1
 import config
2 2
 import logging
3
+import mqtt
3 4
 import paho.mqtt.client as paho
4 5
 import socket
5 6
 import report
@@ -47,20 +48,16 @@ class meaner(dict):
47 48
         return time.time() - self.start_time
48 49
 
49 50
 
51
+mqtt_inst = mqtt.mqtt_client(config.APP_NAME, config.MQTT_SERVER, username=config.MQTT_USER, password=config.MQTT_PASS)
50 52
 dht_meaner = meaner()
51 53
 bmp_meaner = meaner()
52 54
 
55
+
53 56
 def send_data_to_mqtt(data):
54
-    client = paho.Client("temp_sens")
55
-    client.username_pw_set(config.MQTT_USER, config.MQTT_PASS)
56
-    try:
57
-        client.connect(config.MQTT_SERVER, 1883)
58
-        for key in data:
59
-            topic = config.MQTT_TOPIC + "/" + key
60
-            logger.info("Sending Ambient Information to mqtt %s=%s", topic, str(data[key]))
61
-            client.publish(topic, data[key])
62
-    except (socket.timeout, OSError) as e:
63
-        logger.warning("Erro while sending ambient information")
57
+    for key in data:
58
+        topic = config.MQTT_TOPIC + "/" + key
59
+        logger.info("Sending Ambient Information to mqtt %s=%s", topic, str(data[key]))
60
+        mqtt_inst.send(topic, data[key])
64 61
 
65 62
 
66 63
 def dht_callback(**data):

+ 0
- 1
requirements.txt View File

@@ -1,3 +1,2 @@
1
-paho-mqtt
2 1
 adafruit-circuitpython-dht
3 2
 smbus

Loading…
Cancel
Save