mqtt_client.py
Go to the documentation of this file.
1 # -*- coding: utf-8 -*-
2 import ssl
3 
4 import paho.mqtt.client as mqtt
5 import rospy
6 
7 
9  u""" MQTT Client factory
10 
11  :param dict param: configuration parameters
12  :return mqtt.Client: MQTT Client
13  """
14  # create client
15  client_params = params.get('client', {})
16  client = mqtt.Client(**client_params)
17 
18  # configure tls
19  tls_params = params.get('tls', {})
20  if tls_params:
21  tls_insecure = tls_params.pop('tls_insecure', False)
22  client.tls_set(**tls_params)
23  client.tls_insecure_set(tls_insecure)
24 
25  # configure username and password
26  account_params = params.get('account', {})
27  if account_params:
28  client.username_pw_set(**account_params)
29 
30  # configure message params
31  message_params = params.get('message', {})
32  if message_params:
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')
40  if retry is not None:
41  client.message_retry_set(retry)
42 
43  # configure userdata
44  userdata = params.get('userdata', {})
45  if userdata:
46  client.user_data_set(userdata)
47 
48  # configure will params
49  will_params = params.get('will', {})
50  if will_params:
51  client.will_set(**will_params)
52 
53  return client
54 
55 
56 def create_private_path_extractor(mqtt_private_path):
57  def extractor(topic_path):
58  if topic_path.startswith('~/'):
59  return '{}/{}'.format(mqtt_private_path, topic_path[2:])
60  return topic_path
61  return extractor
62 
63 
64 __all__ = ['default_mqtt_client_factory', 'create_private_path_extractor']
def create_private_path_extractor(mqtt_private_path)
Definition: mqtt_client.py:56
def default_mqtt_client_factory(params)
Definition: mqtt_client.py:8


mqtt_bridge
Author(s): Junya Hayashi
autogenerated on Thu Jun 6 2019 19:18:59