Skip to content

Commit

Permalink
Merge pull request adafruit#30 from jimbobbennett/fix_broker
Browse files Browse the repository at this point in the history
Using a copy of the broker name when splitting
  • Loading branch information
brentru authored Apr 21, 2020
2 parents 2f97b43 + 4ab6018 commit 2cbd472
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions adafruit_minimqtt.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,11 +223,11 @@ def connect(self, clean_session=True):
"""
try:
proto, dummy, self.broker, path = self.broker.split("/", 3)
proto, dummy, broker, path = self.broker.split("/", 3)
# replace spaces in path
path = path.replace(" ", "%20")
except ValueError:
proto, dummy, self.broker = self.broker.split("/", 2)
proto, dummy, broker = self.broker.split("/", 2)
path = ""
if proto == "http:":
self.port = MQTT_TCP_PORT
Expand All @@ -236,13 +236,11 @@ def connect(self, clean_session=True):
else:
raise ValueError("Unsupported protocol: " + proto)

if ":" in self.broker:
self.broker, port = self.broker.split(":", 1)
if ":" in broker:
broker, port = broker.split(":", 1)
port = int(port)

addr = _the_sock.getaddrinfo(self.broker, self.port, 0, _the_sock.SOCK_STREAM)[
0
]
addr = _the_sock.getaddrinfo(broker, self.port, 0, _the_sock.SOCK_STREAM)[0]
self._sock = _the_sock.socket(addr[0], addr[1], addr[2])
self._sock.settimeout(15)
if self.port == 8883:
Expand All @@ -251,7 +249,7 @@ def connect(self, clean_session=True):
self.logger.debug(
"Attempting to establish secure MQTT connection..."
)
self._sock.connect((self.broker, self.port), _the_interface.TLS_MODE)
self._sock.connect((broker, self.port), _the_interface.TLS_MODE)
except RuntimeError as e:
raise MMQTTException("Invalid broker address defined.", e)
else:
Expand Down

0 comments on commit 2cbd472

Please sign in to comment.