Skip to content

Commit 7d6834a

Browse files
authored
Merge pull request #139 from vladak/tls_port
do not hard-code TLS port value
2 parents 43ce775 + 79e58f6 commit 7d6834a

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

adafruit_minimqtt/adafruit_minimqtt.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,8 @@ class MQTT:
124124
"""MQTT Client for CircuitPython.
125125
126126
:param str broker: MQTT Broker URL or IP Address.
127-
:param int port: Optional port definition, defaults to 8883.
127+
:param int port: Optional port definition, defaults to MQTT_TLS_PORT if is_ssl is True,
128+
MQTT_TCP_PORT otherwise.
128129
:param str username: Username for broker authentication.
129130
:param str password: Password for broker authentication.
130131
:param network_manager: NetworkManager object, such as WiFiManager from ESPSPI_WiFiManager.
@@ -252,7 +253,7 @@ def _get_connect_socket(self, host, port, *, timeout=1):
252253
if not isinstance(port, int):
253254
raise RuntimeError("Port must be an integer")
254255

255-
if port == 8883 and not self._ssl_context:
256+
if port == MQTT_TLS_PORT and not self._ssl_context:
256257
raise RuntimeError(
257258
"ssl_context must be set before using adafruit_mqtt for secure MQTT."
258259
)
@@ -282,7 +283,7 @@ def _get_connect_socket(self, host, port, *, timeout=1):
282283
continue
283284

284285
connect_host = addr_info[-1][0]
285-
if port == 8883:
286+
if port == MQTT_TLS_PORT:
286287
sock = self._ssl_context.wrap_socket(sock, server_hostname=host)
287288
connect_host = host
288289
sock.settimeout(timeout)

0 commit comments

Comments
 (0)