Exception handling for MQTT
This commit is contained in:
parent
2ba5d7bf49
commit
d0817bc504
@ -1,6 +1,7 @@
|
||||
import config
|
||||
import logging
|
||||
import paho.mqtt.client as paho
|
||||
import socket
|
||||
import report
|
||||
import time
|
||||
|
||||
@ -17,11 +18,14 @@ logger = logging.getLogger(ROOT_LOGGER_NAME).getChild('main')
|
||||
def send_data_to_mqtt(data):
|
||||
client= paho.Client("temp_sens")
|
||||
client.username_pw_set(config.MQTT_USER, config.MQTT_PASS)
|
||||
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])
|
||||
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")
|
||||
|
||||
|
||||
def dht_callback(**data):
|
||||
|
Loading…
x
Reference in New Issue
Block a user