def __init__(self, wolkMQTTClientConfig):
self.clientConfig = wolkMQTTClientConfig
# Setup MQTT client
self.client = mqtt.Client(self.clientConfig.wolkClientId, True)
self.client.on_connect = self._on_mqtt_connect
self.client.on_disconnect = self._on_mqtt_disconnect
self.client.on_message = self._on_mqtt_message
if self.clientConfig.ca_cert:
self.client.tls_set(self.clientConfig.ca_cert)
if self.clientConfig.set_insecure:
self.client.tls_insecure_set(self.clientConfig.set_insecure)
self.client.username_pw_set(self.clientConfig.username, self.clientConfig.password)
self.host = self.clientConfig.host
self.port = self.clientConfig.port
lastWillTopic = "lastwill/" + self.clientConfig.username
lastWillPayloyad = "Last will of serial:" + self.clientConfig.username
self.client.will_set(lastWillTopic, lastWillPayloyad, self.clientConfig.qos, False)
self.client.on_log = self._on_log
评论列表
文章目录