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,6 +79,7 @@ class MqttBackend(Backend):
|
|||
|
||||
|
||||
def send_message(self, msg):
|
||||
try:
|
||||
client = get_plugin('mqtt')
|
||||
client.send_message(topic=self.topic, msg=msg, host=self.host,
|
||||
port=self.port, username=self.username,
|
||||
|
@ -87,6 +88,8 @@ class MqttBackend(Backend):
|
|||
tls_keyfile=self.tls_keyfile,
|
||||
tls_version=self.tls_version,
|
||||
tls_ciphers=self.tls_ciphers)
|
||||
except Exception as e:
|
||||
self.logger.exception(e)
|
||||
|
||||
def run(self):
|
||||
def on_connect(client, userdata, flags, rc):
|
||||
|
@ -100,21 +103,18 @@ class MqttBackend(Backend):
|
|||
self.logger.info('Processing response on the MQTT topic {}: {}'.
|
||||
format(response_topic, response))
|
||||
|
||||
client = get_plugin('mqtt')
|
||||
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)
|
||||
self.send_message(response)
|
||||
|
||||
msg = msg.payload.decode('utf-8')
|
||||
try: msg = Message.build(json.loads(msg))
|
||||
except: pass
|
||||
|
||||
self.logger.info('Received message on the MQTT backend: {}'.format(msg))
|
||||
|
||||
try:
|
||||
self.on_message(msg)
|
||||
except Exception as e:
|
||||
self.logger.exception(e)
|
||||
|
||||
if isinstance(msg, Request):
|
||||
threading.Thread(target=response_thread, args=(msg,)).start()
|
||||
|
|
Loading…
Reference in a new issue