Make sure that the shitty MQTT backend doesn't break for no reason
This commit is contained in:
parent
cbfcb76c21
commit
26ec213098
1 changed files with 17 additions and 17 deletions
|
@ -79,14 +79,17 @@ class MqttBackend(Backend):
|
||||||
|
|
||||||
|
|
||||||
def send_message(self, msg):
|
def send_message(self, msg):
|
||||||
client = get_plugin('mqtt')
|
try:
|
||||||
client.send_message(topic=self.topic, msg=msg, host=self.host,
|
client = get_plugin('mqtt')
|
||||||
port=self.port, username=self.username,
|
client.send_message(topic=self.topic, msg=msg, host=self.host,
|
||||||
password=self.password, tls_cafile=self.tls_cafile,
|
port=self.port, username=self.username,
|
||||||
tls_certfile=self.tls_certfile,
|
password=self.password, tls_cafile=self.tls_cafile,
|
||||||
tls_keyfile=self.tls_keyfile,
|
tls_certfile=self.tls_certfile,
|
||||||
tls_version=self.tls_version,
|
tls_keyfile=self.tls_keyfile,
|
||||||
tls_ciphers=self.tls_ciphers)
|
tls_version=self.tls_version,
|
||||||
|
tls_ciphers=self.tls_ciphers)
|
||||||
|
except Exception as e:
|
||||||
|
self.logger.exception(e)
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
def on_connect(client, userdata, flags, rc):
|
def on_connect(client, userdata, flags, rc):
|
||||||
|
@ -100,21 +103,18 @@ class MqttBackend(Backend):
|
||||||
self.logger.info('Processing response on the MQTT topic {}: {}'.
|
self.logger.info('Processing response on the MQTT topic {}: {}'.
|
||||||
format(response_topic, response))
|
format(response_topic, response))
|
||||||
|
|
||||||
client = get_plugin('mqtt')
|
self.send_message(response)
|
||||||
client.send_message(topic=self.topic, msg=response, host=self.host,
|
|
||||||
port=self.port, username=self.username,
|
|
||||||
password=self.password, tls_cafile=self.tls_cafile,
|
|
||||||
tls_certfile=self.tls_certfile,
|
|
||||||
tls_keyfile=self.tls_keyfile,
|
|
||||||
tls_version=self.tls_version,
|
|
||||||
tls_ciphers=self.tls_ciphers)
|
|
||||||
|
|
||||||
msg = msg.payload.decode('utf-8')
|
msg = msg.payload.decode('utf-8')
|
||||||
try: msg = Message.build(json.loads(msg))
|
try: msg = Message.build(json.loads(msg))
|
||||||
except: pass
|
except: pass
|
||||||
|
|
||||||
self.logger.info('Received message on the MQTT backend: {}'.format(msg))
|
self.logger.info('Received message on the MQTT backend: {}'.format(msg))
|
||||||
self.on_message(msg)
|
|
||||||
|
try:
|
||||||
|
self.on_message(msg)
|
||||||
|
except Exception as e:
|
||||||
|
self.logger.exception(e)
|
||||||
|
|
||||||
if isinstance(msg, Request):
|
if isinstance(msg, Request):
|
||||||
threading.Thread(target=response_thread, args=(msg,)).start()
|
threading.Thread(target=response_thread, args=(msg,)).start()
|
||||||
|
|
Loading…
Reference in a new issue