def _mq_reconnect(self, force=False):
if force:
self.mq_connected = False
while not self.mq_connected:
try:
self.mq_client = mqtt.Client()
self.mq_client.connect(host=self.broker, keepalive=10)
self.mq_client.subscribe(MQ_COMMAND_TOPIC)
self.mq_client.subscribe(MQ_HA_NOTIFY_TOPIC)
self.mq_client.on_message = self.on_mq_message
self.on_mq_disconnect = self.on_mq_disconnect
self.mq_client.loop_start()
self.mq_connected = True
_LOG.info("Connected to MQ!")
except Exception as ex:
_LOG.error("Could not connect to MQ: {0}".format(ex))
_LOG.warning("Trying again in 5 seconds...")
time.sleep(5)
评论列表
文章目录