|
@@ -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):
|