|
@@ -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"])
|