4 import paho.mqtt.client
as mqtt
9 u""" MQTT Client factory 11 :param dict param: configuration parameters 12 :return mqtt.Client: MQTT Client 15 client_params = params.get(
'client', {})
16 client = mqtt.Client(**client_params)
19 tls_params = params.get(
'tls', {})
21 tls_insecure = tls_params.pop(
'tls_insecure',
False)
22 client.tls_set(**tls_params)
23 client.tls_insecure_set(tls_insecure)
26 account_params = params.get(
'account', {})
28 client.username_pw_set(**account_params)
31 message_params = params.get(
'message', {})
33 inflight = message_params.get(
'max_inflight_messages')
34 if inflight
is not None:
35 client.max_inflight_messages_set(inflight)
36 queue_size = message_params.get(
'max_queued_messages')
37 if queue_size
is not None:
38 client.max_queued_messages_set(queue_size)
39 retry = message_params.get(
'message_retry')
41 client.message_retry_set(retry)
44 userdata = params.get(
'userdata', {})
46 client.user_data_set(userdata)
49 will_params = params.get(
'will', {})
51 client.will_set(**will_params)
57 def extractor(topic_path):
58 if topic_path.startswith(
'~/'):
59 return '{}/{}'.format(mqtt_private_path, topic_path[2:])
64 __all__ = [
'default_mqtt_client_factory',
'create_private_path_extractor']
def create_private_path_extractor(mqtt_private_path)
def default_mqtt_client_factory(params)