Skip to content

Commit

Permalink
support setting recconect delay (#123)
Browse files Browse the repository at this point in the history
  • Loading branch information
bellrichm committed Apr 8, 2021
1 parent 3c5708a commit 510962d
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
26 changes: 24 additions & 2 deletions bin/user/MQTTSubscribe.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,14 @@
# Default is None.
username = None
# The minimum time in seconds that the client will wait before trying to reconnect.
# Default is 1
min_delay = 1
# The maximum time in seconds that the client will wait before trying to reconnect.
# Default is 120
max_delay = 120
# password for broker authentication.
# Default is None.
password = None
Expand Down Expand Up @@ -244,6 +252,11 @@
# The first topic to subscribe to
[[[first/topic]]]
# When set to false, the topic is not subscribed to.
# Valid values: True, False
# Default is True
subscribe = True
# Specifies a field name in the mqtt message.
# The value of the field is appended to every field name in the mqtt message.
# This enables same formatted messages to map to different WeeWX fields.
Expand Down Expand Up @@ -277,6 +290,11 @@
# Default is float.
conversion_type = float
# Valid values, a Python expression that when evaluated returns a valid value.
Example, conversion_func = lambda x: True if x == 'ON' else False
# Default is not set.
conversion_func =
# When True: if there is an exception converting the data type, the value is set to None.
# When False: if there is an exception converting the data type, an error is logged and the MQTT msg is skipped.
# Valid values: True, False.
Expand Down Expand Up @@ -371,7 +389,7 @@
import weewx.drivers
from weewx.engine import StdEngine, StdService

VERSION = '2.0.0'
VERSION = '2.1.0-rc01'
DRIVER_NAME = 'MQTTSubscribeDriver'
DRIVER_VERSION = VERSION

Expand Down Expand Up @@ -745,7 +763,7 @@ def __init__(self, archive_topic, config, logger):
topic_defaults['use_server_datetime']))
self.subscribed_topics[topic]['datetime_format'] = topic_dict.get('datetime_format', topic_defaults['datetime_format'])
self.subscribed_topics[topic]['offset_format'] = topic_dict.get('offset_format', topic_defaults['offset_format'])
self.subscribed_topics[topic]['ignore_msg_id_field'] = callback_config_name
self.subscribed_topics[topic]['ignore_msg_id_field'] = callback_config_name # ToDo - investigate
self.subscribed_topics[topic]['ignore_msg_id_field'] = []
self.subscribed_topics[topic]['fields'] = {}
if not single_queue or topic == archive_topic:
Expand Down Expand Up @@ -1502,6 +1520,8 @@ def __init__(self, service_dict, logger):
port = to_int(service_dict.get('port', 1883))
username = service_dict.get('username', None)
password = service_dict.get('password', None)
min_delay = to_int(service_dict.get('min_delay', 1))
max_delay = to_int(service_dict.get('max_delay', 120))
log_mqtt = to_bool(service_dict.get('log', False))

self.logger.info("message_callback_provider_name is %s" % message_callback_provider_name)
Expand Down Expand Up @@ -1549,6 +1569,8 @@ def __init__(self, service_dict, logger):
if username is not None and password is not None:
self.client.username_pw_set(username, password)

self.client.reconnect_delay_set(min_delay=min_delay, max_delay=max_delay)

tls_dict = service_dict.get('tls')
if tls_dict:
self.config_tls(tls_dict)
Expand Down
2 changes: 1 addition & 1 deletion install.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
else:
from io import StringIO

VERSION = '2.0.0'
VERSION = '2.1.0-rc01'

MQTTSUBSCRIBESERVICE_CONFIG = """
[MQTTSubscribeService]
Expand Down

0 comments on commit 510962d

Please sign in to comment.